1
我想只包含位於給定邊界框內的shapefile的地理特徵。我無法找到類似於Matlab的Shaperead函數的函數和BoundingBox選項[1],因此我試圖從圖層的線串中刪除不相關的點,但我不確定如何做到這一點(我預計會有與addPoint [2]相反)。我到目前爲止的代碼是:從GDAL中刪除點LineString
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
}
任何想法?