• gdal笔记之获取矢量面边界点坐标


    有时候我们需要获得矢量边界的空间坐标,然后把它转化为行列坐标,例如使用GDALWarp实现裁剪的时候。​下面的代码就是把空间坐标下的矢量多边形转化为行列坐标的矢量多边形。

    OGRPolygon* aoiPolygon = (OGRPolygon*)aoiGeometry;

    OGRLinearRing* boundary = aoiPolygon->getExteriorRing(); 

    OGRPolygon* pPolygon = (OGRPolygon*)OGRGeometryFactory::createGeometry(wkbPolygon); 

    int pointcount = boundary->getNumPoints(); 

    OGRLinearRing* pRing = (OGRLinearRing*)OGRGeometryFactory::createGeometry(wkbLinearRing); 

    for (int i = 0; i < pointcount; i++) 

    {  

        double gx = boundary->getX(i);  

        double gy = boundary->getY(i);  

        int row = static_cast((gy - srcGeotransform[3]) / srcGeotransform[5]); 

        int col = static_cast((gx - srcGeotransform[0]) / srcGeotransform[1]);  

        OGRPoint pt;  

        pt.setX(col);  pt.setY(row);  

        pRing->addPoint(&pt); 

    }

    pRing->closeRings(); 

    pPolygon->addRing(pRing); 

    OGRGeometry* cutGeometry = (OGRGeometry*)pPolygon;​

    注:aoiGeometry是原始多边形

  • 相关阅读:
    项目乱码导致原因
    springmvc配置文件
    IntelliJ IDEA启动Tomcat后,却无法访问Tomcat主页 等一系列问题
    java错题
    java 从键盘录入的三种方法
    java内部类 和外部类的区别
    多线程
    24中模式详解
    java的强制类型转换
    正则表达式
  • 原文地址:https://www.cnblogs.com/liuslayer/p/13153888.html
Copyright © 2020-2023  润新知