Delete or hide Shape from Shapefile

View: New views
6 Messages — Rating Filter:   Alert me  

Delete or hide Shape from Shapefile

by Jelmer Baas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

Any help would be appreciated,

With kind regards,
Jelmer Baas
Speer IT B.V.
_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Delete or hide Shape from Shapefile

by Frank Warmerdam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Delete or hide Shape from Shapefile

by Jelmer Baas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> > 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...
> >
> 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.

Frank,

Thank you for your quick reply. I tried setting the shpType to
NullShape, but this somehow doesn't seem to affect MapServer... I
verified the results and my modified shapefile is indeed different than
the original, and after re-loading the shpType is still 0. Setting the
vertices coordinates to zero *DID* have a result.

Seems like the only way to somehow mark an item for deletion is to move
it to 0,0 and every now and then build a new shapefile with these shapes
excluded.

If you have any other ideas, please let me know.

I'm happy at least the shapelib works in read/write mode. Thanks for all
your hard work.

--
Jelmer

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Delete or hide Shape from Shapefile

by Jelmer Baas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.
_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Delete or hide Shape from Shapefile

by Frank Warmerdam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jelmer Baas wrote:

> 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?

Jelmer,

The minB, maxB arguments to SHPGetInfo() should be dimensioned with a size
of four (X, Y, Z, measure), not 2.  I presume SHPGetInfo is writing past
the end of your arrays and corrupting the heap.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib

Re: Delete or hide Shape from Shapefile

by Jelmer Baas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fantastic, that fixed the crash.

Thanks again :)

Regards
Jelmer Baas

> -----Original Message-----
> From: shapelib-bounces@...
> [mailto:shapelib-bounces@...] On Behalf Of
> Frank Warmerdam
> Sent: dinsdag 19 mei 2009 15:49
> To: Shapelib Development
> Subject: Re: [Shapelib] Delete or hide Shape from Shapefile
>
> Jelmer Baas wrote:
> > 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?
>
> Jelmer,
>
> The minB, maxB arguments to SHPGetInfo() should be
> dimensioned with a size
> of four (X, Y, Z, measure), not 2.  I presume SHPGetInfo is
> writing past
> the end of your arrays and corrupting the heap.
>
> Best regards,
> --
> ---------------------------------------+----------------------
> ----------------
> I set the clouds in motion - turn up   | Frank Warmerdam,
> warmerdam@...
> light and sound - activate the windows | http://pobox.com/~warmerdam
> and watch the world go round - Rush    | Geospatial
> Programmer for Rent
>
> _______________________________________________
> Shapelib mailing list
> Shapelib@...
> http://lists.maptools.org/mailman/listinfo/shapelib
>
_______________________________________________
Shapelib mailing list
Shapelib@...
http://lists.maptools.org/mailman/listinfo/shapelib