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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Mar 7 02:38:31 PST 2023


I switched getting coordinate units from the expanded proj4string 
representation to GetAttrValue("UNIT", 0), but failed; try

#include <gdal.h>
#include <gdal_priv.h>
#include <iostream>

int main()
{
	OGRSpatialReference *srs = new OGRSpatialReference;
	int epsg = 3031;
	srs->importFromEPSG(epsg);
	std::cout << epsg << ":" << srs->GetAttrValue("UNIT",0) << std::endl;
	const char *proj4s = "+proj=eqearth";
	srs->importFromProj4(proj4s);
	const char *u = srs->GetAttrValue("UNIT",0);
	std::cout << proj4s << ":" << (u ? u : "NULL") << std::endl;
	return 0;
}

which gives

3031:metre
+proj=eqearth:NULL

whereas the proj4string expansion of "+proj=eqearth" is "+proj=eqearth 
+lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs", so has the units.

What do I miss here? What is the recommended way to get coordinate units?
-- 
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081


More information about the gdal-dev mailing list