[Shapelib] Problem using shapelib

Brian Peschel brianp at mail.occinc.com
Mon Jun 14 08:45:36 PDT 2004


I am having problems with ArcView and shapefiles I am creating with 
shapelib (linux RH 8.0)

I am creating the shape files
    shpHandle = SHPCreate(tname.c_str(), SHPT_POLYGON);

and then adding the points
    SHPGetInfo(shpHandle, NULL, &shapeType, NULL, NULL);
    panParts[0] = 1;
    // Loop and add each point
        padfX[verticesCount] = convertedPoint.x();
        padfY[verticesCount] = convertedPoint.y();
        verticesCount++;
    // end loop
    psObject = SHPCreateObject(shapeType, -1, 1, panParts, NULL, 
verticesCount, padfX, padfY, NULL, NULL );

I then add the first point again since it is a polygon the first and 
last point apparently need to be the same (I have also tried not 
rewritting the final point). 
        padfX[verticesCount] = padfX[0];
        padfY[verticesCount] = padfY[0];
        verticesCount++;

This is a single ring polygon.  If I call SHPRewindObject it reorders my 
points and the first/last point are no longer the same (so I am not 
calling it).  I then write and destroy the objects.

    psObject = SHPCreateObject(shapeType, -1, 1, panParts, NULL, 
verticesCount, padfX, padfY, NULL, NULL );
    SHPWriteObject(shpHandle, -1, psObject);
    SHPDestroyObject(psObject);

If I load these files into ArcView, they appear to be okay until you use 
them when the last point gets dropped off.  If you use this shapechecker 
(http://www.geocities.com/SiliconValley/Haven/2295/useful.html scroll 
down to 'Shapefile Checker' - first hit in google 
http://www.google.com/search?hl=en&ie=UTF-8&q=shapefile+checker&btnG=Google+Search 
) in debug mode you can see it is confused about the last point (and 
complains about the record size).

I am really lost at this point.  Any thoughts would be helpful.  Thanks 
in advance.
Brian



More information about the Shapelib mailing list