I am trying to just include geographic features from a shapefile that lie within a given bounding box. I couldn't find a function similar to Matlab's shaperead function with a BoundingBox option [1] and so I am trying to remove non-relevant points from a layer's linestring however I am unsure how to do this (I kind of expected there would be the opposite of addPoint [2]). The code I have so far is:
OGRLineString *poLineString = (OGRLineString *) poGeometry;
int numPoints = poLineString->getNumPoints();
cout << "num points" << poLineString->getNumPoints() << endl;
//for each feature check if its in the bounding box
for (int i=0; i<numPoints; i++)
{
// start off assuming we are including everything
bool xInclude, yInclude = 1;
OGRPoint* poPoint;
poLineString->getPoint(i, poPoint);
double ptX = poPoint->getX();
double ptY = poPoint->getY();
cout << "ptX " << ptX << " ptY " << ptY <<endl;
//tlE, tlN, maxE, maxN are eastings/northings coordinates
if((ptX<tlE)||(ptX>maxE))
xInclude=0;
if((ptY<minN)||(ptY>tlN))
yInclude=0;
if(!(xInclude && yInclude))
//poLineString->setPoint(i,0,0);
REMOVE POINT HERE
}
Any ideas?