[gdal-dev] GDAL overrite file error

Even Rouault even.rouault at spatialys.com
Thu May 7 13:19:37 PDT 2015


Le jeudi 07 mai 2015 22:15:27, Even Rouault a écrit :
> Le jeudi 07 mai 2015 21:53:19, Stefan Keller a écrit :
> > Hi Even (and Peter)
> > 
> > Thanks for your quick answers! I actually referred to file related
> > read/write formats.
> > I tested some of them, if they support overwriting (I think this is
> > not always documented in the docs).
> > 
> > I fact, following support the -overwrite option (in alphabetical
> > order): GPKG, Mapinfo File, ESRI Shapefil, SQLite
> > 
> > Following don't: CSV, DXF, GeoJSON, GeoRSS, GML, GPX, Interlis 2, KML,
> > PDF and
> 
> Yes expected, none of them support DeleteLayer()

Actually, small correction: CSV does implement DeleteLayer(), but only when 
the filename is directory that contains only .csv file, and not the .csv file 
itself.
> 
> > Spatialite (as SQLite w/ -dsco SPATIALITE=yes)
> 
> Strange : could you provide a reproducable way for this ?
> 
> The following works for me :
> rm poly.sqlite
> ogr2ogr -f sqlite poly.sqlite poly.shp -dsco spatialite=yes
> ogr2ogr poly.sqlite poly.shp -overwrite
> 
> > Cheers, Stefan
> > 
> > P.S. Interlis 1 crashes currently :-< Pirmin is working on it and I
> > hope his patch will make it int the next release before code freeze.
> 
> OK, there's no ticket for that ?
> 
> > 2015-05-07 20:56 GMT+02:00 Even Rouault <even.rouault at spatialys.com>:
> > > Le jeudi 07 mai 2015 20:27:03, Stefan Keller a écrit :
> > >> Hi,
> > >> 
> > >> Regarding overwrite:
> > >> I think the "-overwrite" parameter in ogr2ogr commandline tool does
> > >> not work. I tried it with drivers like "ESRI Shapefile", GeoJSON and
> > >> others without success.
> > >> ogr2ogr always exits and reports
> > >> "ERROR 6: The GeoJSON driver does not overwrite existing files."
> > >> Why should drivers not be able to overwrite?
> > > 
> > > -overwrite causes an existing layer to be deleted before being
> > > recreated, for drivers that support the DeleteLayer() API.
> > > It does not cause an existing dataset to be destroyed however (which
> > > would be calling DeleteDataSource(), which isn't implemented by all
> > > drivers either), which is the issue you must have with the geojson
> > > driver.
> > > For shapefiles, that works in my testing however.
> > > I know this is a bit user unfriendly: nothing fundamentally impossible
> > > to improve here, just historic behaviour.
> > > 
> > >> Is'nt deleting files common task for all drivers (meaning to be
> > >> handled outside the actual writer drivers)?
> > > 
> > > Implementation of DeleteLayer() is driver specific code, since only
> > > drivers know which files (when files are involve. Think to a PostGIS
> > > table) are related to a layer.
> > > 
> > >> -S.
> > >> 
> > >> 2015-02-06 11:06 GMT+01:00 Even Rouault <even.rouault at spatialys.com>:
> > >> > Le vendredi 06 février 2015 10:42:04, Carlos Piury a écrit :
> > >> >> Hi, I am trying to create a vector format (i.e. ESRI Shapefile)
> > >> >> from laser file (.las), and it works fine, but when I try to
> > >> >> overwrite the file I get the following error:
> > >> >> 
> > >> >> ERROR 1: Layer 'output' already exists
> > >> > 
> > >> > --> The message is hopefully clear enough and comes from the
> > >> > implementation of CreateLayer() in the shape file driver. You have
> > >> > to destroy the files of the shapefile first if they exists. You can
> > >> > use DeleteDataSource() for that.
> > >> > 
> > >> >> terminate called after throwing an instance of 'std::runtime_error'
> > >> >> 
> > >> >>   what():  output layer creation failed
> > >> >> 
> > >> >> Aborted (core dumped)
> > >> > 
> > >> > Does this come from inside GDAL code or you own code ? Looks like
> > >> > from yours, if you transform GDAL errors into C++ exceptions.
> > >> > 
> > >> >> I am using the next code to create the layer:
> > >> >> 
> > >> >> OGRSFDriverH formatTranslateDriver =
> > >> >> OGRGetDriverByName(argFormat->sval[0]);
> > >> >> 
> > >> >> OGRDataSourceH dataset =
> > >> >> OGR_Dr_CreateDataSource(formatTranslateDriver, argOutput->sval[0],
> > >> >> 0);
> > >> >> 
> > >> >> OGRLayerH layer = OGR_DS_CreateLayer(dataset, layerName.c_str(), 0,
> > >> >> wkbPoint25D, 0);
> > >> >> 
> > >> >> Any idea about this error?
> > >> >> 
> > >> >> Thanks.
> > >> > 
> > >> > --
> > >> > Spatialys - Geospatial professional services
> > >> > http://www.spatialys.com
> > >> > _______________________________________________
> > >> > gdal-dev mailing list
> > >> > gdal-dev at lists.osgeo.org
> > >> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
> > > 
> > > --
> > > Spatialys - Geospatial professional services
> > > http://www.spatialys.com

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


More information about the gdal-dev mailing list