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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 2262 of file raster2pgsql.c.

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

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, 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: