我正在使用 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]]
因此我的问题是:
- 我可以使用带有点的 gdal.Grid 代替 geojson 吗?
- 我在哪里可以确切地看到我可以为 gdal.Grid 使用哪些输入参数?
最佳答案
这就是我解决问题的方法。它可能不是最优雅的解决方案,但它似乎有效。 我从 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')
关于python - 我如何将 gdal_grid 与点一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40420933/