Re: Rasterize command works from utility but not Python binding

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: Rasterize command works from utility but not Python binding

Even Rouault-2
On mercredi 27 juin 2018 14:51:23 CEST Deschamps, Benjamin (EC) wrote:

> Hi everyone,
> I am burning values from a KMZ into an existing GeoTiff. When I do it on the
> command line using gdal_rasterize (2.1.3), it works correctly:
> gdal_rasterize -burn 0 -dialect SQLITE -sql "SELECT * FROM MyLayer WHERE
> (Name IS NOT '01') AND (Name IS NOT '02')" myfile.kmz existingfile.tif
> But when I try the same, from the Python bindings it fails:
> query = "SELECT * FROM IceLayer WHERE (Name IS NOT '01') AND (Name IS NOT
> '02')" myoptions = gdal.RasterizeOptions(burnValues=0, SQLStatement=query,
> SQLDialect="SQLITE") gdal.Rasterize(tif, kmz, options=myoptions)
> With:
> Traceback (most recent call last):
>   File "", line 65, in <module>
>     create_ids_mask(lcc, working_dir, buffered_coastline)
>   File "", line 54, in my_function
>     gdal.Rasterize(tif, kmz, options=myoptions)
>   File "c:\Python36\lib\site-packages\osgeo\", line 1085, in
> Rasterize return wrapper_GDALRasterizeDestName(destNameOrDestDS, srcDS,
> opts, callback, callback_data) File
> "c:\Python36\lib\site-packages\osgeo\", line 3050, in
> wrapper_GDALRasterizeDestName return
> _gdal.wrapper_GDALRasterizeDestName(*args)
> RuntimeError: Cannot create X:\localpath\existingfile.tif
> I checked that the paths are correctly passed. What else could be the issue?

That error message comes from the code path where it tries to create a new
output file, not update an existing one.

What is 'tif' here ? A string or a GDAL dataset handle (in update mode) ?

I presume it is a filename, and that there's still a file descriptor opened on
it, which prevents it to be deleted. When you pass a filename, GDAL will not
try to update the file, but will recreate a new one. That said, I'm surprised
you didn't get a prior error about missing resolution or size.


Spatialys - Geospatial professional services
gdal-dev mailing list
[hidden email]