I want to interpolate the point data using IDW with GDAL osgeo.gdal.Grid.

IDW_gdal = gdal.Grid(Output, input, zfield="rs",
               algorithm = "invdist", 
               outputBounds = [ulx,
              width = width, height = height)

It works when I am passing the shapefile in 2nd argument but it does not work when I pass the geopandas GeoDataFrame and it throws the error

TypeError                                 Traceback (most recent call last)
<ipython-input-23-a7776d5dffb0> in <module>
     18                                lower_right_x_coordinate,
     19                                lower_right_y_coordinate],
---> 20               width = raster_width, height = raster_height)

C:\ProgramData\Anaconda3\lib\site-packages\osgeo\gdal.py in Grid(destName, srcDS, **kwargs)
    986         srcDS = OpenEx(srcDS, OF_VECTOR)
--> 988     return GridInternal(destName, srcDS, opts, callback, callback_data)
    990 def RasterizeOptions(options = [], format = None,

C:\ProgramData\Anaconda3\lib\site-packages\osgeo\gdal.py in GridInternal(*args)
   3295 def GridInternal(*args):
   3296     """GridInternal(char const * dest, Dataset dataset, GDALGridOptions options, GDALProgressFunc callback=0, void * callback_data=None) -> Dataset"""
-> 3297     return _gdal.GridInternal(*args)
   3298 class GDALRasterizeOptions(_object):
   3299     """Proxy of C++ GDALRasterizeOptions class."""

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

Alternately, I have passed the GeoDataFrame into ogr as GeoJson as given here

df_to_pass_in_ogr = ogr.Open(df_new.to_json())

output is

<osgeo.ogr.DataSource; proxy of <Swig Object of type 'OGRDataSourceShadow *' at 0x0000000BCDA48A80> >

but it did not work too and throws the same error.

Is there any way to use geopandas GeoDataFrame in the 2nd argument where you have passed the point feature shapefile like input_shape_file_name here?

1 Answer 1


gdal.Grid is expecting a GDALDataset object, not an OGRDataSource. As of GDAL 2.0 OGR is deprecated and GDAL can open raster and vector data. Use gdal.OpenEx to open your vector as a GDALDataset:

gdal.OpenEx(df_new.to_json(), gdal.OF_VECTOR)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.