GDAL version 2.1.1
If I open a geospatial raster file, such as a GeoTIFF or DTED file, with GDAL, then I can get the coordinate system info for that file, as a string in OpenGIS WKT format. For example:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
The C++ code I use to get that info is simple and straightforward.
string path = "somewhere.dt1";
unsigned int openFlags = GA_ReadOnly;
GDALDataset * pDataset = static_cast<GDALDataset *>( GDALOpenEx(
path.c_str(),
openFlags,
NULL, NULL, NULL ) );
string projWkt = pDataset->GetProjectionRef();
OGRSpatialReference srs( projWkt.c_str() );
srs.dumpReadable();
However, when I open a geospatial vector file, such as a shapefile, with GDAL, I get only a blank string for the coordinate system info. The only difference in the C++ code I use is that I must also provide the GDAL_OF_VECTOR
flag to GDALOpenEx()
.
string path = "elsewhere.shp";
unsigned int openFlags = GA_ReadOnly | GDAL_OF_VECTOR;
GDALDataset * pDataset = static_cast<GDALDataset *>( GDALOpenEx(
path.c_str(),
openFlags,
NULL, NULL, NULL ) );
The shapefile I am opening does have a valid coordinate system. I can confirm that by opening the shapefile in ArcMap or ArcCatalog. Both of those apps are able to tell me the coordinate system and projection info.
So, why am I not able to fetch it via this GDAL API?
Is there a different mechanism for vector files?