]> granicus.if.org Git - postgis/commitdiff
add VSICURL keyword for GUC postgis.gdal_enabled_drivers. add GUC posgis.enable_outdb...
authorBborie Park <bkpark at ucdavis.edu>
Sat, 26 Apr 2014 14:01:02 +0000 (14:01 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sat, 26 Apr 2014 14:01:02 +0000 (14:01 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12492 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
doc/reference_guc.xml
raster/rt_core/librtcore.h
raster/rt_core/rt_band.c
raster/rt_core/rt_util.c
raster/rt_pg/rtpostgis.c
raster/test/cunit/cu_misc.c
raster/test/regress/loader/BasicOutDB.select.sql
raster/test/regress/permitted_gdal_drivers.sql
raster/test/regress/rt_bytea.sql

diff --git a/NEWS b/NEWS
index 323939e82f00fe7da46fb95cc7f3ac440da7633a..b43e2420236e1a6fa576df34a8934d2ec4d24551 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ PostGIS 2.2.0
   - Added missing variants of ST_TPI(), ST_TRI() and ST_Roughness()
   - Added GUC postgis.gdal_enabled_drivers to specify GDAL config
     variable GDAL_SKIP
+  - Added GUC postgis.enable_outdb_rasters to enable access to
+    rasters with out-db bands
   - #1678, Added GUC postgis.gdal_datapath to specify GDAL config
     variable GDAL_DATA
   - #2341, New mask parameter for ST_MapAlgebra
index f42e45d48363a52aac4b1e3b5e024a6789d10c11..5c5a773c29ca2247b62ebf3be90c68d5dd2375c8 100644 (file)
@@ -103,7 +103,19 @@ SET postgis.gdal_datapath = 'C:/Program Files/PostgreSQL/9.3/gdal-data';</progra
 \r
                                <note>\r
                                        <para>\r
-                                               There are two special codes available to enable or disable all GDAL drivers: ENABLE_ALL and DISABLE_ALL. The codes are case-sensitive.\r
+                                               There are three special codes available for <varname>postgis.gdal_enabled_drivers</varname>. The codes are case-sensitive.\r
+\r
+                                               <itemizedlist>\r
+                                                       <listitem>\r
+                                                               <para><varname>DISABLE_ALL</varname> disables all GDAL drivers. If present, <varname>DISABLE_ALL</varname> overrides all other values in <varname>postgis.gdal_enabled_drivers</varname>.</para>\r
+                                               </listitem>\r
+                                                       <listitem>\r
+                                                               <para><varname>ENABLE_ALL</varname> enables all GDAL drivers.</para>\r
+                                               </listitem>\r
+                                                       <listitem>\r
+                                                               <para><varname>VSICURL</varname> enables GDAL's <varname>/vsicurl/</varname> virtual file system.</para>\r
+                                               </listitem>\r
+                                               </itemizedlist>\r
                                        </para>\r
                                        <para>\r
                                                When <varname>postgis.gdal_enabled_drivers</varname> is set to DISABLE_ALL, attempts to use out-db rasters, ST_FromGDALRaster(), ST_AsGDALRaster(), ST_AsTIFF(), ST_AsJPEG() and ST_AsPNG() will result in error messages.\r
@@ -153,9 +165,65 @@ SET postgis.gdal_enabled_drivers = 'DISABLE_ALL';
                                        <xref linkend="RT_ST_AsGDALRaster" />, \r
                                        <xref linkend="RT_ST_AsTIFF" />, \r
                                        <xref linkend="RT_ST_AsPNG" />, \r
-                                       <xref linkend="RT_ST_AsJPEG" />\r
+                                       <xref linkend="RT_ST_AsJPEG" />, \r
+                                       <xref linkend="postgis_enable_outdb_rasters" />\r
                                </para>\r
                        </refsection>\r
        </refentry>\r
 \r
+  <refentry id="postgis_enable_outdb_rasters">\r
+                       <refnamediv>\r
+                               <refname>postgis.enable_outdb_rasters</refname>\r
+                               <refpurpose>\r
+                                       A boolean configuration option to enable access to out-db raster bands.\r
+                               </refpurpose>\r
+                       </refnamediv>\r
+\r
+                       <refsection>\r
+                               <title>Description</title>\r
+                               <para>\r
+                                       A boolean configuration option to enable access to out-db raster bands.\r
+                               </para>\r
+\r
+                               <note>\r
+                                       <para>\r
+                                               This option can be set in PostgreSQL's configuration file: postgresql.conf. It can also be set by connection or transaction.\r
+                                       </para>\r
+                               </note>\r
+\r
+                               <note>\r
+                                       <para>\r
+                                               Even if <varname>postgis.enable_outdb_rasters</varname> is True, the GUC <varname>postgis.enable_outdb_rasters</varname> determines the accessible raster formats.\r
+                                       </para>\r
+                               </note>\r
+\r
+                               <note>\r
+                                       <para>\r
+                                               In the standard PostGIS installation, <varname>postgis.enable_outdb_rasters</varname> is set to False.\r
+                                       </para>\r
+                               </note>\r
+\r
+                               <para>Availability: 2.2.0</para>\r
+\r
+                       </refsection>\r
+\r
+                       <refsection>\r
+                               <title>Examples</title>\r
+                               <para>Set and reset <varname>postgis.enable_outdb_rasters</varname></para>\r
+\r
+                               <programlisting>\r
+SET postgis.enable_outdb_rasters TO True;\r
+SET postgis.enable_outdb_rasters = default;\r
+SET postgis.enable_outdb_rasters = True;\r
+SET postgis.enable_outdb_rasters = False;\r
+                               </programlisting>\r
+                       </refsection>\r
+\r
+                       <refsection>\r
+                               <title>See Also</title>\r
+                               <para>\r
+                                       <xref linkend="postgis_gdal_enabled_drivers" />\r
+                               </para>\r
+                       </refsection>\r
+       </refentry>\r
 </sect1>\r
index c69429d4e237099b56c4274bed671f31d6c25bee..e60d69818f4e6edff1b35e28bcbe7b9ac878ae14 100644 (file)
@@ -2006,6 +2006,7 @@ extern void rtdealloc(void *mem);
 
 #define GDAL_ENABLE_ALL "ENABLE_ALL"
 #define GDAL_DISABLE_ALL "DISABLE_ALL"
+#define GDAL_VSICURL "VSICURL"
 
 /*
  * Set of functions to clamp double to int of different size
index c4dd6f563a84ddd8eac5307f4ab83bf81803dc92..f18d8855c00f2f1b561d13cb2241f9be47a7ecde 100644 (file)
@@ -316,6 +316,9 @@ rt_band_get_data(rt_band band) {
                return band->data.mem;
 }
 
+/* variable for PostgreSQL GUC: postgis.enable_outdb_rasters */
+char enable_outdb_rasters = 1;
+
 /**
        * Load offline band's data.  Loaded data is internally owned
        * and should not be released by the caller.  Data will be
@@ -352,6 +355,12 @@ rt_band_load_offline_data(rt_band band) {
                return ES_ERROR;
        }
 
+       /* offline_data is disabled */
+       if (!enable_outdb_rasters) {
+               rterror("rt_band_load_offline_data: Access to offline bands disabled");
+               return ES_ERROR;
+       }
+
        rt_util_gdal_register_all(0);
        /*
        hdsSrc = rt_util_gdal_open(band->data.offline.path, GA_ReadOnly, 1);
index 4b62deedb829826e8c87bf513704937d2f86bbdf..824cfd2d4b181621e6c1d55b71c1f8e7622021e4 100644 (file)
@@ -328,8 +328,6 @@ int rt_util_gdal_configured(void) {
        return 1;
 }
 
-char *gdal_enabled_drivers = NULL;
-
 /*
        register all GDAL drivers
 */
@@ -372,6 +370,9 @@ rt_util_gdal_driver_registered(const char *drv) {
        return 0;
 }
 
+/* variable for PostgreSQL GUC: postgis.gdal_enabled_drivers */
+char *gdal_enabled_drivers = NULL;
+
 /*
        wrapper for GDALOpen and GDALOpenShared
 */
@@ -379,12 +380,21 @@ GDALDatasetH
 rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared) {
        assert(NULL != fn);
 
-       if (
-               gdal_enabled_drivers != NULL &&
-               strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL
-       ) {
-               rterror("rt_util_gdal_open: Cannot open file. All GDAL drivers disabled");
-               return NULL;
+       if (gdal_enabled_drivers != NULL) {
+               if (strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
+                       rterror("rt_util_gdal_open: Cannot open file. All GDAL drivers disabled");
+                       return NULL;
+               }
+               else if (strstr(gdal_enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
+                       /* do nothing */
+               }
+               else if (
+                       (strstr(fn, "/vsicurl") != NULL) &&
+                       (strstr(gdal_enabled_drivers, GDAL_VSICURL) == NULL)
+               ) {
+                       rterror("rt_util_gdal_open: Cannot open VSICURL file. VSICURL disabled");
+                       return NULL;
+               }
        }
 
        if (shared)
index 387202dd3e77403ae7e5abc3f5c7490610843d47..98fbcf806e5498dd63264ab8819c7ef7240bfad5 100644 (file)
@@ -154,6 +154,7 @@ void _PG_init(void);
 
 static char *gdal_datapath = NULL;
 extern char *gdal_enabled_drivers;
+extern char enable_outdb_rasters;
 
 /* postgis.gdal_datapath */
 static void
@@ -291,6 +292,12 @@ rtpg_assignHookGDALEnabledDrivers(const char *enabled_drivers, void *extra) {
        POSTGIS_RT_DEBUGF(4, "GDAL_SKIP = %s", CPLGetConfigOption("GDAL_SKIP", NULL));
 }
 
+/* postgis.eanble_outdb_rasters */
+static void
+rtpg_assignHookEnableOutDBRasters(bool enable, void *extra) {
+       /* do nothing for now */
+}
+
 /* Module load callback */
 void
 _PG_init(void) {
@@ -317,16 +324,6 @@ _PG_init(void) {
                NULL  /* GucShowHook show_hook */
        );
 
-       /*
-        * GucContext is set to PGC_BACKEND. As per PostgreSQL's guc.h...
-        *
-        * BACKEND options can only be set at postmaster startup, from the
-        * configuration file, or by client request in the connection startup
-        * packet (e.g., from libpq's PGOPTIONS variable). Furthermore, an
-        * already-started backend will ignore changes to such an option in the
-        * configuration file. The idea is that these options are fixed for a
-        * given backend once it's started, but they can vary across backends.
-        */
        DefineCustomStringVariable(
                "postgis.gdal_enabled_drivers", /* name */
                "Enabled GDAL drivers.", /* short_desc */
@@ -334,13 +331,28 @@ _PG_init(void) {
                &gdal_enabled_drivers, /* valueAddr */
                GDAL_DISABLE_ALL, /* bootValue */
                PGC_SUSET, /* GucContext context */
-               GUC_LIST_INPUT, /* int flags */
+               0, /* int flags */
 #if POSTGIS_PGSQL_VERSION >= 91
                NULL, /* GucStringCheckHook check_hook */
 #endif
                rtpg_assignHookGDALEnabledDrivers, /* GucStringAssignHook assign_hook */
                NULL  /* GucShowHook show_hook */
        );
+
+       DefineCustomBoolVariable(
+               "postgis.enable_outdb_rasters", /* name */
+               "Enable Out-DB raster bands", /* short_desc */
+               "If true, rasters can access data located outside the database", /* long_desc */
+               &enable_outdb_rasters, /* valueAddr */
+               false, /* bootValue */
+               PGC_SUSET, /* GucContext context */
+               0, /* int flags */
+#if POSTGIS_PGSQL_VERSION >= 91
+               NULL, /* GucStringCheckHook check_hook */
+#endif
+               rtpg_assignHookEnableOutDBRasters, /* GucBoolAssignHook assign_hook */
+               NULL  /* GucShowHook show_hook */
+       );
 }
 
 /* ---------------------------------------------------------------- */
index 55c1d89fe101d9f5d2a77221becb419a02f1319a..c69867966ea6823e99a42eeb03439556364d4c9c 100644 (file)
@@ -108,10 +108,43 @@ static void test_hsv_to_rgb() {
        CU_ASSERT_DOUBLE_EQUAL(rgb[2], 0.4, DBL_EPSILON);
 }
 
+static void test_util_gdal_open() {
+       extern char *gdal_enabled_drivers;
+
+       GDALDatasetH ds;
+
+       char *disable_all = GDAL_DISABLE_ALL;
+       char *enabled = "GTiff JPEG PNG";
+       char *enabled_vsi = "GTiff JPEG PNG VSICURL";
+
+       rt_util_gdal_register_all(1);
+
+       /* all drivers disabled */
+       gdal_enabled_drivers = disable_all;
+       ds = rt_util_gdal_open("/tmp/foo", GA_ReadOnly, 0);
+       CU_ASSERT(ds == NULL);
+
+       /* can't test VSICURL if HTTP driver not found */
+       if (!rt_util_gdal_driver_registered("HTTP"))
+               return;
+
+       /* enabled drivers, no VSICURL */
+       gdal_enabled_drivers = enabled;
+       ds = rt_util_gdal_open("/vsicurl/http://download.osgeo.org/gdal/data/gtiff/small_world.tif", GA_ReadOnly, 0);
+       CU_ASSERT(ds == NULL);
+
+       /* enabled drivers with VSICURL */
+       gdal_enabled_drivers = enabled_vsi;
+       ds = rt_util_gdal_open("/vsicurl/http://download.osgeo.org/gdal/data/gtiff/small_world.tif", GA_ReadOnly, 0);
+       CU_ASSERT(ds != NULL);
+       GDALClose(ds);
+}
+
 /* register tests */
 CU_TestInfo misc_tests[] = {
        PG_TEST(test_rgb_to_hsv),
        PG_TEST(test_hsv_to_rgb),
+       PG_TEST(test_util_gdal_open),
        CU_TEST_INFO_NULL
 };
 CU_SuiteInfo misc_suite = {"misc",  NULL,  NULL, misc_tests};
index c586d879337e76bef4029eb12d30f27b811c267e..455e0f3a9593e617269236eed3845a2c860b7bb8 100644 (file)
@@ -2,6 +2,7 @@ WITH foo AS (
        SELECT postgis_raster_lib_version()
 )
 SELECT NULL FROM foo;
+SET postgis.enable_outdb_rasters = true;
 SET postgis.gdal_enabled_drivers = 'GTiff';
 DELETE FROM loadedrast WHERE filename != 'testraster.tif';
 SELECT srid, scale_x::numeric(16, 10), scale_y::numeric(16, 10), blocksize_x, blocksize_y, same_alignment, regular_blocking, num_bands, pixel_types, nodata_values::numeric(16,10)[], out_db, ST_AsEWKT(extent) FROM raster_columns WHERE r_table_name = 'loadedrast' AND r_raster_column = 'rast';
index 1da358d379b8bca195d7c09fd354b3f5ea84d933..04717e8da9eb80fb4fa16ee0776a20c33d6d248c 100644 (file)
@@ -2,6 +2,7 @@ WITH foo AS (
        SELECT postgis_raster_lib_version()
 )
 SELECT NULL FROM foo;
+SET postgis.enable_outdb_rasters = True;
 SET postgis.gdal_enabled_drivers = 'GTiff PNG JPEG';
 
 DO $$
index ae4bd5ebeb53b8a4e8bbc6636085778ca2dc96df..92aa45dd38e8b5f946cbcdfce39267deab28fa52 100644 (file)
@@ -183,6 +183,7 @@ DROP TABLE rt_bytea_test;
 --- Test out-db as in-db
 -----------------------------------------------------------------------
 SET postgis.gdal_enabled_drivers = 'GTiff';
+SET postgis.enable_outdb_rasters = TRUE;
 WITH foo AS (
        SELECT
                rid,