2016-11-04 25 views
1

我正在使用gdal_grid創建一些3d表面的高程模型。如何使用帶點的gdal_grid

我可以使用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?

回答

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')