From ff4cdc048cc62ad9ce0a11ac641bfc7a3bd4705a Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Sat, 7 Jan 2012 15:24:08 +0000 Subject: [PATCH] Have rt_raster_from_gdal_dataset attempt to determine the SRID of the raster using OSR. git-svn-id: http://svn.osgeo.org/postgis/trunk@8695 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 2e1a2d73b..84b421cc6 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -6849,6 +6849,8 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) { int i = 0; int status; + const char *srs = NULL; + GDALRasterBandH gdband = NULL; GDALDataType gdpixtype = GDT_Unknown; rt_band band; @@ -6898,8 +6900,24 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) { /* apply raster attributes */ rt_raster_set_geotransform_matrix(rast, gt); + /* srid */ - /* CANNOT SET srid AS srid IS NOT AVAILABLE IN GDAL dataset */ + srs = GDALGetProjectionRef(ds); + if (srs != NULL && srs[0] != '\0') { + OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL); + if (OSRSetFromUserInput(hSRS, srs) == OGRERR_NONE) { + const char* pszAuthorityName = OSRGetAuthorityName(hSRS, NULL); + const char* pszAuthorityCode = OSRGetAuthorityCode(hSRS, NULL); + if ( + pszAuthorityName != NULL && + strcmp(pszAuthorityName, "EPSG") == 0 && + pszAuthorityCode != NULL + ) { + rt_raster_set_srid(rast, atoi(pszAuthorityCode)); + } + } + OSRDestroySpatialReference(hSRS); + } /* copy bands */ numBands = GDALGetRasterCount(ds); -- 2.40.0