[gdal-dev] DataSource/Dataset using gdal.Grid()

Kai Muehlbauer kai.muehlbauer at uni-bonn.de
Thu Jun 1 09:13:00 PDT 2017


Hi everyone,

I'm using python-bindings gdal.Grid() function to grid scattered data.

I have a in-memory vector point data inside <class
'osgeo.ogr.DataSource'> "ds" which I want to feed directly to gdal.Grid().

ds2 = gdal.Grid('', ds, format='MEM',
                    width=900, height=900,
                    algorithm=algo,
                    zfield='ZX')

Unfortunately I get a "TypeError: in method 'GridInternal', argument 2
of type 'GDALDatasetShadow *'", see complete trace at the end.

If I save this dataset as is to an ESRI-Shapefile "test", I can
successfully do this:

ds2 = gdal.Grid('', 'test', format='MEM',
                    width=900, height=900,
                    algorithm=algo,
                    zfield='ZX')

Although I'm happy to get this running that way, I really would avoid
the save-to-disc part. Can I somehow fake my <osgeo.ogr.DataSource>
object to behave like a Dataset object or do some other magic? Any hints
very much appreciated.

Cheers,
Kai


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-140-a2fa980db211> in <module>()
     12                     width = 900, height = 900,
     13                     algorithm=algo,
---> 14                     zfield='ZX'
     15                     )
     16 dvx_ip2 = np.flipud(ds2.ReadAsArray())

/home/kai/miniconda3/envs/wradlib36/lib/python3.6/site-packages/osgeo/gdal.py
in Grid(destName, srcDS, **kwargs)
    952         srcDS = OpenEx(srcDS, OF_VECTOR)
    953
--> 954     return GridInternal(destName, srcDS, opts, callback,
callback_data)
    955
    956 def RasterizeOptions(options = [], format = None,

/home/kai/miniconda3/envs/wradlib36/lib/python3.6/site-packages/osgeo/gdal.py
in GridInternal(*args)
   3147 def GridInternal(*args):
   3148     """GridInternal(char const * dest, Dataset dataset,
GDALGridOptions options, GDALProgressFunc callback=0, void *
callback_data=None) -> Dataset"""
-> 3149     return _gdal.GridInternal(*args)
   3150 class GDALRasterizeOptions(_object):
   3151     """Proxy of C++ GDALRasterizeOptions class."""

TypeError: in method 'GridInternal', argument 2 of type
'GDALDatasetShadow *'


-- 
Kai Muehlbauer
Meteorological Institute University of Bonn
Auf dem Huegel 20       | +49 228 739083
D-53121 Bonn            | kai.muehlbauer at uni-bonn.de


More information about the gdal-dev mailing list