Cannot get EPSG from Shapefile with OGR / GDAL

At the moment I am working in the peak of a shapefile 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 an EPSG number with:

 atoi(spatialRef->GetAuthorityCode(NULL)); 

This work is beautiful in all my form files less than one. In this case, the method always returns null.

I am trying to use:

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

And all this method returns "" .

I check this shapefile in gis because QGIS and QGIS automatically detect that its EPSG is 25830.

My question is this: can projection information be read in a different way than what I'm doing?

I am waiting for your suggestions.

Thank you very much.

EDIT

This is the contents of the .prj file:

PROJCS ["ETRS89_UTM_zone_30N", GEOGCS ["GCS_ETRS_1989", DATUM ["D_ETRS_1989", spheroid ["GRS_1980", 6378137,298.257222101]], PRIMEM ["Greenwich", 0], BLOCK [+01329, 329451014329014329014, +32159329, 459, 459, 951, 459, 451, 954, 951, 459, 259, 451, 958, 259, 329, 459, 259, 329, 259, 329, 259, 325, 95, 9, 329, 259, 451, 958, 951, 951, 954, 951, 954, 951, 954, 951, 954, 951, 951, 954, 951, 958 blocks ], PROJECTIONS ["Transverse_Mercator"], parameter ["latitude_of_origin", 0], parameter ["central_meridian", - 3], parameter ["scale_factor", 0.9996], parameter ["false_easting", 500000], parameter [ "false_northing", 0], block ["Meter", 1]]

+5
source share
1 answer

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 this helps!

+1
source

Source: https://habr.com/ru/post/1275756/


All Articles