extern void *rtrealloc(void *mem, size_t size);
extern void rtdealloc(void *mem);
+/*
+ * GDAL driver flags
+ */
+#define GDAL_ENABLE_ALL "ENABLE_ALL"
+#define GDAL_DISABLE_ALL "DISABLE_ALL"
-/* Set of functions to clamp double to int of different size
+/*
+ * Set of functions to clamp double to int of different size
*/
#if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION)
*
* @return ES_NONE on success, ES_ERROR on error
*/
-rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
+rt_errorstate
+rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
/*
is GDAL configured correctly?
int
rt_util_gdal_driver_registered(const char *drv);
+/*
+ wrapper for GDALOpen and GDALOpenShared
+*/
+GDALDatasetH
+rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared);
+
void
rt_util_from_ogr_envelope(
OGREnvelope env,
rt_util_gdal_register_all(0);
/*
- hdsSrc = GDALOpenShared(band->data.offline.path, GA_ReadOnly);
+ hdsSrc = rt_util_gdal_open(band->data.offline.path, GA_ReadOnly, 1);
*/
- hdsSrc = GDALOpen(band->data.offline.path, GA_ReadOnly);
+ hdsSrc = rt_util_gdal_open(band->data.offline.path, GA_ReadOnly, 0);
if (hdsSrc == NULL) {
rterror("rt_band_load_offline_data: Cannot open offline raster: %s", band->data.offline.path);
return ES_ERROR;
_rast = rt_raster_from_gdal_dataset(hdsDst);
GDALClose(hdsDst);
- /* XXX: need to find a way to clean up the GDALOpenShared datasets at end of transaction */
- /* GDALClose(hdsSrc); */
GDALClose(hdsSrc);
/*
{
return 1;
}
+char *gdal_enabled_drivers = NULL;
+
/*
register all GDAL drivers
*/
return 0;
}
+/*
+ wrapper for GDALOpen and GDALOpenShared
+*/
+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 (shared)
+ return GDALOpenShared(fn, fn_access);
+ else
+ return GDALOpen(fn, fn_access);
+}
+
void
rt_util_from_ogr_envelope(
OGREnvelope env,
/* open outdb raster file */
rt_util_gdal_register_all(0);
- hdsOut = GDALOpenShared(outdbfile, GA_ReadOnly);
+ hdsOut = rt_util_gdal_open(outdbfile, GA_ReadOnly, 0);
if (hdsOut == NULL) {
if (pgraster != NULL) {
rt_raster_destroy(raster);
rt_util_gdal_register_all(0);
/* open GDAL raster */
- hdsSrc = GDALOpenShared("/vsimem/in.dat", GA_ReadOnly);
+ hdsSrc = rt_util_gdal_open("/vsimem/in.dat", GA_ReadOnly, 1);
if (hdsSrc == NULL) {
VSIFCloseL(vsifp);
PG_FREE_IF_COPY(bytea_data, 0);
/* PostGIS raster GUCs */
/* ---------------------------------------------------------------- */
-static char *gdaldatapath = NULL;
-static char *gdalenableddrivers = NULL;
+static char *gdal_datapath = NULL;
+extern char *gdal_enabled_drivers;
/* postgis.gdal_datapath */
static void
}
/* postgis.gdal_enabled_drivers */
-#define ENABLE_ALL "ENABLE_ALL"
-#define DISABLE_ALL "DISABLE_ALL"
static void
rtpg_assignHookGDALEnabledDrivers(const char *enabled_drivers, void *extra) {
int enable_all = 0;
/* scan for keywords DISABLE_ALL and ENABLE_ALL */
disable_all = 0;
enable_all = 0;
- if (strstr(enabled_drivers, DISABLE_ALL) != NULL) {
+ if (strstr(enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
for (i = 0; i < enabled_drivers_count; i++) {
- if (strstr(enabled_drivers_array[i], DISABLE_ALL) != NULL) {
+ if (strstr(enabled_drivers_array[i], GDAL_DISABLE_ALL) != NULL) {
disable_all = 1;
break;
}
}
}
- else if (strstr(enabled_drivers, ENABLE_ALL) != NULL) {
+ else if (strstr(enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
for (i = 0; i < enabled_drivers_count; i++) {
- if (strstr(enabled_drivers_array[i], ENABLE_ALL) != NULL) {
+ if (strstr(enabled_drivers_array[i], GDAL_ENABLE_ALL) != NULL) {
enable_all = 1;
break;
}
"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 */
+ &gdal_datapath, /* valueAddr */
NULL, /* bootValue */
PGC_SUSET, /* GucContext context */
0, /* int flags */
"postgis.gdal_enabled_drivers", /* name */
"Enabled GDAL drivers.", /* short_desc */
"List of enabled GDAL drivers by short name. To enable/disable all drivers, use 'ENABLE_ALL' or 'DISABLE_ALL' (sets the GDAL_SKIP config option).", /* long_desc */
- &gdalenableddrivers, /* valueAddr */
- DISABLE_ALL, /* bootValue */
+ &gdal_enabled_drivers, /* valueAddr */
+ GDAL_DISABLE_ALL, /* bootValue */
PGC_SUSET, /* GucContext context */
GUC_LIST_INPUT, /* int flags */
#if POSTGIS_PGSQL_VERSION >= 91