[Shapelib] Reading Shapefile Polygon is Line

Richard R McDonald rmcd at usgs.gov
Fri Mar 2 13:36:13 EST 2007

I am having some success in reading shapefiles using shapelib and am very 
happy to have found this library.  In the code below I am reading a 
shapefile that I know to contain a number of polygons.  However when I 
read the geometry of the polygons - the points represent straight lines. I 
think I'm accessing the shapefile correctly.  If anyone has any idea's on 
why my polygons read as lines I would appreciate the help.


void MeshBCCoverage::importShapefile(LPCTSTR pathName, double xOffset, 
double yOffset)
//                      CString fext = openDlg.GetFileExt();
                SHPHandle shpHandle;
                shpHandle = SHPOpen(pathName, "rb");
                int pnEntities, pnShapeType;
                double padfMinBound[4], padfMaxBound[4];
                double tx, ty, tz;
                SbVec3f point;
                SHPGetInfo(shpHandle, &pnEntities, &pnShapeType, 
padfMinBound, padfMaxBound);
                for(int i = 0; i < pnEntities; i++) {
                        SHPObject* shpObject = SHPReadObject(shpHandle, 
                        switch(shpObject->nSHPType) {
                                case (SHPT_POLYGON):
                                                for(int j = 0; j < 
shpObject->nVertices; j++) {
                                                        tx = 
                                                        ty = 
                                                        tz = 
 point.setValue(tx-xOffset, ty-yOffset, this->curIndex+1);


Rich McDonald
Research Hydrologist
USGS Geomorphology and Sediment Transport Laboratory
4620 Technology Drive, Suite 400
Golden, CO 80403
303 278 7952
rmcd at usgs.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/shapelib/attachments/20070302/013a588a/attachment.html

More information about the Shapelib mailing list