Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get EPSG from Shapefile with OGR/GDAL

Tags:

c++

qt

gdal

ogr

At this moment, i'm working in a shapefile visor in C++ and QT and using the GDAL/OGR library. I have this method to get the EPSG of my shapefiles:

OGRLayer layer = dataset->GetLayer(0);
OGRSpatialReference *spatialRef = layer->GetSpatialRef();

With this I get the EPSG number with:

atoi(spatialRef->GetAuthorityCode(NULL));

This work fine in all my shape files less one. In this case, the method always retun null.

I try use:

spatialRef->GetAuthorityCode("PROJCS");
spatialRef->GetAuthorityCode("GEOGCS");
spatialRef->GetAuthorityName("GEOGCS");

And all this method return "".

I check this shapefile in a gis program as QGIS and QGIS autodetected that his EPSG is 25830.

My question is this: could the projection information be readed with a different method than what I'm doing?

I wait yours suggestions.

Thank a lot.

EDIT

This is the content of .prj file:

PROJCS["ETRS89_UTM_zone_30N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]

like image 744
Zharios Avatar asked Nov 07 '22 09:11

Zharios


1 Answers

Something like this should work:

OGRLayer  * layer = dataset->GetLayer(0);
layer->ResetReading();
OGRFeature * feat= layer->GetNextFeature(); 
OGRGeometry * geom = feat->GetGeometryRef(); 
OGRSpatialReference * spatRef = geom->getSpatialReference(); 
int EPSG =  spatRef->GetEPSGGeogCS(); 

Hope it helps!

like image 176
Streamsoup Avatar answered Nov 14 '22 23:11

Streamsoup