PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ rt_util_gdal_open()

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

Definition at line 386 of file rt_util.c.

390  {
391  char *vsi_options_str = rtoptions("gdal_vsi_options");
392 
393  /* Parse vsi options string */
394  if (vsi_options_str && strlen(vsi_options_str) > 0) {
395  size_t sz;
396  char *olist[OPTION_LIST_SIZE];
397  rtinfo("postgis.gdal_vsi_options is set");
398  memset(olist, 0, sizeof(olist));
399  option_list_parse(vsi_options_str, olist);
400  sz = option_list_length(olist);
401  if (sz % 2 == 0) {
402  size_t i;
403  for (i = 0; i < sz; i += 2)
404  {
405  char *key = olist[i];
406  char *val = olist[i+1];
407  /* GDAL_SKIP is where the disallowed drivers are set */
408  /* We cannot allow user-level over-ride of that config option */
409  if (strcmp(key, "gdal_skip") == 0) {
410  rtwarn("Unable to set GDAL_SKIP config option");
411  continue;
412  }
413  rtinfo("CPLSetConfigOption(%s)", key);
414  CPLSetConfigOption(key, val);
415  }
416  }
417  }
418 
419  unsigned int open_flags;
420  assert(NULL != fn);
421 
422  if (gdal_enabled_drivers != NULL) {
423  if (strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
424  rterror("rt_util_gdal_open: Cannot open file. All GDAL drivers disabled");
425  return NULL;
426  }
427  else if (strstr(gdal_enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
428  /* do nothing */
429  }
430  else if (
431  (strstr(fn, "/vsi") != NULL) &&
432  (strstr(fn, "/vsimem") == NULL) &&
433  (strstr(gdal_enabled_drivers, GDAL_VSICURL) == NULL)
434  ) {
435  rterror("rt_util_gdal_open: Cannot open %s file. %s disabled", GDAL_VSICURL, GDAL_VSICURL);
436  return NULL;
437  }
438  }
439 
440  open_flags = GDAL_OF_RASTER
441  | GDAL_OF_VERBOSE_ERROR
442  | (fn_access == GA_Update ? GDAL_OF_UPDATE : 0)
443  | (shared ? GDAL_OF_SHARED : 0);
444 
445  return GDALOpenEx(fn /* filename */,
446  open_flags,
447  NULL, /* allowed drivers */
448  NULL, /* open options */
449  NULL /* sibling files */
450  );
451 }
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:378

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: