[gdal-dev] addRingDirectly is crashed

Andrew C Aitchison andrew at aitchison.me.uk
Sat Apr 18 06:04:21 PDT 2020


On Sat, 18 Apr 2020, Ahmet Temiz wrote:

> Hi,
> What am I doing wrong?
> addRingDirectly is  crashed
>
> f( poGeometry != NULL && wkbFlatten(poGeometry->getGeometryType()) ==
> wkbPolygon )
>              {
>                   OGRPolygon *poPolygon = (OGRPolygon *) poGeometry;
>
>             // Box,
>                  OGRLinearRing * poLinearRing {};
>                   OGRPolygon *bbox {};
>
>                   OGREnvelope oEnv1;
>
>                   poPolygon->getEnvelope(&oEnv1);
>
>                   poLinearRing = new OGRLinearRing({});
>                   poLinearRing-> addPoint (oEnv1.MinX,oEnv1.MinY  );
>                   poLinearRing-> addPoint (oEnv1.MaxX,oEnv1.MinY  );
>                   poLinearRing-> addPoint (oEnv1.MaxX,oEnv1.MaxY  );
>                   poLinearRing-> addPoint (oEnv1.MinX,oEnv1.MaxY  );
>                   poLinearRing-> addPoint (oEnv1.MinX,oEnv1.MinY  );
>
>                   bbox= new OGRPolygon({});
>                   bbox-> addRingDirectly(poLinearRing );   ** crash occur
>                                           Segmentation fault (core dumped)


The following works for me (I don't have {} in my new ...() ):

     OGRLinearRing* linearRing = new OGRLinearRing ();

     linearRing->setCoordinateDimension(2);
     linearRing->setNumPoints(4);

     linearRing->setPoint( 0, TL.lon, TL.lat );
     linearRing->setPoint( 1, TR.lon, TR.lat );
     linearRing->setPoint( 2, BR.lon, BR.lat );
     linearRing->setPoint( 3, BL.lon, BL.lat );

     OGRPolygon* poly = new OGRPolygon ();

     poly->addRingDirectly(linearRing);
     poly->closeRings();

     poFeature->SetGeometryDirectly(poly);



More information about the gdal-dev mailing list