【问题标题】:Remove point from GDAL LineString从GDAL LineString中删除点
【发布时间】:2013-06-29 21:35:39
【问题描述】:

我试图仅包含位于给定边界框内的 shapefile 中的地理特征。我找不到类似于 Matlab 的 shaperead 函数和 BoundingBox 选项 [1] 的函数,所以我试图从图层的线串中删除不相关的点,但是我不确定如何做到这一点(我有点期待那里将与 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
        }

有什么想法吗?

【问题讨论】:

    标签: c++ gdal ogr


    【解决方案1】:

    鉴于您想要做的事情,也许您可​​以在 OGR 中使用 Intersection() 方法。请参阅the GDAL docs 中的参考资料。只需将您的边界框创建为实际的几何对象,然后调用例如poClippedLine = poLineString->Intersection(poBoundingBox) - poClippedLine 将是您所需要的。

    但是,请注意,此方法会在剪裁的边界框的“边界”处创建新部分,您可能想要也可能不想要。

    否则:- 是的,我也没有找到 RemovePoint 方法。因此,您可能只需要使用要包含的顶点子集复制并创建一个新的 lineString。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      • 2014-02-20
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多