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

Andrew C Aitchison andrew at aitchison.me.uk
Fri Oct 14 02:34:16 PDT 2022


On Fri, 14 Oct 2022, Johannes Paul wrote:

> Hello,
> Yes i would need a polygon with the raster footprint.

apps/gdaltindex.cpp implements the gdaltindex application
and is written in C++, so should do what you wish.

Note that this assumes the raster geolocation is given by the affine 
transformation GDALDataset::GetGeoTransform(), which is usually true.
Howver, if the raster geolocation is given by one of the other methods in
https://gdal.org/user/raster_data_model.html (GCPs and/or RPCs)
you may have to do the work yourself.


> 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

-- 
Andrew C. Aitchison                      Kendal, UK
                    andrew at aitchison.me.uk


More information about the gdal-dev mailing list