From d6a5e52c74dc82adebc8b2d2a622f3a358e051fd Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Thu, 21 Jun 2012 20:18:12 +0000 Subject: [PATCH] Added method that includes the string "MISSING GDAL DATA" in the output of postgis_gdal_version() if GDAL is unable to access its data files git-svn-id: http://svn.osgeo.org/postgis/trunk@9968 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 29 +++++++++++++++++++++++++ raster/rt_core/rt_api.h | 15 +++++++++++++ raster/rt_pg/rt_pg.c | 18 ++++++++++++++- raster/test/core/testapi.c | 11 ++++++++++ raster/test/regress/Makefile.in | 5 ++++- raster/test/regress/check_gdal.sql | 6 +++++ raster/test/regress/check_gdal_expected | 0 7 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 raster/test/regress/check_gdal.sql create mode 100644 raster/test/regress/check_gdal_expected diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 3538e617c..101994687 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -307,6 +307,9 @@ rt_util_extent_type(const char *name) { return ET_INTERSECTION; } +/* + convert the spatial reference string from a GDAL recognized format to either WKT or Proj4 +*/ char* rt_util_gdal_convert_sr(const char *srs, int proj4) { OGRSpatialReferenceH hsrs; @@ -333,6 +336,9 @@ rt_util_gdal_convert_sr(const char *srs, int proj4) { return rtn; } +/* + is the spatial reference string supported by GDAL +*/ int rt_util_gdal_supported_sr(const char *srs) { OGRSpatialReferenceH hsrs; @@ -348,6 +354,29 @@ rt_util_gdal_supported_sr(const char *srs) { return 0; } +/* + is GDAL configured correctly? +*/ +int rt_util_gdal_configured(void) { + + /* set of EPSG codes */ + if (!rt_util_gdal_supported_sr("EPSG:4326")) + return 0; + if (!rt_util_gdal_supported_sr("EPSG:4269")) + return 0; + if (!rt_util_gdal_supported_sr("EPSG:4267")) + return 0; + if (!rt_util_gdal_supported_sr("EPSG:3310")) + return 0; + if (!rt_util_gdal_supported_sr("EPSG:2163")) + return 0; + + return 1; +} + +/* + is the driver registered? +*/ int rt_util_gdal_driver_registered(const char *drv) { int count = GDALGetDriverCount(); diff --git a/raster/rt_core/rt_api.h b/raster/rt_core/rt_api.h index 70edabc97..34c86cc9f 100644 --- a/raster/rt_core/rt_api.h +++ b/raster/rt_core/rt_api.h @@ -1554,12 +1554,27 @@ rt_util_gdal_version(const char *request); rt_extenttype rt_util_extent_type(const char *name); +/* + convert the spatial reference string from a GDAL recognized format to either WKT or Proj4 +*/ char* rt_util_gdal_convert_sr(const char *srs, int proj4); +/* + is the spatial reference string supported by GDAL +*/ int rt_util_gdal_supported_sr(const char *srs); +/* + is GDAL configured correctly? +*/ +int +rt_util_gdal_configured(void); + +/* + is the driver registered? +*/ int rt_util_gdal_driver_registered(const char *drv); diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index df747bc68..8b5f34fa6 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -628,7 +628,23 @@ PG_FUNCTION_INFO_V1(RASTER_gdal_version); Datum RASTER_gdal_version(PG_FUNCTION_ARGS) { const char *ver = rt_util_gdal_version("--version"); - text *result = cstring2text(ver); + text *result; + + /* add indicator if GDAL isn't configured right */ + if (!rt_util_gdal_configured()) { + char *rtn = NULL; + rtn = palloc(strlen(ver) + strlen(" MISSING GDAL DATA") + 1); + if (!rtn) + result = cstring2text(ver); + else { + sprintf(rtn, "%s MISSING GDAL DATA", ver); + result = cstring2text(rtn); + pfree(rtn); + } + } + else + result = cstring2text(ver); + PG_RETURN_POINTER(result); } diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index ca486930b..05f1ef062 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -103,6 +103,13 @@ fillRasterToPolygonize(int hasnodata, double nodatavalue) return raster; } +static void testGDALConfigured() { + int rtn; + + rtn = rt_util_gdal_configured(); + CHECK((rtn != 0)); +} + static void testGDALPolygonize() { int i; rt_raster rt; @@ -2941,6 +2948,10 @@ main() rt_raster_set_skews(raster, 0, 0); } + printf("Testing rt_util_gdal_configured... "); + testGDALConfigured(); + printf("OK\n"); + printf("Testing rt_raster_gdal_polygonize... "); testGDALPolygonize(); printf("OK\n"); diff --git a/raster/test/regress/Makefile.in b/raster/test/regress/Makefile.in index 0e5b906e9..1c56bbb74 100644 --- a/raster/test/regress/Makefile.in +++ b/raster/test/regress/Makefile.in @@ -29,6 +29,9 @@ REGRESS_INSTALLDIR=$(POSTGIS_SRC)/regress/00-regress-install PATH := $(PGSQL_BINDIR):$(PATH) export PATH +TEST_FIRST = \ + check_gdal + TEST_METADATA = \ check_raster_columns \ check_raster_overviews @@ -130,7 +133,7 @@ TEST_LOADER = \ loader/Tiled10x10 \ loader/Tiled10x10Copy -TESTS = $(TEST_METADATA) $(TEST_IO) $(TEST_FUNC) \ +TESTS = $(TEST_FIRST) $(TEST_METADATA) $(TEST_IO) $(TEST_FUNC) \ $(TEST_PROPS) $(TEST_BANDPROPS) \ $(TEST_UTILITY) $(TEST_GIST) $(TEST_SREL) \ $(TEST_BUGS) \ diff --git a/raster/test/regress/check_gdal.sql b/raster/test/regress/check_gdal.sql new file mode 100644 index 000000000..0da564e5d --- /dev/null +++ b/raster/test/regress/check_gdal.sql @@ -0,0 +1,6 @@ +SELECT + CASE + WHEN strpos(postgis_gdal_version(), 'MISSING') <> 0 + THEN false + ELSE NULL + END; diff --git a/raster/test/regress/check_gdal_expected b/raster/test/regress/check_gdal_expected new file mode 100644 index 000000000..e69de29bb -- 2.50.1