[gdal-dev] addRingDirectly is crashed

Martin Chapman mchapman at hyperacktive.com
Sat Apr 18 06:53:51 PDT 2020


Your point ordering is counter clockwise.  Did you intend to add a hole?  I think exterior rings must be  clockwise.  Also, I think you need to set the spatial reference of the ring.

Best regards,
Martin Chapman

> On Apr 18, 2020, at 7:15 AM, Andrew C Aitchison <andrew at aitchison.me.uk> wrote:
> 
> 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);
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list