]> granicus.if.org Git - postgis/commitdiff
Added method that includes the string "MISSING GDAL DATA" in the output
authorBborie Park <bkpark at ucdavis.edu>
Thu, 21 Jun 2012 20:18:12 +0000 (20:18 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 21 Jun 2012 20:18:12 +0000 (20:18 +0000)
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
raster/rt_core/rt_api.h
raster/rt_pg/rt_pg.c
raster/test/core/testapi.c
raster/test/regress/Makefile.in
raster/test/regress/check_gdal.sql [new file with mode: 0644]
raster/test/regress/check_gdal_expected [new file with mode: 0644]

index 3538e617c8512c0549807f61e6f517f6ecccb2e3..1019946874dca2146c1c5bebaeb0a9540232134a 100644 (file)
@@ -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();
index 70edabc97b121d9b241eb7ba3c3761c6a31e3056..34c86cc9f4de798740a1e0fe1e447e6b18da240a 100644 (file)
@@ -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);
 
index df747bc68452794d0031360e29b2ebf28101144b..8b5f34fa674e79719015ac0ca601259c5dcbf0cc 100644 (file)
@@ -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);
 }
 
index ca486930b67ac34f634cf095d4f3984c6e5d76bf..05f1ef062851b0367ec0092029c14becd9378173 100644 (file)
@@ -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");
index 0e5b906e925f19a022239451440dbee3b6564e0b..1c56bbb74f9ffad3b2dfc2588e39dfbf07e401f8 100644 (file)
@@ -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 (file)
index 0000000..0da564e
--- /dev/null
@@ -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 (file)
index 0000000..e69de29