如何将gdal_grid与点一起使用

时间:2016-11-04 10:57:27

标签: python parameters grid gdal rasterizing

我正在使用gdal_grid来制作一些3d表面的高程模型。

我可以使用带有此命令的geojson文件来执行此操作:

ds2 = gdal.Grid('outputfile.tif', 'inputfile.geojson', format = 'GTiff', algorithm = 'linear:radius=0')

这很好用,但我希望能够为每个功能单独完成。我可以循环遍历geojson文件并获取每个功能,但有没有办法将gdal.Grid与点一起使用,例如:

[[12.135253194446484, 55.590235278979236, 44.500800000000005],
[12.136885609925141, 55.58968131535586, 44.500800000000005],
[12.149742647277185, 55.59946751368944, 89.5008],
[12.14443275453964, 55.601269628832526, 89.5008],
[12.135253194446484, 55.590235278979236, 44.500800000000005]]

我的问题是:

  1. 我可以使用gdal.Grid代替geojson吗?
  2. 我在哪里可以看到我可以用于gdal.Grid ??
  3. 的输入参数

1 个答案:

答案 0 :(得分:0)

这就是我解决问题的方法。它可能不是最优雅的解决方案,但似乎有效。 我从geojson文件(作为字典)加载表面,获取第一个特征,然后将其转换为json字符串。

with open(surfaceFileName,'r') as file:
    data = json.load(file)
# the first feature:
dataJson = json.dumps(data['features'][0]['geometry'])
# this feature as geojson-string
featureJson = """{"type":"FeatureCollection",
               "features": [
               {"type": "Feature",
               "geometry": """+dataJson+""",
               "properties": {}
               }]}"""
# Using gdal_grid:
ds2 = gdal.Grid('test10py.tif', featureJson, format = 'GTiff', algorithm = 'linear:radius=0')