[gdal-dev] Additional arguments in gdal driver.CreateCopy function

Even Rouault even.rouault at spatialys.com
Fri Apr 22 12:11:56 PDT 2016


Le vendredi 22 avril 2016 21:05:50, Didier Bernard a écrit :
> Thank you for the reply Even,
> 
> Would you mind if I just ask you how can I delete the new .tif file that
> the driver.CreateCopy function created? When I try to delete it, it says:
> 
>     [Errno 13] The process cannot access the file because it is being used
> by another process
> 
> even though I did the following before trying to delete the new .tif file:
> 
>     src_ds.FlushCache();
>     dst_ds.FlushCache();
>     driver.Dispose();
> 
> Is there some other function I should call to close the file handle?

FlushCache() isn't enough to close the file descriptor, and you definitely don't 
want to call driver.Dispose() as it could cause crashes.

It seems there's a Dataset.Dispose(). You might try that.

> 
> I apologize if this question is C# specific, I hoped that it may be similar
> to Python syntax.
> 
> Thank you.
> 
> Didier
> 
> ________________________________________
> From: Even Rouault <even.rouault at spatialys.com>
> Sent: Friday, April 22, 2016 8:51 PM
> To: gdal-dev at lists.osgeo.org
> Cc: Didier Bernard
> Subject: Re: [gdal-dev] Additional arguments in gdal driver.CreateCopy
> function
> 
> Le vendredi 22 avril 2016 20:10:48, Didier Bernard a écrit :
> > Hello,
> > 
> > I would like to create a new .tif file in GDAL C# by using the
> > driver.CreateCopy<http://www.gdal.org/classGDALDriver.html#a2c897da2a6e25
> > 1 69cccc49ef48797ce1> function. I have been reading gdal tutorial
> > page<http://www.gdal.org/gdal_tutorial.html> and it looks like the python
> > version of driver.CreateCopy function supports the use of additional
> > arguments. For example, it supports using 'TILED=YES' argument:
> > 
> > src_ds = gdal.Open( src_filename )
> > 
> > dst_ds = driver.CreateCopy( dst_filename, src_ds, 0,
> > 
> >                             [ 'TILED=YES', 'COMPRESS=PACKBITS' ] )
> > 
> > I assume this means it can also support an argument like: "-outsize 50%
> > 50%" ?
> 
> No, -outsize is an argument specific to gdal_translate. CreateCopy() only
> accept driver specific creation options.
> 
> If you use GDAL 2.1.0, you can use it in gdal.Translate(). It is available
> in Python. See for example test_gdal_translate_lib_7() of
> https://svn.osgeo.org/gdal/trunk/autotest/utilities/test_gdal_translate_lib
> .py The widthPct/heightPct are syntaxic sugar of Python bindings.
> 
> Not completely sure however how ready the C# bindings of gdal.Translate()
> are. I presume that might be pretty raw. Something like (you will
> certainly need to fix it to be correct C#) :
> 
> gdal.GDALTranslateOptions options  = new gdal.GDALTranslateOptions( new
> String[] { "-outsize", "50%", "50%" } );
> gdal.wrapper_GDALTranslate("out.tif", src_ds, options);
> 
> Don't ask me more about C# bindings ;-)
> 
> > If this is so, then how can I use the same argument ("-outsize 50% 50%")
> > in C# version of driver.CreateCopy function? Something like:
> > 
> > driver.CreateCopy(filePath, dataset, False, "-outsize 50% 50%", null,
> > null);
> > 
> > ?
> > 
> > Thank you.
> > 
> > Didier
> 
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list