mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-23 16:42:35 +00:00
add VSICURL keyword for GUC postgis.gdal_enabled_drivers. add GUC posgis.enable_outdb_rasters
git-svn-id: http://svn.osgeo.org/postgis/trunk@12492 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
parent
344943cd2b
commit
7d58fb71bd
2
NEWS
2
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
|
||||
|
|
|
@ -103,7 +103,19 @@ SET postgis.gdal_datapath = 'C:/Program Files/PostgreSQL/9.3/gdal-data';</progra
|
|||
|
||||
<note>
|
||||
<para>
|
||||
There are two special codes available to enable or disable all GDAL drivers: ENABLE_ALL and DISABLE_ALL. The codes are case-sensitive.
|
||||
There are three special codes available for <varname>postgis.gdal_enabled_drivers</varname>. The codes are case-sensitive.
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<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>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><varname>ENABLE_ALL</varname> enables all GDAL drivers.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><varname>VSICURL</varname> enables GDAL's <varname>/vsicurl/</varname> virtual file system.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
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.
|
||||
|
@ -153,9 +165,65 @@ SET postgis.gdal_enabled_drivers = 'DISABLE_ALL';
|
|||
<xref linkend="RT_ST_AsGDALRaster" />,
|
||||
<xref linkend="RT_ST_AsTIFF" />,
|
||||
<xref linkend="RT_ST_AsPNG" />,
|
||||
<xref linkend="RT_ST_AsJPEG" />
|
||||
<xref linkend="RT_ST_AsJPEG" />,
|
||||
<xref linkend="postgis_enable_outdb_rasters" />
|
||||
</para>
|
||||
</refsection>
|
||||
</refentry>
|
||||
|
||||
<refentry id="postgis_enable_outdb_rasters">
|
||||
<refnamediv>
|
||||
<refname>postgis.enable_outdb_rasters</refname>
|
||||
<refpurpose>
|
||||
A boolean configuration option to enable access to out-db raster bands.
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsection>
|
||||
<title>Description</title>
|
||||
<para>
|
||||
A boolean configuration option to enable access to out-db raster bands.
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
This option can be set in PostgreSQL's configuration file: postgresql.conf. It can also be set by connection or transaction.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
Even if <varname>postgis.enable_outdb_rasters</varname> is True, the GUC <varname>postgis.enable_outdb_rasters</varname> determines the accessible raster formats.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
In the standard PostGIS installation, <varname>postgis.enable_outdb_rasters</varname> is set to False.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<para>Availability: 2.2.0</para>
|
||||
|
||||
</refsection>
|
||||
|
||||
<refsection>
|
||||
<title>Examples</title>
|
||||
<para>Set and reset <varname>postgis.enable_outdb_rasters</varname></para>
|
||||
|
||||
<programlisting>
|
||||
SET postgis.enable_outdb_rasters TO True;
|
||||
SET postgis.enable_outdb_rasters = default;
|
||||
SET postgis.enable_outdb_rasters = True;
|
||||
SET postgis.enable_outdb_rasters = False;
|
||||
</programlisting>
|
||||
</refsection>
|
||||
|
||||
<refsection>
|
||||
<title>See Also</title>
|
||||
<para>
|
||||
<xref linkend="postgis_gdal_enabled_drivers" />
|
||||
</para>
|
||||
</refsection>
|
||||
</refentry>
|
||||
</sect1>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 */
|
||||
);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 $$
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue