Deleting from a shapefile

Frank Warmerdam warmerdam at POBOX.COM
Wed Aug 2 09:02:32 EDT 2006


Tamas Szekeres wrote:
> Antonio,
> 
> AFAIK, deleting shapes from the file would not be so easy like adding
> a shape since the file from the deleted shape should be rewritten and
> the shx should be recreated. Finally the implementation would be
> similar as recreating the file like you have mentioned before.

Tamas,

The CVS version of Shapelib (and GDAL/OGR 1.3.2) supports most update
operations on shapefiles.  This includes adding new shapes, deleting
shapes, and writing a new feature over an existing shape (with a
potentially different sized geometry).   Deleting is accomplished by
marking records deleted in the .dbf file.   All this can be done "in place"
on a shapefile without having to copy it.

However, rewriting a shape with a bigger geometry results in the geometry
being written at the end of the file and the space of the original being
lost.    The only way to recover the space held by deleted shapes, and
the lost geometry space for rewritten shapes is to issue the "REPACK <table>"
command via OGR SQL.  This repacking effectively rewrites the files.

None of this is directly usable from within mapscript, unfortunately.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGF, http://osgeo.org



More information about the mapserver-users mailing list