Search code examples
c++ogr

OGRGeometry Intersection


i need intersect 2 OGRGeometry. In my code, i'm defining a OGRPolygon that will be intersected with other OGRGeometry.

This my OGRPolygon:

    OGRLinearRing ring;
    OGRPolygon poly;
    ring.addPoint(-300, 300);
    ring.addPoint(300, 300);
    ring.addPoint(-300, -300);
    ring.addPoint(300, -300);
    ring.closeRings();
    poly.addRing(&ring);

And this is the Intersection code:

 for (int i = 0; i < geo5.size(); i++)
 {  
        qDebug() << geo5[i]->Intersect(&poly);
        if (geo5[i]->Intersect(&poly)) {
            qDebug() << "El tipo es "<< geo5[i]->Intersection(&poly);
            OGRGeometry* newGeo = geo5[i]->Intersection(&poly);
        }

 }

newGeo always is null, and compiler throw this:

Exception thrown at 0x00007FFE11593FB8 in ShapeViewer.exe: Microsoft C++ exception: geos::util::TopologyException at memory location 0x000000370A0FE5C0.

Could some one help me with this problem please? Thanks all!


Solution

  • Definition of ring is invalid

    -300,300 [1]    300,300 [2]
    
    
    -300,-300 [3]   300,-300 [4]
    

    there is intersection point between line [2,3] and [4,1] after connecting [1] with [4] points. You should add [4] point before adding [3].