2278 char **elements = NULL;
2280 GDALDriverH drv = NULL;
2286 setlocale (LC_ALL,
"");
2287 bindtextdomain (PACKAGE, LOCALEDIR);
2288 textdomain (PACKAGE);
2299 if (config == NULL) {
2300 rterror(
_(
"Could not allocate memory for loader configuration"));
2309 for (i = 1; i < argc; i++) {
2312 if (
CSEQUAL(argv[i],
"-s") && i < argc - 1) {
2314 ptr = strchr(optarg,
':');
2317 sscanf(optarg,
"%d", &config->
srid);
2318 sscanf(ptr,
"%d", &config->
out_srid);
2320 config->
srid = atoi(optarg);
2324 else if (
CSEQUAL(argv[i],
"-b") && i < argc - 1) {
2325 elements =
strsplit(argv[++i],
",", &n);
2327 rterror(
_(
"Could not process -b"));
2333 for (j = 0; j < n; j++) {
2334 char *t =
trim(elements[j]);
2335 char **minmax = NULL;
2345 if (!
array_range(atoi(minmax[0]), atoi(minmax[1]), 1, &range, &p)) {
2346 rterror(
_(
"Could not allocate memory for storing band indices"));
2347 for (l = 0; l < o; l++)
2350 for (j = 0; j < n; j++)
2361 if (range == NULL) {
2362 rterror(
_(
"Could not allocate memory for storing band indices"));
2363 for (l = 0; l < o; l++)
2366 for (j = 0; j < n; j++)
2379 if (config->
nband == NULL) {
2380 rterror(
_(
"Could not allocate memory for storing band indices"));
2382 for (l = 0; l < o; l++)
2385 for (j = 0; j < n; j++)
2393 for (l = 0; l < p; l++, m++)
2394 config->
nband[m] = range[l];
2398 for (l = 0; l < o; l++)
2410 if (config->
nband[j] < 1) {
2411 rterror(
_(
"Band index %d must be greater than 0"), config->
nband[j]);
2418 else if (
CSEQUAL(argv[i],
"-t") && i < argc - 1) {
2419 if (
CSEQUAL(argv[++i],
"auto")) {
2424 elements =
strsplit(argv[i],
"x", &n);
2426 rterror(
_(
"Could not process -t"));
2431 for (j = 0; j < n; j++) {
2432 char *t =
trim(elements[j]);
2441 for (j = 0; j < 2; j++) {
2443 rterror(
_(
"Tile size must be greater than 0x0"));
2451 else if (
CSEQUAL(argv[i],
"-P")) {
2455 else if (
CSEQUAL(argv[i],
"-R")) {
2459 else if (
CSEQUAL(argv[i],
"-d")) {
2463 else if (
CSEQUAL(argv[i],
"-a")) {
2467 else if (
CSEQUAL(argv[i],
"-c")) {
2471 else if (
CSEQUAL(argv[i],
"-p")) {
2475 else if (
CSEQUAL(argv[i],
"-f") && i < argc - 1) {
2478 rterror(
_(
"Could not allocate memory for storing raster column name"));
2482 strncpy(config->
raster_column, argv[i], strlen(argv[i]) + 1);
2485 else if (
CSEQUAL(argv[i],
"-F")) {
2489 else if (
CSEQUAL(argv[i],
"-n") && i < argc - 1) {
2492 rterror(
_(
"Could not allocate memory for storing filename column name"));
2500 else if (
CSEQUAL(argv[i],
"-l") && i < argc - 1) {
2501 elements =
strsplit(argv[++i],
",", &n);
2503 rterror(
_(
"Could not process -l"));
2511 rterror(
_(
"Could not allocate memory for storing overview factors"));
2515 for (j = 0; j < n; j++) {
2516 char *t =
trim(elements[j]);
2534 else if (
CSEQUAL(argv[i],
"-q")) {
2538 else if (
CSEQUAL(argv[i],
"-I")) {
2542 else if (
CSEQUAL(argv[i],
"-M")) {
2546 else if (
CSEQUAL(argv[i],
"-C")) {
2550 else if (
CSEQUAL(argv[i],
"-x")) {
2554 else if (
CSEQUAL(argv[i],
"-r")) {
2558 else if (
CSEQUAL(argv[i],
"-T") && i < argc - 1) {
2561 rterror(
_(
"Could not allocate memory for storing tablespace of new table"));
2565 strncpy(config->
tablespace, argv[i], strlen(argv[i]) + 1);
2568 else if (
CSEQUAL(argv[i],
"-X") && i < argc - 1) {
2571 rterror(
_(
"Could not allocate memory for storing tablespace of new indices"));
2578 else if (
CSEQUAL(argv[i],
"-N") && i < argc - 1) {
2583 else if (
CSEQUAL(argv[i],
"-k")) {
2587 else if (
CSEQUAL(argv[i],
"-E") && i < argc - 1) {
2588 config->
endian = atoi(argv[++i]);
2592 else if (
CSEQUAL(argv[i],
"-V") && i < argc - 1) {
2593 config->
version = atoi(argv[++i]);
2597 else if (
CSEQUAL(argv[i],
"-e")) {
2601 else if (
CSEQUAL(argv[i],
"-Y")) {
2605 else if (
CSEQUAL(argv[i],
"-G")) {
2608 if (drv_set == NULL || !drv_count) {
2609 rterror(
_(
"Could not get list of available GDAL raster formats"));
2612 printf(
_(
"Supported GDAL raster formats:\n"));
2613 for (j = 0; j < drv_count; j++) {
2614 printf(
_(
" %s\n"), drv_set[j].long_name);
2627 else if (
CSEQUAL(argv[i],
"-?")) {
2635 if (config->
rt_file == NULL) {
2636 rterror(
_(
"Could not allocate memory for storing raster files"));
2643 rterror(
_(
"Could not allocate memory for storing raster filename"));
2653 rterror(
_(
"Invalid argument combination - cannot use -Y with -s FROM_SRID:TO_SRID"));
2681 if (config->
schema == NULL) {
2682 rterror(
_(
"Could not allocate memory for storing schema name"));
2690 if (config->
table == NULL) {
2691 rterror(
_(
"Could not allocate memory for storing table name"));
2701 if (config->
table == NULL) {
2702 rterror(
_(
"Could not allocate memory for storing table name"));
2711 if (config->
rt_file == NULL) {
2712 rterror(
_(
"Could not reallocate the memory holding raster names"));
2725 drv = GDALIdentifyDriver(config->
rt_file[i], NULL);
2737 rterror(
_(
"Could not allocate memory for cleaned raster filenames"));
2747 rterror(
_(
"Could not allocate memory for cleaned raster filename"));
2751 strcpy(file, config->
rt_file[i]);
2753 for (ptr = file + strlen(file); ptr > file; ptr--) {
2754 if (*ptr ==
'/' || *ptr ==
'\\') {
2762 rterror(
_(
"Could not allocate memory for cleaned raster filename"));
2775 if (config->
table == NULL) {
2781 rterror(
_(
"Could not allocate memory for proxy table name"));
2787 for (ptr = file + strlen(file); ptr > file; ptr--) {
2794 config->
table =
rtalloc(
sizeof(
char) * (strlen(file) + 1));
2795 if (config->
table == NULL) {
2796 rterror(
_(
"Could not allocate memory for proxy table name"));
2800 strcpy(config->
table, file);
2808 rterror(
_(
"Could not allocate memory for default raster column name"));
2819 rterror(
_(
"Could not allocate memory for default filename column name"));
2832 if (config->
schema != NULL)
2834 if (config->
table != NULL)
2854 rterror(
_(
"Could not allocate memory for overview table names"));
2860 sprintf(factor,
"%d", config->
overview[i]);
2864 rterror(
_(
"Could not allocate memory for overview table name"));
2877 rtwarn(
_(
"The schema name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2883 rtwarn(
_(
"The table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2889 rtwarn(
_(
"The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2895 rtwarn(
_(
"The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2901 rtwarn(
_(
"The tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2907 rtwarn(
_(
"The index tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2915 rtwarn(
_(
"The overview table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2927 if (config->
schema != NULL) {
2930 rterror(
_(
"Could not allocate memory for quoting schema name"));
2935 sprintf(tmp,
"\"%s\".", config->
schema);
2939 if (config->
table != NULL) {
2940 tmp =
rtalloc(
sizeof(
char) * (strlen(config->
table) + 3));
2942 rterror(
_(
"Could not allocate memory for quoting table name"));
2947 sprintf(tmp,
"\"%s\"", config->
table);
2949 config->
table = tmp;
2954 rterror(
_(
"Could not allocate memory for quoting raster column name"));
2966 rterror(
_(
"Could not allocate memory for quoting raster column name"));
2978 rterror(
_(
"Could not allocate memory for quoting tablespace name"));
2990 rterror(
_(
"Could not allocate memory for quoting index tablespace name"));
3003 rterror(
_(
"Could not allocate memory for quoting overview table name"));
3020 if (buffer == NULL) {
3021 rterror(
_(
"Could not allocate memory for output string buffer"));
3029 rterror(
_(
"Unable to process rasters"));
static void flush_stringbuffer(STRINGBUFFER *buffer)
static void rtdealloc_stringbuffer(STRINGBUFFER *buffer, int freebuffer)
static int array_range(int min, int max, int step, int **range, int *len)
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
void * rtrealloc(void *mem, size_t size)
Datum buffer(PG_FUNCTION_ARGS)
static char * strtolower(char *str)
static int process_rasters(RTLOADERCFG *config, STRINGBUFFER *buffer)
static void rt_init_allocators(void)
void rtwarn(const char *fmt,...)
#define SRID_UNKNOWN
Unknown SRID value.
static void rtdealloc_config(RTLOADERCFG *config)
static void init_stringbuffer(STRINGBUFFER *buffer)
static char ** strsplit(const char *str, const char *delimiter, int *n)
void rtdealloc(void *mem)
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
static char * trim(const char *input)
static void init_config(RTLOADERCFG *config)