PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ rt_util_gdal_open()

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

Definition at line 491 of file rt_util.c.

495 {
496 char *vsi_options_str = rtoptions("gdal_vsi_options");
497
498 /* Parse vsi options string */
499 if (vsi_options_str && strlen(vsi_options_str) > 0) {
500 size_t sz;
501 char *olist[OPTION_LIST_SIZE];
502 rtinfo("postgis.gdal_vsi_options is set");
503 memset(olist, 0, sizeof(olist));
504 option_list_parse(vsi_options_str, olist);
505 sz = option_list_length(olist);
506 if (sz % 2 == 0) {
507 size_t i;
508 for (i = 0; i < sz; i += 2)
509 {
510 char *key = olist[i];
511 char *val = olist[i+1];
512 /* GDAL_SKIP is where the disallowed drivers are set */
513 /* We cannot allow user-level over-ride of that config option */
514 if (strcmp(key, "gdal_skip") == 0) {
515 rtwarn("Unable to set GDAL_SKIP config option");
516 continue;
517 }
518 rtinfo("CPLSetConfigOption(%s)", key);
519 CPLSetConfigOption(key, val);
520 }
521 }
522 }
523
524 unsigned int open_flags;
525 assert(NULL != fn);
526
527 if (gdal_enabled_drivers != NULL) {
528 if (strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL) {
529 rterror("rt_util_gdal_open: Cannot open file. All GDAL drivers disabled");
530 return NULL;
531 }
532 else if (strstr(gdal_enabled_drivers, GDAL_ENABLE_ALL) != NULL) {
533 /* do nothing */
534 }
535 else if (
536 (strstr(fn, "/vsi") != NULL) &&
537 (strstr(fn, "/vsimem") == NULL) &&
538 (strstr(gdal_enabled_drivers, GDAL_VSICURL) == NULL)
539 ) {
540 rterror("rt_util_gdal_open: Cannot open %s file. %s disabled", GDAL_VSICURL, GDAL_VSICURL);
541 return NULL;
542 }
543 }
544
545 open_flags = GDAL_OF_RASTER
546 | GDAL_OF_VERBOSE_ERROR
547 | (fn_access == GA_Update ? GDAL_OF_UPDATE : 0)
548 | (shared ? GDAL_OF_SHARED : 0);
549
550 return GDALOpenEx(fn /* filename */,
551 open_flags,
552 NULL, /* allowed drivers */
553 NULL, /* open options */
554 NULL /* sibling files */
555 );
556}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void void rtinfo(const char *fmt,...) __attribute__((format(printf
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
void void void char * rtoptions(const char *varname)
Wrappers used for options.
Definition rt_context.c:256
#define GDAL_ENABLE_ALL
Definition librtcore.h:2239
#define GDAL_DISABLE_ALL
Definition librtcore.h:2240
#define GDAL_VSICURL
Definition librtcore.h:2241
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:483

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: