Little geek Little geek - 1 year ago 106
Python Question

How do I use gdal_grid with points

I am using gdal_grid to make an elevation model of some 3d surfaces.

I can do it using a geojson-file with this command:

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

This works fine, but I would like to be able to do it for each feature individually. I can loop through the geojson-file and get each feature, but is there a way to use gdal.Grid with just the points, e.g.:

[[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]]

My questions are therefore:

  1. Can I use gdal.Grid with the points in stead of the geojson??

  2. Where can I see EXACTLY what input parameters I can use for gdal.Grid??

Answer Source

This is how I solved the problem. It might not be the most elegant solution, but it seems to work. I load the surfaces from a geojson file (as a dictionary), get the first feature, and then turn it into a json-string.

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')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download