PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ rt_util_gdal_open()

GDALDatasetH rt_util_gdal_open ( const char *  fn,
GDALAccess  fn_access,
int  shared 
)

Definition at line 389 of file rt_util.c.

393  {
394  char *vsi_options_str = rtoptions("gdal_vsi_options");
395 
396  /* Parse vsi options string */
397  if (vsi_options_str && strlen(vsi_options_str) > 0) {
398  size_t sz;
399  char *olist[OPTION_LIST_SIZE];
400  rtinfo("postgis.gdal_vsi_options is set");
401  memset(olist, 0, sizeof(olist));
402  option_list_parse(vsi_options_str, olist);
403  sz = option_list_length(olist);
404  if (sz % 2 == 0) {
405  size_t i;
406  for (i = 0; i < sz; i += 2)
407  {
408  char *key = olist[i];
409  char *val = olist[i+1];
410  /* GDAL_SKIP is where the disallowed drivers are set */
411  /* We cannot allow user-level over-ride of that config option */
412  if (strcmp(key, "gdal_skip") == 0) {
413  rtwarn("Unable to set GDAL_SKIP config option");
414  continue;
415  }
416  rtinfo("CPLSetConfigOption(%s)", key);
417  CPLSetConfigOption(key, val);
418  }
419  }
420  }
421 
422  unsigned int open_flags;
423  assert(NULL != fn);
424 
425  if (gdal_enabled_drivers != NULL) {
426  if (strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
427  rterror("rt_util_gdal_open: Cannot open file. All GDAL drivers disabled");
428  return NULL;
429  }
430  else if (strstr(gdal_enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
431  /* do nothing */
432  }
433  else if (
434  (strstr(fn, "/vsi") != NULL) &&
435  (strstr(fn, "/vsimem") == NULL) &&
436  (strstr(gdal_enabled_drivers, GDAL_VSICURL) == NULL)
437  ) {
438  rterror("rt_util_gdal_open: Cannot open %s file. %s disabled", GDAL_VSICURL, GDAL_VSICURL);
439  return NULL;
440  }
441  }
442 
443  open_flags = GDAL_OF_RASTER
444  | GDAL_OF_VERBOSE_ERROR
445  | (fn_access == GA_Update ? GDAL_OF_UPDATE : 0)
446  | (shared ? GDAL_OF_SHARED : 0);
447 
448  return GDALOpenEx(fn /* filename */,
449  open_flags,
450  NULL, /* allowed drivers */
451  NULL, /* open options */
452  NULL /* sibling files */
453  );
454 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:219
void rtinfo(const char *fmt,...)
Definition: rt_context.c:231
char * rtoptions(const char *varname)
Wrappers used for options.
Definition: rt_context.c:256
void rtwarn(const char *fmt,...)
Definition: rt_context.c:244
#define GDAL_ENABLE_ALL
Definition: librtcore.h:2192
#define GDAL_DISABLE_ALL
Definition: librtcore.h:2193
#define GDAL_VSICURL
Definition: librtcore.h:2194
size_t option_list_length(char **olist)
Returns the total number of keys and values in the list.
Definition: optionlist.c:73
void option_list_parse(char *input, char **olist)
option_list is a null-terminated list of strings, where every odd string is a key and every even stri...
Definition: optionlist.c:86
#define OPTION_LIST_SIZE
Definition: optionlist.h:31
char * gdal_enabled_drivers
Definition: rt_util.c:381

References GDAL_DISABLE_ALL, GDAL_ENABLE_ALL, gdal_enabled_drivers, GDAL_VSICURL, option_list_length(), option_list_parse(), OPTION_LIST_SIZE, rterror(), rtinfo(), rtoptions(), and rtwarn().

Referenced by RASTER_addBandOutDB(), RASTER_fromGDALRaster(), rt_band_load_offline_data(), rt_band_new_offline_from_path(), and test_util_gdal_open().

Here is the call graph for this function:
Here is the caller graph for this function: