Caminho de aprendizagem GDAL C++ API (6) Classe de geometria OGRGeometry OGRGeometry

Simplificar

virtual  OGRGeometry  *Simplify(double dTolerance) const

Simplificar geometria

parâmetro:

dTolerance  – tolerância de distância simplificada.

Retorna: a geometria simplificada ou NULL se ocorrer um erro

   // 创建一个多边形对象
    OGRLinearRing ring;
    ring.addPoint(0, 0);
    ring.addPoint(0, 4);
    ring.addPoint(2, 4);
    ring.addPoint(2, 2);
    ring.addPoint(4, 2);
    ring.addPoint(4, 0);
    ring.addPoint(0, 0);

    OGRPolygon polygon;
    polygon.addRing(&ring);

    // 输出原始多边形的点数
    std::cout << "Original polygon points count: " << polygon.getNumPoints() << std::endl;

    // 进行简化
    OGRGeometry* simplifiedGeometry = polygon.Simplify(1.0);

    // 输出简化后的多边形的点数
    cout << "Simplified polygon points count: " << simplifiedGeometry->getNumPoints() << endl;

SimplificarPreservarTopologia

OGRGeometry  *SimplifyPreserveTopology(double dTolerance) const

Simplifique a geometria enquanto preserva a topologia

parâmetro:

dTolerance  – tolerância de distância simplificada.

Retorna: a geometria simplificada ou NULL se ocorrer um erro

    // 创建一个多边形对象
    OGRLinearRing ring;
    ring.addPoint(0, 0);
    ring.addPoint(0, 4);
    ring.addPoint(2, 4);
    ring.addPoint(2, 2);
    ring.addPoint(4, 2);
    ring.addPoint(4, 0);
    ring.addPoint(0, 0);

    OGRPolygon polygon;
    polygon.addRing(&ring);

    // 输出原始多边形的点数
    std::cout << "Original polygon points count: " << polygon.getNumPoints() << std::endl;

    // 进行简化,并保持拓扑结构
    OGRGeometry* simplifiedGeometry = polygon.SimplifyPreserveTopology(1.0);

    // 输出简化后的多边形的点数
    std::cout << "Simplified polygon points count: " << simplifiedGeometry->getNumPoints() << std::endl;

    // 释放简化后的几何对象的内存
    delete simplifiedGeometry;

DelaunayTriangulação

virtual  OGRGeometry  *DelaunayTriangulation(double dfTolerance, int bOnlyEdges) const

Retorna a triangulação Delaunay dos vértices da geometria

parâmetro:

  • dfTolerance  – tolerância de encaixe opcional para robustez

  • bOnlyEdge - Se for TRUE, retornará uma MULTILINESTRING, caso contrário retornará uma GEOMETRYCOLLECTION contendo polígonos triangulares.

Retorna: a geometria gerada pela triangulação Delaunay ou NULL se ocorreu um erro

 // 创建一组点
    OGRPoint points[4];
    points[0].setX(0);
    points[0].setY(0);

    points[1].setX(0);
    points[1].setY(10);

    points[2].setX(10);
    points[2].setY(10);

    points[3].setX(10);
    points[3].setY(0);

    // 创建一个几何对象集合并添加点
    OGRGeometryCollection collection;
    for (int i = 0; i < 4; i++) {
        collection.addGeometry(&points[i]);
    }

    // 对点进行 Delaunay 三角剖分
    OGRGeometry* triangulatedGeometry = collection.DelaunayTriangulation(0.0, 0);

    // 输出三角剖分结果的类型
    if (triangulatedGeometry != nullptr) {
        OGRwkbGeometryType geomType = triangulatedGeometry->getGeometryType();
        std::cout << "Triangulated geometry type: " << OGRGeometryTypeToName(geomType) << std::endl;

        // 释放三角剖分结果的内存
        delete triangulatedGeometry;
    } else {
        std::cout << "Failed to perform Delaunay triangulation." << std::endl;
    }

poligonizar

Virtual  OGRGeometry  *Polygonize() const

Poligonizar um conjunto de arestas esparsas        

irá criar e retornar um novo objeto de geometria contendo a coleção remontada de polígonos: NULL será retornado se a coleção de entrada não corresponder a uma string multilinha, ou se as arestas não puderem ser remontadas em polígonos devido a inconsistências topológicas

Retorna: a geometria recém-alocada agora pertencente ao chamador ou NULL em caso de falha

// 创建一组线要素
    OGRLineString lineStrings[3];
    lineStrings[0].addPoint(0, 0);
    lineStrings[0].addPoint(0, 10);

    lineStrings[1].addPoint(0, 10);
    lineStrings[1].addPoint(10, 10);

    lineStrings[2].addPoint(10, 10);
    lineStrings[2].addPoint(10, 0);

    // 创建一个几何对象集合并添加线要素
    OGRGeometryCollection collection;
    for (int i = 0; i < 3; i++) {
        collection.addGeometry(&lineStrings[i]);
    }

    // 对几何对象进行多边形化处理
    OGRGeometry* polygonizedGeometry = collection.Polygonize();

    // 输出多边形化处理结果的类型
    if (polygonizedGeometry != nullptr) {
        OGRwkbGeometryType geomType = polygonizedGeometry->getGeometryType();
        std::cout << "Polygonized geometry type: " << OGRGeometryTypeToName(geomType) << std::endl;

        // 释放多边形化处理结果的内存
        delete polygonizedGeometry;
    } else {
        std::cout << "Failed to polygonize the geometries." << std::endl;
    }

Distância3D

virtual double Distance3D(const  OGRGeometry  *poOtherGeom) const 

Retorna a distância 3D entre duas geometrias

As distâncias são expressas nas mesmas unidades que as coordenadas geométricas

Retorna: a distância entre duas formas geométricas

// 创建两个点
OGRPoint point1(0, 0, 0);
OGRPoint point2(3, 4, 5);

// 计算两点之间的三维空间距离
double distance3D = point1.Distance3D(&point2);

cout << "3D Distance between point1 and point2: " << distance3D << endl;

 

trocaXY

virtual  void  swapXY ( )

troque as coordenadas x e y

// 创建一个点对象
OGRPoint point(10, 20);

// 打印交换前的坐标
std::cout << "Before swap: X=" << point.getX() << ", Y=" << point.getY() << std::endl;

// 调用 swapXY 函数交换 X 和 Y 坐标
point.swapXY();

// 打印交换后的坐标
std::cout << "After swap: X=" << point.getX() << ", Y=" << point.getY() << std::endl;

projeção

linha  OGRPoint  * toPoint ( )

Downcast para OGRPoint*

Significa verificar previamente que  wkbFlatten(getGeometryType())  == wkbPoint

Existem muitas projeções diferentes, mas em geral é de alta latitude para baixa dimensão

Acho que você gosta

Origin blog.csdn.net/qq_69574549/article/details/131924382
Recomendado
Clasificación