Unwanted edges when rendering polygon shapefile

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

Unwanted edges when rendering polygon shapefile

by dgp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have used a Polygon Shapefile using Shapelib in OpenGL.When I used States.shp(attachment) I get some unwanted additional edges.

#include #include #include "shapelib\shapefil.h" #include using namespace std; typedef struct MyPoint2D { double dX; double dY; }MyPoint2D; //Holds Coordinates of Point Shapefile vector vPoints; typedef struct MyLineString2D { vector vPointList; }MyLineString2D; //Holds Coordinates of Line Shapefile vector vLines; typedef struct MyPolygon2D { vector vPointList; }MyPolygon2D; //Holds Coordinates of Polygon Shapefile vector vPolygons; typedef struct SBoundingBox { float fMaxX; float fMaxY; float fMinX; float fMinY; }SBoundingBox; //Bounding Box of Shapefile SBoundingBox sBoundingBox; //Function to Open Shapefile and parse the info void OpenShapeFile(char* fileName) { SHPHandle hSHP=SHPOpen(fileName, "rb" ); //Read Bounding Box of Shapefile sBoundingBox.fMaxX=hSHP->adBoundsMax[0]; sBoundingBox.fMaxY=hSHP->adBoundsMax[1]; sBoundingBox.fMinX=hSHP->adBoundsMin[0]; sBoundingBox.fMinY=hSHP->adBoundsMin[1]; if(hSHP == NULL) return; //Point Shapefile if(hSHP->nShapeType == SHPT_POINT) { SHPObject *psShape; for(int i=0;inRecords;i++) { psShape = SHPReadObject(hSHP, i); double fX = psShape->padfX[0]; double fY = -psShape->padfY[0]; //Plot these points MyPoint2D pt; pt.dX=fX; pt.dY=-fY; vPoints.push_back(pt); } } //Line Shapefile else if(hSHP->nShapeType == SHPT_ARC) { SHPObject *psShape; for(int i=0;inRecords;i++) { psShape = SHPReadObject(hSHP, i); vector tempPointArray; for(int j=0;jnVertices;j++) { double fX = psShape->padfX[j]; double fY = psShape->padfY[j]; MyPoint2D pt; pt.dX=fX; pt.dY=fY; tempPointArray.push_back(pt); } MyLineString2D linestring; linestring.vPointList=tempPointArray; vLines.push_back(linestring); } } //Polygon Shapefile if(hSHP->nShapeType == SHPT_POLYGON) { SHPObject *psShape; for(int i=0;inRecords;i++) { psShape = SHPReadObject(hSHP, i); vector tempPointArray; for(int j=0;jnVertices;j++) { double fX = psShape->padfX[j]; double fY = psShape->padfY[j]; MyPoint2D pt; pt.dX=fX; pt.dY=fY; tempPointArray.push_back(pt); } MyPolygon2D polygon; polygon.vPointList=tempPointArray; vPolygons.push_back(polygon); } } }
void draw() { glClear (GL_COLOR_BUFFER_BIT); glColor3f (0.0, 0.0, 1.0); glLoadIdentity (); //Render Point Shapefile glColor3f (0.0, 0.0, 1.0); glEnable(GL_POINT_SMOOTH) ; glPointSize(5.0); glBegin(GL_POINTS); for(int i=0;i //OpenShapeFile("States\\states.shp");//Polygon Shapefile I get the output as follows when I tried to render.Observe the yellow circled areas.

But there is no problem when the same file is opened in softwares like Sharpmap which also use shapelib.

What could be the problem ?States.zip