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]]
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With