我试图仅包含位于给定边界框内的 shapefile 中的地理特征。我找不到类似于带有 BoundingBox 选项 [ 1 ] 的 Matlab 的 shaperead 函数的函数,因此我试图从图层的线串中删除不相关的点,但是我不确定如何执行此操作(我有点期望会有addPoint [ 2 ] 的反面)。我到目前为止的代码是:
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
}
有任何想法吗?