建议实现一个简单的RESTful微服务,用于从GeoTiff中检索像素值。

huangapple go评论90阅读模式
英文:

Suggestion to implement a simple RESTFul microservice to retraive pixel value from GeoTiff

问题

我是计算机科学专业的硕士学生,正在制作一个基于GeoTiFF图像和Spring Boot(Java)的“简单”微服务。

我想要做的是:

1)下载意大利的高分辨率(10米像素)DEM(数字高程模型),即TINITALY/01,将其划分为瓦片,其中每个瓦片都是一个GeoTiff图像。

“这个DEM是从意大利各个行政区的单独DEM开始获取的。该DEM以10米单元格大小的网格(GeoTIFF格式)免费提供,在UTM WGS 84区32投影系统中(请参阅下载链接)。”

http://tinitaly.pi.ingv.it/Download_Area1_1.html

2)将图像保存到数据库中(?)

3)在Spring Boot中开发一个REST服务,根据坐标点(纬度/经度)和周围的像素大小返回一个DEM值数组

问题(感谢):

1)我了解到有几种保存GeoTiff图像的方法,如Postgresql的PostGIS、MongoDB、GeoServer等。老实说,对于我需要制作的应用程序,我还没有确定哪个组件最适合存储GeoTiff。

2)我了解到,一些开发人员建议,为了在云中工作,将GeoTIFF转换为云优化的GeoTIFF(COG)。我仍在研究文档,但您认为这是我想要实现的服务的必需步骤吗?

英文:

I am a student in Science in Computer Science (Master degree) and I am making a "simple" microservice based on GeoTiFF images and Spring Boot (Java).

What I would like to do is:

  1. download the high resolution (10-m pixel) DEM Italy (i.e., TINITALY/01 ), divided into tiles, where each tile is a GeoTiff image.

"This DEM was obtained starting from separate DEMs of single administrative regions of Italy. The DEM is freely available as a 10 m-cell size grid (in GeoTIFF format), in the UTM WGS 84 zone 32 projection system (see the link download)".

http://tinitaly.pi.ingv.it/Download_Area1_1.html

  1. save the images in a database (?)

  2. develop a REST service in Spring Boot where, given a coordinate point (lat/long) and an around (of the pixel) returns an array of the DEM values

Questions (Thanks):

  1. I have read that there are several approaches to save GeoTiff images such as Postgresql's PostGIS, mongoDB, GeoServer, etc. Honestly, for the application I need to make, I have not figured out which component is best for store GeoTiff.

  2. I have read that several developers recommend, in order to work in the cloud, to transform GeoTIFF to Cloud Optimized GeoTIFF (COG). I am still studying the documentation but do you think it is a required step for the service I want to implement?

答案1

得分: 1

我使用了Postgres+POSTGIS,我认为它在只想获取单元格值时表现得非常出色 - 即使进行空间分析也可以很好地工作,但对于非常大的栅格数据集可能稍微慢一些。

在这里,您可以轻松地使用ST_Value来获取单元格的值:https://postgis.net/docs/RT_ST_Value.html 正如您在这里所看到的,您可以使用位置或图像空间的行和列来获取数据。如果您想从附近像素获取值,ST_Neighbourhood也可能很有用:https://postgis.net/docs/RT_ST_Neighborhood.html

就性能而言,我曾经使用了澳大利亚维多利亚州的30m * 30m DEM数据,使用PostGIS非常出色 - 即使对于需要空间连接的更高级查询,性能也是可接受的。

我建议使用PostGIS,我相当确定它会表现得很好。但是对于第二个问题,我不确定 - 我没有使用COG的经验。

这些是一些可能有帮助的示例查询。在这里,我使用了WGS84(SRID:4326)中的一个点来从我的栅格数据中获取数据,该点在SRID 7855中(因此需要转换坐标)。我的栅格表是victoria_raster,点的坐标为(纬度:-37.8136,经度:144.9631)。

获取像素值(由几何定义):

select rid, ST_WorldToRasterCoordX(raster.rast,
				ST_Transform(
					ST_Point(144.9631, -37.8136, 4326),
					7855
				)) as pix_value
from victoria_raster as raster
WHERE ST_Intersects(raster.rast,ST_Transform(
					ST_Point(144.9631, -37.8136, 4326),
					7855));

获取像素周围的值(由几何定义) - 3x3像素,因为在ST_Neighbourhood函数中只考虑了列+-1和行+-1:

-- 3x3像素 - 在点周围
with input_point as (
	select ST_Transform(
					ST_Point(144.9631, -37.8136, 4326),
					7855) as geom
),
row_col as (
	select ST_WorldToRasterCoordX(raster.rast,
				input_point.geom) as c_number,
			ST_WorldToRasterCoordY(raster.rast,
				input_point.geom) as r_number,
			input_point.geom as geom
	from victoria_raster as raster, input_point
	WHERE ST_Intersects(raster.rast,input_point.geom)
)
select ST_Neighborhood(raster.rast, row_col.c_number, row_col.r_number, 1,1)
from row_col, victoria_raster as raster
WHERE ST_Intersects(raster.rast,row_col.geom)

因此,我建议使用数据库来处理栅格数据集 - Postgres+PostGIS。并使用REST Web服务中的查询来获取值。

英文:

I worked with Postgres+POSTGIS and I think it works amazing if you just want to fetch values of cells - even spatial analysis will work well but maybe a bit slow for very large Raster dataset.

Here, how you can easily get the value of a cell using ST_Value: https://postgis.net/docs/RT_ST_Value.html as you see here you can use location or image space row, column to get the data. ST_Neighbourhood could be also useful in case you want to get values from nearby pixels: https://postgis.net/docs/RT_ST_Neighborhood.html

In terms of performance, I had worked with 30m*30m DEM of Victoria, Australia and it works really well using PostGIS - even for more advanced queries that needs spatial join the performance was acceptable.

I would recommend using PostGIS as I am pretty sure it will work well. But I am not sure about the second question - I didn't have experience with COG.

These are some sample queries that might be helpful. Here, I am using a point in WGS84 (SRID:4326) to get data from my raster data which is in SRID 7855 (so I need to transform the coordinates). My raster table is victoria_raster and the point coordinates in (latitude: -37.8136, longitude: 144.9631).

getting the pixel value (defined by geometry):

select rid, ST_WorldToRasterCoordX(raster.rast,
				ST_Transform(
					ST_Point(144.9631, -37.8136, 4326),
					7855
				)) as pix_value
from victoria_raster as raster
WHERE ST_Intersects(raster.rast,ST_Transform(
					ST_Point(144.9631, -37.8136, 4326),
					7855));

getting the values around the pixel (defined by geometry) - 3 by 3 as we only consider cols +- 1 and rows +-1 in the ST_Neighbourhood function:

-- 3 by 3 pixels - around the point
with input_point as (
	select ST_Transform(
					ST_Point(144.9631, -37.8136, 4326),
					7855) as geom
),
row_col as (
	select ST_WorldToRasterCoordX(raster.rast,
				input_point.geom) as c_number,
			ST_WorldToRasterCoordY(raster.rast,
				input_point.geom) as r_number,
			input_point.geom as geom
	from victoria_raster as raster, input_point
	WHERE ST_Intersects(raster.rast,input_point.geom)
)
select ST_Neighborhood(raster.rast, row_col.c_number, row_col.r_number, 1,1)
from row_col, victoria_raster as raster
WHERE ST_Intersects(raster.rast,row_col.geom)

So, I would recommend using database to handle the raster dataset - Postgres+PostGIS. And using queries in your REST webservice to fetch the values.

huangapple
  • 本文由 发表于 2023年6月26日 19:15:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定