[gdal-dev] Can't delete feature from shapefile in python
Hugo
hfpmartins at gmail.com
Thu Sep 27 06:39:19 PDT 2012
Thanks a lot for your suggestion Even. That is it.
Cheers,
Hugo
On Sun, Sep 16, 2012 at 1:40 PM, Even Rouault
<even.rouault at mines-paris.org>wrote:
> Le samedi 08 septembre 2012 05:06:41, Hugo a écrit :
> > Hello all,
> >
> > I'm trying to delete a number of records from shapefile based on an
> > attribute. The strange thing that is happening is that feature count
> never
> > changes but if i make the same filter a second time the features are no
> > longer there. The code i'm using is below. I should be doing something
> > wrong for sure.
>
> I don't think you are doing something wrong. This is just a limitation of
> the
> implementation of GetFeatureCount() in the shapefile driver. When there
> are no
> attribute or spatial filter set, it returns the total number of records in
> the
> DBF file. When you delete a feature, it marks the corresponding record as
> invalid, but doesn't actually remove it from the file, so the total number
> of
> records remains unchanged. You can "repack" the .shp, .shx and .dbf files
> by
> running shp.ExecuteSQL("REPACK locais") (see
> http://gdal.org/ogr/drv_shapefile.html)
>
--
Hugo Martins
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120927/4bb98dac/attachment.html>
More information about the gdal-dev
mailing list