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