[gdal-dev] C++ Getting OGRGeometry out of GDALDataset

Laurențiu Nicola lnicola at dend.ro
Fri Oct 14 01:09:44 PDT 2022


In that case you need to create it manually. There's an example here, using Python, but the API is pretty similar: https://pcjericks.github.io/py-gdalogr-cookbook/geometry.html#create-a-polygon. Remember to close it by duplicating the first vertex.

To get the footprint itself, you'll need to look at the GeoTransform of the raster and its dimensions. https://gdal.org/tutorials/geotransforms_tut.html has more details. Basically, one corner of the footprint is in GT(0) and GT(3), and to get the other four you'll need to translate that point by the spacing in each direction multiplied by the number of pixels. Most images won't be using the rotation parameters.

Laurentiu

On Fri, Oct 14, 2022, at 11:03, Johannes Paul wrote:
> Hello,
> Yes i would need a polygon with the raster footprint.
> Thanks
> 
> 
> Le ven. 14 oct. 2022 à 10:01, Laurențiu Nicola via gdal-dev <gdal-dev at lists.osgeo.org> a écrit :
>> __
>> Hi Mats,
>> 
>> Vector and raster datasets are pretty much different things in GDAL. And generally it would be a good idea to check whether e.g. GetLayer actually returns a pointer or nullptr.
>> 
>> What exactly do you mean by "associated OGRPolygon"? Do you want a polygon with the same footprint as the raster?
>> 
>> Laurentiu
>> 
>> On Fri, Oct 14, 2022, at 10:51, Johannes Paul wrote:
>>> Hello,
>>> Is there a way to get the OGRGeometry object out of a GDALDataset object in c++?
>>> My GDALDataset is a raster and i would like to get the associated OGRPolygon out of it.
>>> I've used:
>>> srcDataset->GetLayer(0)->GetNextFeature()->GetGeometryRef()->toPolygon()
>>> However i keep getting segmentation faults error.
>>> Any help would be appreciated.
>>> Thanks
>>> _______________________________________________
>>> gdal-dev mailing list
>>> gdal-dev at lists.osgeo.org
>>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>> 
>> 
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20221014/f2756ad4/attachment-0001.htm>


More information about the gdal-dev mailing list