PostGIS  2.3.7dev-r@@SVN_REVISION@@
int main ( int  argc,
char **  argv 
)

Definition at line 2273 of file raster2pgsql.c.

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.

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

Here is the call graph for this function: