[gdal-dev] Fwd: Problem with gdal.Rasterize utility : argument GDALDatasetShadow in wrapper_GDALRasterizeDestName

François ALLAIN frallain at gmail.com
Thu Jul 14 12:13:24 PDT 2016


Hello,

I am trying to convert a gdal_rasterize command to a gdal.Rasterize call
with the Python bindings
(Python 2.7.9 64bits, GDAL 2.1.0 compiled with libproj0 libgeos-dev on
Debian 8.3).

The  gdal_rasterize command works perfectly  :
gdal_rasterize -i -b 4 -burn 0 my.geojson my.tif

With the information available on the web :
http://erouault.blogspot.ie/2015/10/gdal-and-ogr-utilities-as-library.html
https://trac.osgeo.org/gdal/wiki/rfc59.1_utilities_as_a_library
http://gis.stackexchange.com/questions/77139/why-do-shapefiles-and-geojson-behave-differently-in-gdal-python

I've tried this kind of script :

import os
import sys
from osgeo import gdal, ogr, osr

geojson_filename = "my.geojson"
driver = ogr.GetDriverByName("GeoJSON")
vector_ds = driver.Open(geojson_filename, gdal.GA_ReadOnly)

geotiff_filename = "my.tif"
ds = gdal.Open(geotiff_filename, gdal.GA_Update)

ret = gdal.Rasterize(ds, vector_ds,
            bands = [4],
            inverse = True,
            burnValues = [0])
if ret != 1:
    print 'fail'
else:
    print 'success'

but I kept getting this error :
Traceback (most recent call last):
  File "test.py", line 62, in <module>
    ret = gdal.Rasterize(ds, vector_ds, bands = [4], inverse = True,
burnValues = [0])
  File "/usr/local/lib/python2.7/dist-packages/osgeo/gdal.py", line 1046,
in Rasterize
    return wrapper_GDALRasterizeDestName(destNameOrDestDS, srcDS, opts,
callback, callback_data)
TypeError: in method 'wrapper_GDALRasterizeDestName', argument 2 of type
'GDALDatasetShadow *'

Any ideas of what could be wrong with this script ?

Thanks in advance

Cheers

François ALLAIN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20160714/7924ecb0/attachment.html>


More information about the gdal-dev mailing list