PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ rt_util_gdal_open()

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

Definition at line 394 of file rt_util.c.

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

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: