From: Bborie Park Date: Thu, 20 Jun 2013 15:57:50 +0000 (+0000) Subject: Addition of GUC postgis.gdal.datapath to specify GDAL config variable GDAL_DATA.... X-Git-Tag: 2.2.0rc1~1480 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4336f28e4fc6915590043ceffc67284a2e8ae256;p=postgis Addition of GUC postgis.gdal.datapath to specify GDAL config variable GDAL_DATA. Ticket #1678 git-svn-id: http://svn.osgeo.org/postgis/trunk@11554 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 066ed9adc..3161a8ff8 100644 --- 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 * diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index d3cc46a2c..e885b0a0b 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -48,6 +48,7 @@ #include "../../postgis_config.h" +#include "utils/guc.h" #include "lwgeom_pg.h" #include "rt_pg.h" #include "pgsql_compat.h" @@ -69,18 +70,8 @@ */ 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) { diff --git a/raster/test/regress/check_gdal.sql b/raster/test/regress/check_gdal.sql index 764619f0b..d01688fc6 100644 --- a/raster/test/regress/check_gdal.sql +++ b/raster/test/regress/check_gdal.sql @@ -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;