[gdal-dev] getting SRS units from GetAttrValue("UNIT", 0)?

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Mar 7 13:45:51 PST 2023



On 07/03/2023 17:11, Even Rouault wrote:
> 
> Le 07/03/2023 à 17:08, Edzer Pebesma a écrit :
>> Thanks, Even!
>>
>> I was after the units of the horizontal coordinates; GetLinearUnits() 
>> returns "unknown" for EPSG:4326 and, according to the docs returns the 
>> units of the vertical coordinate in 3D CRS (didn't check). So what I 
>> now use is GetAttrValue("UNIT", 0) (which returns "degree" for 
>> EPSG:4326"), and if that returns NULL, use GetLinearUnit(&unit) if its 
>> value differs from "unknown".
> 
> Try:
> 
> if( srs->IsGeographic() )
>     srs->GetAngularUnits(&unit);
> else
> 
>    srs->GetLinearUnits(&unit);
> 
> 
Great, that's much more elegant. Thanks!
-- 
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081


More information about the gdal-dev mailing list