从GDAL LineString中删除点
Remove point from GDAL LineString
我试图只包含位于给定边界框内的形状文件中的地理特征。我找不到一个类似于带有BoundingBox选项[1]的Matlab的shapehead函数的函数,所以我试图从层的行字符串中删除不相关的点,但我不确定如何做到这一点(我有点期待会有与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
}
有什么想法吗?
如果你想做什么,也许你可以在OGR中使用Intersection()方法。请参阅GDAL文档中的参考资料。只需将边界框创建为实际的Geometry对象,然后调用例如poClippedLine=poLineString->Intersection(poBoundingBox),poClippedRine将是您所需要的。
但是,请注意,此方法将在剪裁边界框的"边界"处创建新的部分,您可能需要也可能不需要。
否则:-是的,我也没有找到RemovePoint方法。因此,您可能只需要复制并创建一个包含要包含的顶点子集的新lineString。
相关文章:
- 将数组的地址分配给变量并删除
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- C/C++编译器通常会删除重复的库吗
- 从链接列表c++中删除一个项目
- C++如何通过用户输入删除列表元素
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 是否需要删除包含对象的"pair"?
- 如何在自删除后将对象设置为nullptr
- 迭代时从向量和内存中删除对象
- 使用函数"remove"删除重复元素
- 如何从多映射中删除特定的重复项
- 运算符C++ "delete []"仅删除 2 个前值
- 删除指向指针的指针是运行时错误吗
- 将指针设置为"nullptr"并不能防止双重删除?
- 为什么示例代码访问IUnknown中已删除的内存
- 如何通过 getter 函数删除矢量的元素?
- 从控制台中删除最后打印的元素
- C++中的线程安全删除
- 如何从存储在std::映射中的std::集中删除元素
- 从GDAL LineString中删除点