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

Even Rouault even.rouault at spatialys.com
Tue Mar 7 08:11:14 PST 2023


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);


-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list