[gdal-dev] Re: Editing attributes with ogr causing corrupt shapefile

Peter J Halls P.Halls at york.ac.uk
Thu Aug 5 02:09:49 EDT 2010


    so far as I am aware, neither GDAL/OGR nor ArcGIS update a shapefile in situ 
- I believe that ArcGIS creates a temporary dataset, performs the update as it 
copies the input data over, then deletes and renames to get the replacement.  I 
have used a similar method with Shapelib over the years and have done so with 
OGR more recently.  I think it likely that attempting to update a shapefile 
structure in situ is going always to carry the risk of corruption ...

Best wishes,


Tom Jeffery wrote:
> Chaitanya,
> I wrote up a method to find and delete geometries that fall outside of the
> reported Extent from the shapefile.  It seems to be doing the trick, though
> with some strange side effects.  
> It finds the bad features properly, and I remove them with
> layer.DeleteFeature(feature.GetFID()), but the .shp part of the shapefile is
> never updated.  (The dbf is the only file to change.)  Everything looks fine
> in OGR and ArcGIS, but if I run repair geometry in ArcGIS on the same file,
> it deletes the "same" records, causing the file to become completely
> unreadable.
> I seem to recall reading about this before, but haven't turned up anything
> in google searches.  Is there a method to properly delete a record so the
> .shp is updated as well?
> -Tom
> Tom,
> The -skipfailures flag skips only failures to create new features. Null
> geometries in non-null shapetype shapefile are not handled.
> The only way I can think of to clean such a file is by checking the geometry
> in each feature.
> On Thu, Aug 5, 2010 at 1:01 AM, Tom Jeffery <tjeffery at gmail.com> wrote:
>> Chaitanya,
>> I've found the issue with the particular shapefile I'm using.  It actually
>> has some null geometries in it, which are fixable using ESRI's "Repair
>> Geometry" tool.  I read that ogr2ogr is also suppose to remove records
>> with
>> empty geometries, but it doesn't seem to be working on my file, even with
>> the -skipfailures flag set.
>> Any thoughts?  Or is there another good way to clean a shapefile that
>> might
>> have null geometries?
>> Thanks so much for your help so far!
>> -Tom

Peter J Halls, GIS Advisor, University of York
Telephone: 01904 433806     Fax: 01904 433740
Snail mail: IT Services, University of York, Heslington, York YO10 5DD
This message has the status of a private and personal communication

More information about the gdal-dev mailing list