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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 2274 of file raster2pgsql.c.

2274 {
2275 RTLOADERCFG *config = NULL;
2276 STRINGBUFFER *buffer = NULL;
2277 uint32_t i = 0;
2278 uint32_t j = 0;
2279 char **elements = NULL;
2280 uint32_t n = 0;
2281 GDALDriverH drv = NULL;
2282 char *tmp = NULL;
2283 int argit = 0;
2284
2286
2287#ifdef USE_NLS
2288 setlocale (LC_ALL, "");
2289 bindtextdomain (PACKAGE, LOCALEDIR);
2290 textdomain (PACKAGE);
2291#endif
2292
2293 /* no args, show usage */
2294 if (argc == 1) {
2295 usage();
2296 exit(0);
2297 }
2298
2299 /* initialize config */
2300 config = rtalloc(sizeof(RTLOADERCFG));
2301 if (config == NULL) {
2302 rterror(_("Could not allocate memory for loader configuration"));
2303 exit(1);
2304 }
2305 init_config(config);
2306
2307 /****************************************************************************
2308 * parse arguments
2309 ****************************************************************************/
2310
2311 for (argit = 1; argit < argc; argit++) {
2312 char *optarg, *ptr;
2313 /* srid */
2314
2315 if (CSEQUAL(argv[argit], "-s") && argit < argc - 1) {
2316 optarg = argv[++argit];
2317 ptr = strchr(optarg, ':');
2318 if (ptr) {
2319 *ptr++ = '\0';
2320 sscanf(optarg, "%d", &config->srid);
2321 sscanf(ptr, "%d", &config->out_srid);
2322 } else {
2323 config->srid = atoi(optarg);
2324 }
2325 }
2326 /* band index */
2327 else if (CSEQUAL(argv[argit], "-b") && argit < argc - 1) {
2328 elements = strsplit(argv[++argit], ",", &n);
2329 if (n < 1) {
2330 rterror(_("Could not process -b"));
2331 rtdealloc_config(config);
2332 exit(1);
2333 }
2334
2335 config->nband_count = 0;
2336 for (j = 0; j < n; j++) {
2337 char *t = trim(elements[j]);
2338 char **minmax = NULL;
2339 int *range = NULL;
2340 uint32_t p = 0;
2341 uint32_t l = 0;
2342 int m = 0;
2343 uint32_t o = 0;
2344
2345 /* is t a range? */
2346 minmax = strsplit(t, "-", &o);
2347 if (o == 2) {
2348 if (!array_range(atoi(minmax[0]), atoi(minmax[1]), 1, &range, &p)) {
2349 rterror(_("Could not allocate memory for storing band indices"));
2350 for (l = 0; l < o; l++)
2351 rtdealloc(minmax[l]);
2352 rtdealloc(minmax);
2353 for (j = 0; j < n; j++)
2354 rtdealloc(elements[j]);
2355 rtdealloc(elements);
2356 rtdealloc(t);
2357 rtdealloc_config(config);
2358 exit(1);
2359 }
2360 }
2361 else {
2362 p = 1;
2363 range = rtalloc(sizeof(int));
2364 if (range == NULL) {
2365 rterror(_("Could not allocate memory for storing band indices"));
2366 for (l = 0; l < o; l++)
2367 rtdealloc(minmax[l]);
2368 rtdealloc(minmax);
2369 for (j = 0; j < n; j++)
2370 rtdealloc(elements[j]);
2371 rtdealloc(elements);
2372 rtdealloc(t);
2373 rtdealloc_config(config);
2374 exit(1);
2375 }
2376 *range = atoi(t);
2377 }
2378
2379 m = config->nband_count;
2380 config->nband_count += p;
2381 config->nband = rtrealloc(config->nband, sizeof(int) * config->nband_count);
2382 if (config->nband == NULL) {
2383 rterror(_("Could not allocate memory for storing band indices"));
2384 rtdealloc(range);
2385 for (l = 0; l < o; l++)
2386 rtdealloc(minmax[l]);
2387 rtdealloc(minmax);
2388 for (j = 0; j < n; j++)
2389 rtdealloc(elements[j]);
2390 rtdealloc(elements);
2391 rtdealloc(t);
2392 rtdealloc_config(config);
2393 exit(1);
2394 }
2395
2396 for (l = 0; l < p; l++, m++)
2397 config->nband[m] = range[l];
2398
2399 rtdealloc(range);
2400
2401 for (l = 0; l < o; l++)
2402 rtdealloc(minmax[l]);
2403 rtdealloc(minmax);
2404
2405 rtdealloc(t);
2406 rtdealloc(elements[j]);
2407 }
2408 rtdealloc(elements);
2409 elements = NULL;
2410 n = 0;
2411
2412 for (j = 0; j < config->nband_count; j++) {
2413 if (config->nband[j] < 1) {
2414 rterror(_("Band index %d must be greater than 0"), config->nband[j]);
2415 rtdealloc_config(config);
2416 exit(1);
2417 }
2418 }
2419 }
2420 /* tile size */
2421 else if (CSEQUAL(argv[argit], "-t") && argit < argc - 1) {
2422 if (CSEQUAL(argv[++argit], "auto")) {
2423 config->tile_size[0] = -1;
2424 config->tile_size[1] = -1;
2425 }
2426 else {
2427 elements = strsplit(argv[argit], "x", &n);
2428 if (n != 2) {
2429 rterror(_("Could not process -t"));
2430 rtdealloc_config(config);
2431 exit(1);
2432 }
2433
2434 for (j = 0; j < n; j++) {
2435 char *t = trim(elements[j]);
2436 config->tile_size[j] = atoi(t);
2437 rtdealloc(t);
2438 rtdealloc(elements[j]);
2439 }
2440 rtdealloc(elements);
2441 elements = NULL;
2442 n = 0;
2443
2444 for (j = 0; j < 2; j++) {
2445 if (config->tile_size[j] < 1) {
2446 rterror(_("Tile size must be greater than 0x0"));
2447 rtdealloc_config(config);
2448 exit(1);
2449 }
2450 }
2451 }
2452 }
2453 /* pad tiles */
2454 else if (CSEQUAL(argv[argit], "-P")) {
2455 config->pad_tile = 1;
2456 }
2457 /* out-of-db raster */
2458 else if (CSEQUAL(argv[argit], "-R")) {
2459 config->outdb = 1;
2460 }
2461 /* drop table and recreate */
2462 else if (CSEQUAL(argv[argit], "-d")) {
2463 config->opt = 'd';
2464 }
2465 /* append to table */
2466 else if (CSEQUAL(argv[argit], "-a")) {
2467 config->opt = 'a';
2468 }
2469 /* create new table */
2470 else if (CSEQUAL(argv[argit], "-c")) {
2471 config->opt = 'c';
2472 }
2473 /* prepare only */
2474 else if (CSEQUAL(argv[argit], "-p")) {
2475 config->opt = 'p';
2476 }
2477 /* raster column name */
2478 else if (CSEQUAL(argv[argit], "-f") && argit < argc - 1) {
2479 const size_t len = (strlen(argv[++argit]) + 1);
2480 config->raster_column = rtalloc(sizeof(char) * len);
2481 if (config->raster_column == NULL) {
2482 rterror(_("Could not allocate memory for storing raster column name"));
2483 rtdealloc_config(config);
2484 exit(1);
2485 }
2486 strncpy(config->raster_column, argv[argit], len);
2487 }
2488 /* filename column */
2489 else if (CSEQUAL(argv[argit], "-F")) {
2490 config->file_column = 1;
2491 }
2492 /* filename column name */
2493 else if (CSEQUAL(argv[argit], "-n") && argit < argc - 1) {
2494 const size_t len = (strlen(argv[++argit]) + 1);
2495 config->file_column_name = rtalloc(sizeof(char) * len);
2496 if (config->file_column_name == NULL) {
2497 rterror(_("Could not allocate memory for storing filename column name"));
2498 rtdealloc_config(config);
2499 exit(1);
2500 }
2501 strncpy(config->file_column_name, argv[argit], len);
2502 config->file_column = 1;
2503 }
2504 /* overview factors */
2505 else if (CSEQUAL(argv[argit], "-l") && argit < argc - 1) {
2506 elements = strsplit(argv[++argit], ",", &n);
2507 if (n < 1) {
2508 rterror(_("Could not process -l"));
2509 rtdealloc_config(config);
2510 exit(1);
2511 }
2512
2513 config->overview_count = n;
2514 config->overview = rtalloc(sizeof(int) * n);
2515 if (config->overview == NULL) {
2516 rterror(_("Could not allocate memory for storing overview factors"));
2517 rtdealloc_config(config);
2518 exit(1);
2519 }
2520 for (j = 0; j < n; j++) {
2521 char *t = trim(elements[j]);
2522 config->overview[j] = atoi(t);
2523 rtdealloc(t);
2524 rtdealloc(elements[j]);
2525 }
2526 rtdealloc(elements);
2527 elements = NULL;
2528 n = 0;
2529
2530 for (j = 0; j < (uint32_t)config->overview_count; j++) {
2531 if (config->overview[j] < MINOVFACTOR || config->overview[j] > MAXOVFACTOR) {
2532 rterror(_("Overview factor %d is not between %d and %d"), config->overview[j], MINOVFACTOR, MAXOVFACTOR);
2533 rtdealloc_config(config);
2534 exit(1);
2535 }
2536 }
2537 }
2538 /* quote identifiers */
2539 else if (CSEQUAL(argv[argit], "-q")) {
2540 config->quoteident = 1;
2541 }
2542 /* create index */
2543 else if (CSEQUAL(argv[argit], "-I")) {
2544 config->idx = 1;
2545 }
2546 /* maintenance */
2547 else if (CSEQUAL(argv[argit], "-M")) {
2548 config->maintenance = 1;
2549 }
2550 /* set constraints */
2551 else if (CSEQUAL(argv[argit], "-C")) {
2552 config->constraints = 1;
2553 }
2554 /* disable extent constraint */
2555 else if (CSEQUAL(argv[argit], "-x")) {
2556 config->max_extent = 0;
2557 }
2558 /* enable regular_blocking */
2559 else if (CSEQUAL(argv[argit], "-r")) {
2560 config->regular_blocking = 1;
2561 }
2562 /* tablespace of new table */
2563 else if (CSEQUAL(argv[argit], "-T") && argit < argc - 1) {
2564 const size_t len = (strlen(argv[++argit]) + 1);
2565 config->tablespace = rtalloc(len);
2566 if (config->tablespace == NULL) {
2567 rterror(_("Could not allocate memory for storing tablespace of new table"));
2568 rtdealloc_config(config);
2569 exit(1);
2570 }
2571 strncpy(config->tablespace, argv[argit], len);
2572 }
2573 /* tablespace of new index */
2574 else if (CSEQUAL(argv[argit], "-X") && argit < argc - 1) {
2575 const size_t len = (strlen(argv[++argit]) + 1);
2576 config->idx_tablespace = rtalloc(len);
2577 if (config->idx_tablespace == NULL) {
2578 rterror(_("Could not allocate memory for storing tablespace of new indices"));
2579 rtdealloc_config(config);
2580 exit(1);
2581 }
2582 strncpy(config->idx_tablespace, argv[argit], len);
2583 }
2584 /* nodata value */
2585 else if (CSEQUAL(argv[argit], "-N") && argit < argc - 1) {
2586 config->hasnodata = 1;
2587 config->nodataval = atof(argv[++argit]);
2588 }
2589 /* skip NODATA value check for bands */
2590 else if (CSEQUAL(argv[argit], "-k")) {
2591 config->skip_nodataval_check = 1;
2592 }
2593 /* endianness */
2594 else if (CSEQUAL(argv[argit], "-E") && argit < argc - 1) {
2595 config->endian = atoi(argv[++argit]);
2596 config->endian = 1;
2597 }
2598 /* version */
2599 else if (CSEQUAL(argv[argit], "-V") && argit < argc - 1) {
2600 config->version = atoi(argv[++argit]);
2601 config->version = 0;
2602 }
2603 /* transaction */
2604 else if (CSEQUAL(argv[argit], "-e")) {
2605 config->transaction = 0;
2606 }
2607 /* COPY statements */
2608 else if (CSEQUAL(argv[argit], "-Y")) {
2609 config->copy_statements = 1;
2610 /* max tiles per copy */
2611 if ( argit < argc - 1) {
2612 optarg = argv[argit + 1];
2613 if (atoi(optarg) > 0 ) {
2614 config->max_tiles_per_copy = atoi(optarg);
2615 ++argit;
2616 }
2617 }
2618 }
2619
2620
2621 /* GDAL formats */
2622 else if (CSEQUAL(argv[argit], "-G")) {
2623 uint32_t drv_count = 0;
2624 rt_gdaldriver drv_set = rt_raster_gdal_drivers(&drv_count, 0);
2625 if (drv_set == NULL || !drv_count) {
2626 rterror(_("Could not get list of available GDAL raster formats"));
2627 }
2628 else {
2629 printf(_("Supported GDAL raster formats:\n"));
2630 for (j = 0; j < drv_count; j++) {
2631 printf(_(" %s\n"), drv_set[j].long_name);
2632
2633 rtdealloc(drv_set[j].short_name);
2634 rtdealloc(drv_set[j].long_name);
2635 rtdealloc(drv_set[j].create_options);
2636 }
2637 rtdealloc(drv_set);
2638 }
2639
2640 rtdealloc_config(config);
2641 exit(0);
2642 }
2643 /* help */
2644 else if (CSEQUAL(argv[argit], "-?")) {
2645 usage();
2646 rtdealloc_config(config);
2647 exit(0);
2648 }
2649 else {
2650 size_t len;
2651 config->rt_file_count++;
2652 config->rt_file = (char **) rtrealloc(config->rt_file, sizeof(char *) * config->rt_file_count);
2653 if (config->rt_file == NULL) {
2654 rterror(_("Could not allocate memory for storing raster files"));
2655 rtdealloc_config(config);
2656 exit(1);
2657 }
2658
2659 len = strlen(argv[argit]) + 1;
2660 config->rt_file[config->rt_file_count - 1] = rtalloc(sizeof(char) * len);
2661 if (config->rt_file[config->rt_file_count - 1] == NULL) {
2662 rterror(_("Could not allocate memory for storing raster filename"));
2663 rtdealloc_config(config);
2664 exit(1);
2665 }
2666 strncpy(config->rt_file[config->rt_file_count - 1], argv[argit], len);
2667 }
2668 }
2669
2670 if (config->srid != config->out_srid && config->out_srid != SRID_UNKNOWN) {
2671 if (config->copy_statements) {
2672 rterror(_("Invalid argument combination - cannot use -Y with -s FROM_SRID:TO_SRID"));
2673 exit(1);
2674 }
2675 }
2676
2677 /* register GDAL drivers */
2678 GDALAllRegister();
2679
2680 /* no files provided */
2681 if (!config->rt_file_count) {
2682 rterror(_("No raster provided"));
2683 rtdealloc_config(config);
2684 exit(1);
2685 }
2686 /*
2687 at least two files, see if last is table
2688 last isn't recognized by GDAL
2689 */
2690 else if (config->rt_file_count > 1) {
2691 drv = GDALIdentifyDriver(config->rt_file[config->rt_file_count - 1], NULL);
2692
2693 if (drv == NULL) {
2694 char *ptr;
2695 ptr = strchr(config->rt_file[config->rt_file_count - 1], '.');
2696
2697 /* schema.table */
2698 if (ptr) {
2699 config->schema = rtalloc(sizeof(char) * (ptr - config->rt_file[config->rt_file_count - 1] + 1));
2700 if (config->schema == NULL) {
2701 rterror(_("Could not allocate memory for storing schema name"));
2702 rtdealloc_config(config);
2703 exit(1);
2704 }
2705 snprintf(config->schema, ptr - config->rt_file[config->rt_file_count - 1] + 1, "%s", config->rt_file[config->rt_file_count - 1]);
2706 config->schema[ptr - config->rt_file[config->rt_file_count - 1]] = '\0';
2707
2708 config->table = rtalloc(sizeof(char) * (strlen(config->rt_file[config->rt_file_count - 1]) - strlen(config->schema) + 1));
2709 if (config->table == NULL) {
2710 rterror(_("Could not allocate memory for storing table name"));
2711 rtdealloc_config(config);
2712 exit(1);
2713 }
2714 snprintf(config->table, strlen(config->rt_file[config->rt_file_count - 1]) - strlen(config->schema), "%s", ptr + 1);
2715 config->table[strlen(config->rt_file[config->rt_file_count - 1]) - strlen(config->schema)] = '\0';
2716 }
2717 /* table */
2718 else {
2719 const size_t len = strlen(config->rt_file[config->rt_file_count - 1]) + 1;
2720 config->table = rtalloc(sizeof(char) * len);
2721 if (config->table == NULL) {
2722 rterror(_("Could not allocate memory for storing table name"));
2723 rtdealloc_config(config);
2724 exit(1);
2725 }
2726 strncpy(config->table, config->rt_file[config->rt_file_count - 1], len);
2727 }
2728
2729 rtdealloc(config->rt_file[--(config->rt_file_count)]);
2730 config->rt_file = (char **) rtrealloc(config->rt_file, sizeof(char *) * config->rt_file_count);
2731 if (config->rt_file == NULL) {
2732 rterror(_("Could not reallocate the memory holding raster names"));
2733 rtdealloc_config(config);
2734 exit(1);
2735 }
2736 }
2737 }
2738
2739 /****************************************************************************
2740 * validate raster files
2741 ****************************************************************************/
2742
2743 /* check that GDAL recognizes all files */
2744 for (i = 0; i < config->rt_file_count; i++) {
2745 drv = GDALIdentifyDriver(config->rt_file[i], NULL);
2746
2747 if (drv == NULL) {
2748 rterror(_("Unable to read raster file: %s"), config->rt_file[i]);
2749 rtdealloc_config(config);
2750 exit(1);
2751 }
2752 }
2753
2754 /* process each file for just the filename */
2755 config->rt_filename = (char **) rtalloc(sizeof(char *) * config->rt_file_count);
2756 if (config->rt_filename == NULL) {
2757 rterror(_("Could not allocate memory for cleaned raster filenames"));
2758 rtdealloc_config(config);
2759 exit(1);
2760 }
2761 for (i = 0; i < config->rt_file_count; i++) {
2762 char *file;
2763 char *ptr;
2764
2765 file = rtalloc(sizeof(char) * (strlen(config->rt_file[i]) + 1));
2766 if (file == NULL) {
2767 rterror(_("Could not allocate memory for cleaned raster filename"));
2768 rtdealloc_config(config);
2769 exit(1);
2770 }
2771 strcpy(file, config->rt_file[i]);
2772
2773 for (ptr = file + strlen(file); ptr > file; ptr--) {
2774 if (*ptr == '/' || *ptr == '\\') {
2775 ptr++;
2776 break;
2777 }
2778 }
2779
2780 config->rt_filename[i] = rtalloc(sizeof(char) * (strlen(ptr) + 1));
2781 if (config->rt_filename[i] == NULL) {
2782 rterror(_("Could not allocate memory for cleaned raster filename"));
2783 rtdealloc_config(config);
2784 exit(1);
2785 }
2786 strcpy(config->rt_filename[i], ptr);
2787 rtdealloc(file);
2788 }
2789
2790 /****************************************************************************
2791 * defaults for table and column names
2792 ****************************************************************************/
2793
2794 /* first file as proxy table name */
2795 if (config->table == NULL) {
2796 char *file;
2797 char *ptr;
2798
2799 file = rtalloc(sizeof(char) * (strlen(config->rt_filename[0]) + 1));
2800 if (file == NULL) {
2801 rterror(_("Could not allocate memory for proxy table name"));
2802 rtdealloc_config(config);
2803 exit(1);
2804 }
2805 strcpy(file, config->rt_filename[0]);
2806
2807 for (ptr = file + strlen(file); ptr > file; ptr--) {
2808 if (*ptr == '.') {
2809 *ptr = '\0';
2810 break;
2811 }
2812 }
2813
2814 config->table = rtalloc(sizeof(char) * (strlen(file) + 1));
2815 if (config->table == NULL) {
2816 rterror(_("Could not allocate memory for proxy table name"));
2817 rtdealloc_config(config);
2818 exit(1);
2819 }
2820 strcpy(config->table, file);
2821 rtdealloc(file);
2822 }
2823
2824 /* raster_column not specified, default to "rast" */
2825 if (config->raster_column == NULL) {
2826 config->raster_column = rtalloc(sizeof(char) * (strlen("rast") + 1));
2827 if (config->raster_column == NULL) {
2828 rterror(_("Could not allocate memory for default raster column name"));
2829 rtdealloc_config(config);
2830 exit(1);
2831 }
2832 strcpy(config->raster_column, "rast");
2833 }
2834
2835 /* file_column_name not specified, default to "filename" */
2836 if (config->file_column_name == NULL) {
2837 config->file_column_name = rtalloc(sizeof(char) * (strlen("filename") + 1));
2838 if (config->file_column_name == NULL) {
2839 rterror(_("Could not allocate memory for default filename column name"));
2840 rtdealloc_config(config);
2841 exit(1);
2842 }
2843 strcpy(config->file_column_name, "filename");
2844 }
2845
2846 /****************************************************************************
2847 * literal PostgreSQL identifiers disabled
2848 ****************************************************************************/
2849
2850 /* no quotes, lower case everything */
2851 if (!config->quoteident) {
2852 if (config->schema != NULL)
2853 config->schema = strtolower(config->schema);
2854 if (config->table != NULL)
2855 config->table = strtolower(config->table);
2856 if (config->raster_column != NULL)
2857 config->raster_column = strtolower(config->raster_column);
2858 if (config->file_column_name != NULL)
2859 config->file_column_name = strtolower(config->file_column_name);
2860 if (config->tablespace != NULL)
2861 config->tablespace = strtolower(config->tablespace);
2862 if (config->idx_tablespace != NULL)
2863 config->idx_tablespace = strtolower(config->idx_tablespace);
2864 }
2865
2866 /****************************************************************************
2867 * overview table names
2868 ****************************************************************************/
2869
2870 if (config->overview_count) {
2871 char factor[4];
2872 config->overview_table = rtalloc(sizeof(char *) * config->overview_count);
2873 if (config->overview_table == NULL) {
2874 rterror(_("Could not allocate memory for overview table names"));
2875 rtdealloc_config(config);
2876 exit(1);
2877 }
2878
2879 for (i = 0; i < config->overview_count; i++) {
2880 sprintf(factor, "%d", config->overview[i]);
2881
2882 config->overview_table[i] = rtalloc(sizeof(char) * (strlen("o__") + strlen(factor) + strlen(config->table) + 1));
2883 if (config->overview_table[i] == NULL) {
2884 rterror(_("Could not allocate memory for overview table name"));
2885 rtdealloc_config(config);
2886 exit(1);
2887 }
2888 sprintf(config->overview_table[i], "o_%d_%s", config->overview[i], config->table);
2889 }
2890 }
2891
2892 /****************************************************************************
2893 * check that identifiers won't get truncated
2894 ****************************************************************************/
2895
2896 if (config->schema != NULL && strlen(config->schema) > MAXNAMELEN) {
2897 rtwarn(_("The schema name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2898 config->schema,
2900 );
2901 }
2902 if (config->table != NULL && strlen(config->table) > MAXNAMELEN) {
2903 rtwarn(_("The table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2904 config->table,
2906 );
2907 }
2908 if (config->raster_column != NULL && strlen(config->raster_column) > MAXNAMELEN) {
2909 rtwarn(_("The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2910 config->raster_column,
2912 );
2913 }
2914 if (config->file_column_name != NULL && strlen(config->file_column_name) > MAXNAMELEN) {
2915 rtwarn(_("The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2916 config->file_column_name,
2918 );
2919 }
2920 if (config->tablespace != NULL && strlen(config->tablespace) > MAXNAMELEN) {
2921 rtwarn(_("The tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2922 config->tablespace,
2924 );
2925 }
2926 if (config->idx_tablespace != NULL && strlen(config->idx_tablespace) > MAXNAMELEN) {
2927 rtwarn(_("The index tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2928 config->idx_tablespace,
2930 );
2931 }
2932 if (config->overview_count) {
2933 for (i = 0; i < config->overview_count; i++) {
2934 if (strlen(config->overview_table[i]) > MAXNAMELEN) {
2935 rtwarn(_("The overview table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2936 config->overview_table[i],
2938 );
2939 }
2940 }
2941 }
2942
2943 /****************************************************************************
2944 * double quote identifiers
2945 ****************************************************************************/
2946
2947 if (config->schema != NULL) {
2948 tmp = rtalloc(sizeof(char) * (strlen(config->schema) + 4));
2949 if (tmp == NULL) {
2950 rterror(_("Could not allocate memory for quoting schema name"));
2951 rtdealloc_config(config);
2952 exit(1);
2953 }
2954
2955 sprintf(tmp, "\"%s\".", config->schema);
2956 rtdealloc(config->schema);
2957 config->schema = tmp;
2958 }
2959 if (config->table != NULL) {
2960 tmp = rtalloc(sizeof(char) * (strlen(config->table) + 3));
2961 if (tmp == NULL) {
2962 rterror(_("Could not allocate memory for quoting table name"));
2963 rtdealloc_config(config);
2964 exit(1);
2965 }
2966
2967 sprintf(tmp, "\"%s\"", config->table);
2968 rtdealloc(config->table);
2969 config->table = tmp;
2970 }
2971 if (config->raster_column != NULL) {
2972 tmp = rtalloc(sizeof(char) * (strlen(config->raster_column) + 3));
2973 if (tmp == NULL) {
2974 rterror(_("Could not allocate memory for quoting raster column name"));
2975 rtdealloc_config(config);
2976 exit(1);
2977 }
2978
2979 sprintf(tmp, "\"%s\"", config->raster_column);
2980 rtdealloc(config->raster_column);
2981 config->raster_column = tmp;
2982 }
2983 if (config->file_column_name != NULL) {
2984 tmp = rtalloc(sizeof(char) * (strlen(config->file_column_name) + 3));
2985 if (tmp == NULL) {
2986 rterror(_("Could not allocate memory for quoting raster column name"));
2987 rtdealloc_config(config);
2988 exit(1);
2989 }
2990
2991 sprintf(tmp, "\"%s\"", config->file_column_name);
2992 rtdealloc(config->file_column_name);
2993 config->file_column_name = tmp;
2994 }
2995 if (config->tablespace != NULL) {
2996 tmp = rtalloc(sizeof(char) * (strlen(config->tablespace) + 3));
2997 if (tmp == NULL) {
2998 rterror(_("Could not allocate memory for quoting tablespace name"));
2999 rtdealloc_config(config);
3000 exit(1);
3001 }
3002
3003 sprintf(tmp, "\"%s\"", config->tablespace);
3004 rtdealloc(config->tablespace);
3005 config->tablespace = tmp;
3006 }
3007 if (config->idx_tablespace != NULL) {
3008 tmp = rtalloc(sizeof(char) * (strlen(config->idx_tablespace) + 3));
3009 if (tmp == NULL) {
3010 rterror(_("Could not allocate memory for quoting index tablespace name"));
3011 rtdealloc_config(config);
3012 exit(1);
3013 }
3014
3015 sprintf(tmp, "\"%s\"", config->idx_tablespace);
3016 rtdealloc(config->idx_tablespace);
3017 config->idx_tablespace = tmp;
3018 }
3019 if (config->overview_count) {
3020 for (i = 0; i < config->overview_count; i++) {
3021 tmp = rtalloc(sizeof(char) * (strlen(config->overview_table[i]) + 3));
3022 if (tmp == NULL) {
3023 rterror(_("Could not allocate memory for quoting overview table name"));
3024 rtdealloc_config(config);
3025 exit(1);
3026 }
3027
3028 sprintf(tmp, "\"%s\"", config->overview_table[i]);
3029 rtdealloc(config->overview_table[i]);
3030 config->overview_table[i] = tmp;
3031 }
3032 }
3033
3034 /****************************************************************************
3035 * processing of rasters
3036 ****************************************************************************/
3037
3038 /* initialize string buffer */
3039 buffer = rtalloc(sizeof(STRINGBUFFER));
3040 if (buffer == NULL) {
3041 rterror(_("Could not allocate memory for output string buffer"));
3042 rtdealloc_config(config);
3043 exit(1);
3044 }
3046
3047 /* pass off to processing function */
3048 if (!process_rasters(config, buffer)) {
3049 rterror(_("Unable to process rasters"));
3051 rtdealloc_config(config);
3052 exit(1);
3053 }
3054
3056
3058 rtdealloc_config(config);
3059
3060 return 0;
3061}
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:191
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition rt_raster.c:1716
void * rtrealloc(void *mem, size_t size)
Definition rt_context.c:199
void rtdealloc(void *mem)
Definition rt_context.c:206
Datum buffer(PG_FUNCTION_ARGS)
static void rtdealloc_stringbuffer(STRINGBUFFER *buffer, int freebuffer)
static void usage()
static int array_range(int min, int max, int step, int **range, uint32_t *len)
static void flush_stringbuffer(STRINGBUFFER *buffer)
static void init_config(RTLOADERCFG *config)
static char * strtolower(char *str)
static void rt_init_allocators(void)
static char ** strsplit(const char *str, const char *delimiter, uint32_t *n)
static void rtdealloc_config(RTLOADERCFG *config)
static void init_stringbuffer(STRINGBUFFER *buffer)
static int process_rasters(RTLOADERCFG *config, STRINGBUFFER *buffer)
static char * trim(const char *input)
#define MAXNAMELEN
#define CSEQUAL(a, b)
#define MAXOVFACTOR
#define MINOVFACTOR
#define _(String)
Definition shpcommon.h:24
uint32_t max_tiles_per_copy
max tiles per copy

References _, array_range(), buffer(), raster_loader_config::constraints, raster_loader_config::copy_statements, CSEQUAL, raster_loader_config::endian, raster_loader_config::file_column, raster_loader_config::file_column_name, flush_stringbuffer(), raster_loader_config::hasnodata, raster_loader_config::idx, raster_loader_config::idx_tablespace, init_config(), init_stringbuffer(), raster_loader_config::maintenance, raster_loader_config::max_extent, raster_loader_config::max_tiles_per_copy, MAXNAMELEN, MAXOVFACTOR, MINOVFACTOR, raster_loader_config::nband, raster_loader_config::nband_count, raster_loader_config::nodataval, raster_loader_config::opt, raster_loader_config::out_srid, raster_loader_config::outdb, raster_loader_config::overview, raster_loader_config::overview_count, raster_loader_config::overview_table, raster_loader_config::pad_tile, process_rasters(), raster_loader_config::quoteident, raster_loader_config::raster_column, raster_loader_config::regular_blocking, raster_loader_config::rt_file, raster_loader_config::rt_file_count, raster_loader_config::rt_filename, rt_init_allocators(), rt_raster_gdal_drivers(), rtalloc(), rtdealloc(), rtdealloc_config(), rtdealloc_stringbuffer(), rterror(), rtrealloc(), rtwarn(), raster_loader_config::schema, raster_loader_config::skip_nodataval_check, raster_loader_config::srid, SRID_UNKNOWN, strsplit(), strtolower(), raster_loader_config::table, raster_loader_config::tablespace, raster_loader_config::tile_size, raster_loader_config::transaction, trim(), usage(), and raster_loader_config::version.

Here is the call graph for this function: