[gdal-dev] GDAL overrite file error

Stefan Keller sfkeller at gmail.com
Thu May 7 12:53:19 PDT 2015


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 Spatialite (as SQLite w/ -dsco SPATIALITE=yes)

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.


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


More information about the gdal-dev mailing list