[Shapelib] Delete or hide Shape from Shapefile

Jelmer Baas Baas at speerit.nl
Tue May 19 06:41:31 EST 2009


Hi again,

Following my previous experiments with Shapelib, it seems I've found a
problem. 

I can access the exisiting features, I can modify the shape type, the 
vertices, etc. Shapelib also saves these changes properly. The problem
occurs
when VS.NET (Using Visual Studio 2005 now with David Gancarz's .NET
wrapper) 
starts to clean up. 

The following code freezes my application:

    Dim intShapeFile As Integer, intEntities As Integer, objShapeType As
MapTools.ShapeLib.ShapeType
    Dim minB(2) As Double, maxB(2) As Double

    intShapeFile = SHPOpen("C:\test\test.shp", "rb+")
    SHPGetInfo(intShapeFile, intEntities, objShapeType, minB, maxB)
    SHPClose(intShapeFile)
    System.GC.Collect()

I tried a different shape file, same problem. MapServer can properly
draw the shapes, so 
I think it's a valid file, too. There's no way to recover except kill
the application.


Well, wouldn't you know. While typing this I had another idea: to skip
SHPGetInfo, and that 
does the trick. Question remains: why does SHPGetInfo crash the app when
using Shapelib?


With kind regards,
Jelmer Baas

> Jelmer Baas wrote:
> > Hello,
> > 
> > I'm looking for a way to remove or hide a shape in a shape file. I'm
> > using MapServer to draw it, so it needs to be supported by 
> MapServer,
> > too. 
> > 
> > The PDF found on the shapelib page shows there's a shapetype 0 (Null
> > Shape), can't that somehow be used? Otherwise overwrite the style to
> > have a width of 0, something like that? I find it hard to 
> believe that
> > ESRI apps rewrite the entire file when a single object is 
> deleted... 
> > 
> > Despite already finding evidence that it's not possible
> > 
> (http://lists.maptools.org/pipermail/shapelib/2004-May/000074.html), I
> > wanted to ask it nonetheless.
> 
> Jelmer,
> 
> The normal approach to this is to call DBFMarkRecordDeleted() 
> which flips
> the bit in the DBF file marking a record as deleted.  
> However, I see no
> evidence that the MapServer native shapefile code checks the deleted
> marker so this isn't likely to help you with MapServer.
> 
> I think replacing the shape with a SHPT_NULL shape is the next best
> alternative.


More information about the Shapelib mailing list