[Shapelib] Reading Shapefile Polygon is Line

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


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

thanks,
rich



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, 
i);
                        switch(shpObject->nSHPType) {
                                case (SHPT_POLYGON):
                                        {
                                                this->createNewLine();
                                                for(int j = 0; j < 
shpObject->nVertices; j++) {
                                                        tx = 
*shpObject->padfX+j;
                                                        ty = 
*shpObject->padfY+j;
                                                        tz = 
*shpObject->padfZ+j;
 point.setValue(tx-xOffset, ty-yOffset, this->curIndex+1);
                                                        this
->addPoint(point);
                                                        this
->rbrBandPoint(point);
                                                }
                                                this->finishLine();
                                        }
                                        break;
                        }
                }

}


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.osgeo.org/pipermail/shapelib/attachments/20070302/013a588a/attachment.html>


More information about the Shapelib mailing list