简体   繁体   English

将纬度和经度写入Geotiff文件

[英]Write Latitude and Longitude to Geotiff file

I am basically trying to achieve the opposite of this question . 我基本上是想解决这个问题

I have a set of latitude and longitude coordinates (with values) in the WGS84 coordinate system, that I would like to write to a geotiff (or just add to a gdal dataset) via the gdal python bindings. 我在WGS84坐标系中有一组纬度和经度坐标(带有值),我想通过gdal python绑定写入geotiff(或仅添加到gdal数据集)。

For example, my starting data might be: 例如,我的起始数据可能是:

lat = np.array([45.345,56.267,23.425])
lon = np.array([134.689,128.774,111.956])
value = np.array([3.0,6.2,2.5])

How might one do this? 怎么可能呢? Thanks! 谢谢!

Although it is not in your question, it appears you need to project the lat/long data from the WGS84 datum to a UTM projection. 尽管这不是您的问题,但是您似乎需要将经纬度数据从WGS84基准投影到UTM投影。 This can be using the ogr2ogr command line from GDAL using the two options -a_srs 4326 -t_srs ???? 可以使用GDAL的ogr2ogr命令行,使用两个选项-a_srs 4326 -t_srs ???? (the target SRID). (目标SRID)。 It can also be done internally with Python using the OGR module of GDAL. 也可以使用GDAL的OGR模块在Python内部完成此操作。 Here is an example of use . 这是一个使用示例

There are two independent ways to get a raster from point data. 有两种独立的方法可以从点数据获取栅格。 The first is to interpolate the values in data, so that the values flood the region (or sometimes only the convex hull). 首先是对数据中的值进行插值 ,以使这些值淹没该区域(有时甚至是凸包)。 There are many methods and tools to interpolate values in 2D. 有许多方法和工具可以在2D中插值。 With GDAL, a comand-line tool gdal_grid is useful for this purpose, although I don't think it is possible to use from Python. 使用GDAL,通用命令工具gdal_grid可用于此目的,尽管我认为无法从Python使用它。 Probably the simplest would be to use scipy.interpolate . 可能最简单的方法是使用scipy.interpolate Once you have a 2D NumPy array, it is simple to create a raster file with GDAL/Python. 拥有2D NumPy数组后,使用GDAL / Python 创建栅格文件简单

The second method of converting the points to a raster is to burn the point locations to pixels on a raster. 将点转换为栅格的第二种方法是将点位置刻录到栅格上的像素。 Unlike the first method, only the locations where the points are have values, while the values are not interpolated anywhere else in the raster. 与第一种方法不同,只有点所在的位置才有值,而值不会在栅格中的其他任何位置进行插值。 Rasterising or burning vectors into a raster can be done from a GDAL command line tool gdal_rasterize . 可以使用GDAL命令行工具gdal_rasterize将矢量栅格化或刻录到栅格中。 It can also be done internally with GDAL/Python, here is an example . 也可以使用GDAL / Python 内部完成, 这是一个示例

It is possible to use gdal_grid from Python. 可以使用Python中的gdal_grid。 I am using it. 我正在使用它。 All you need to do is construct the command as if you were using it from the command line and put it inside a subprocess.call(com, shell=True). 您需要做的就是像在命令行中使用命令那样构造命令,并将其放在subprocess.call(com,shell = True)中。 You need to import subprocess module first. 您需要首先导入子流程模块。

This is actually how I am using it: 这实际上是我的使用方式:

pcall= "gdal_grid  --config 'NUM_THREADS=ALL_CPUS GDAL_CACHEMAX=2000'\
       -overwrite -a invdist:power=2.0:smoothing=2.0:radius1=360.0:radius2=360.0\
       -ot UInt16 -of GTiff -outsize %d %d -l %s -zfield 'Z' %s %s "%(npx, npy,\
       lname,ptshapefile,interprasterfile)

subprocess.call(pcall, shell= True)

NUM_THREADS option is available from gdal 1.10+ NUM_THREADS选项可从gdal 1.10+开始使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM