]> granicus.if.org Git - postgis/commitdiff
Addition of GUC postgis.gdal.datapath to specify GDAL config variable GDAL_DATA....
authorBborie Park <bkpark at ucdavis.edu>
Thu, 20 Jun 2013 15:57:50 +0000 (15:57 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 20 Jun 2013 15:57:50 +0000 (15:57 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11554 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
raster/rt_pg/rt_pg.c
raster/test/regress/check_gdal.sql

diff --git a/NEWS b/NEWS
index 066ed9adcfd3831904dfd1df097a3c27a1327c70..3161a8ff882e6c355a9522453f6394041bb75878 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ PostGIS 2.2.0
  * Enhancements *
 
   - Added missing variants of ST_TPI(), ST_TRI() and ST_Roughness()
+  - #1678, Added GUC postgis.gdal.datapath to specify GDAL config
+    variable GDAL_DATA
   - #2361, Added spatial_index column to raster_columns view
 
  * Bug Fixes *
index d3cc46a2c8de2a1a8f840b1e21c5e8e1484eda06..e885b0a0b6a9806be076a181389f67fae2419a0f 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "../../postgis_config.h"
 
+#include "utils/guc.h"
 #include "lwgeom_pg.h"
 #include "rt_pg.h"
 #include "pgsql_compat.h"
  */
 PG_MODULE_MAGIC;
 
-/*
- * Module load callback
- */
+/* Module load callback */
 void _PG_init(void);
-void
-_PG_init(void)
-{
-    /* Install liblwgeom handlers */
-    pg_install_lwgeom_handlers();
-
-    /* TODO: Install raster callbacks (see rt_init_allocators) */
-}
 
 /***************************************************************
  * Internal functions must be prefixed with rtpg_.  This is
@@ -100,6 +91,9 @@ static char *rtpg_removespaces(char *str);
 static char *rtpg_trim(const char* input);
 static char *rtpg_getSR(int srid);
 
+static char *gdaldatapath;
+static void rtpg_assignHookGDALDataPath(const char *newpath, void *extra);
+
 /***************************************************************
  * Some rules for returning NOTICE or ERROR...
  *
@@ -393,6 +387,31 @@ Datum RASTER_union_finalfn(PG_FUNCTION_ARGS);
 /* raster clip */
 Datum RASTER_clip(PG_FUNCTION_ARGS);
 
+/* Module load callback */
+void
+_PG_init(void) {
+       /* Install liblwgeom handlers */
+       pg_install_lwgeom_handlers();
+
+       /* TODO: Install raster callbacks (see rt_init_allocators)??? */
+
+       /* Define custom GUC variables. */
+       DefineCustomStringVariable(
+               "postgis.gdal.datapath", /* name */
+               "Path to GDAL data files.", /* short_desc */
+               "Physical path to directory containing GDAL data files (sets the GDAL_DATA config option).", /* long_desc */
+               &gdaldatapath, /* valueAddr */
+               NULL, /* bootValue */
+               PGC_SUSET, /* GucContext context */
+               0, /* int flags */
+#if POSTGIS_PGSQL_VERSION >= 91
+               NULL, /* GucStringCheckHook check_hook */
+#endif
+               rtpg_assignHookGDALDataPath, /* GucStringAssignHook assign_hook */
+               NULL  /* GucShowHook show_hook */
+       );
+}
+
 /* string replacement function taken from
  * http://ubuntuforums.org/showthread.php?s=aa6f015109fd7e4c7e30d2fd8b717497&t=141670&page=3
  */
@@ -618,8 +637,7 @@ rtpg_trim(const char *input) {
 }
 
 static char*
-rtpg_getSR(int srid)
-{
+rtpg_getSR(int srid) {
        int i = 0;
        int len = 0;
        char *sql = NULL;
@@ -724,6 +742,21 @@ LIMIT 1
        return srs;
 }
 
+static void
+rtpg_assignHookGDALDataPath(const char *newpath, void *extra) {
+       POSTGIS_RT_DEBUGF(4, "newpath = %s", newpath);
+
+       /* clear finder cache */
+       CPLFinderClean();
+
+       /* clear cached OSR */
+       OSRCleanup();
+
+       /* set GDAL_DATA */
+       CPLSetConfigOption("GDAL_DATA", newpath);
+       POSTGIS_RT_DEBUGF(4, "GDAL_DATA = %s", CPLGetConfigOption("GDAL_DATA", NULL));
+}
+
 PG_FUNCTION_INFO_V1(RASTER_lib_version);
 Datum RASTER_lib_version(PG_FUNCTION_ARGS)
 {
index 764619f0b73b0d21a2057c5e0dc9c2c90b0fa6a8..d01688fc696c9f7e16632024639fefe745e8186c 100644 (file)
@@ -4,3 +4,17 @@ SELECT
                        THEN false
                ELSE NULL
        END;
+SET postgis.gdal.datapath = '';
+SELECT 
+       CASE
+               WHEN strpos(postgis_gdal_version(), 'GDAL_DATA') <> 0
+                       THEN NULL
+               ELSE TRUE
+       END;
+SET postgis.gdal.datapath = default;
+SELECT 
+       CASE
+               WHEN strpos(postgis_gdal_version(), 'GDAL_DATA') <> 0
+                       THEN false
+               ELSE NULL
+       END;