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

Definition at line 2288 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::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, 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.

2288  {
2289  RTLOADERCFG *config = NULL;
2290  STRINGBUFFER *buffer = NULL;
2291  int i = 0;
2292  int j = 0;
2293  char **elements = NULL;
2294  int n = 0;
2295  GDALDriverH drv = NULL;
2296  char *tmp = NULL;
2297 
2298 #ifdef USE_NLS
2299  setlocale (LC_ALL, "");
2300  bindtextdomain (PACKAGE, LOCALEDIR);
2301  textdomain (PACKAGE);
2302 #endif
2303 
2304  /* Set up memory allocators */
2306 
2307  /* no args, show usage */
2308  if (argc == 1) {
2309  usage();
2310  exit(0);
2311  }
2312 
2313  /* initialize config */
2314  config = rtalloc(sizeof(RTLOADERCFG));
2315  if (config == NULL) {
2316  rterror(_("Could not allocate memory for loader configuration"));
2317  exit(1);
2318  }
2319  init_config(config);
2320 
2321  /****************************************************************************
2322  * parse arguments
2323  ****************************************************************************/
2324 
2325  for (i = 1; i < argc; i++) {
2326  /* srid */
2327  if (CSEQUAL(argv[i], "-s") && i < argc - 1) {
2328  config->srid = atoi(argv[++i]);
2329  }
2330  /* band index */
2331  else if (CSEQUAL(argv[i], "-b") && i < argc - 1) {
2332  elements = strsplit(argv[++i], ",", &n);
2333  if (n < 1) {
2334  rterror(_("Could not process -b"));
2335  rtdealloc_config(config);
2336  exit(1);
2337  }
2338 
2339  config->nband_count = 0;
2340  for (j = 0; j < n; j++) {
2341  char *t = trim(elements[j]);
2342  char **minmax = NULL;
2343  int *range = NULL;
2344  int p = 0;
2345  int l = 0;
2346  int m = 0;
2347  int o = 0;
2348 
2349  /* is t a range? */
2350  minmax = strsplit(t, "-", &o);
2351  if (o == 2) {
2352  if (!array_range(atoi(minmax[0]), atoi(minmax[1]), 1, &range, &p)) {
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  }
2365  else {
2366  p = 1;
2367  range = rtalloc(sizeof(int));
2368  if (range == NULL) {
2369  rterror(_("Could not allocate memory for storing band indices"));
2370  for (l = 0; l < o; l++)
2371  rtdealloc(minmax[l]);
2372  rtdealloc(minmax);
2373  for (j = 0; j < n; j++)
2374  rtdealloc(elements[j]);
2375  rtdealloc(elements);
2376  rtdealloc(t);
2377  rtdealloc_config(config);
2378  exit(1);
2379  }
2380  *range = atoi(t);
2381  }
2382 
2383  m = config->nband_count;
2384  config->nband_count += p;
2385  config->nband = rtrealloc(config->nband, sizeof(int) * config->nband_count);
2386  if (config->nband == NULL) {
2387  rterror(_("Could not allocate memory for storing band indices"));
2388  rtdealloc(range);
2389  for (l = 0; l < o; l++)
2390  rtdealloc(minmax[l]);
2391  rtdealloc(minmax);
2392  for (j = 0; j < n; j++)
2393  rtdealloc(elements[j]);
2394  rtdealloc(elements);
2395  rtdealloc(t);
2396  rtdealloc_config(config);
2397  exit(1);
2398  }
2399 
2400  for (l = 0; l < p; l++, m++)
2401  config->nband[m] = range[l];
2402 
2403  rtdealloc(range);
2404 
2405  for (l = 0; l < o; l++)
2406  rtdealloc(minmax[l]);
2407  rtdealloc(minmax);
2408 
2409  rtdealloc(t);
2410  rtdealloc(elements[j]);
2411  }
2412  rtdealloc(elements);
2413  elements = NULL;
2414  n = 0;
2415 
2416  for (j = 0; j < config->nband_count; j++) {
2417  if (config->nband[j] < 1) {
2418  rterror(_("Band index %d must be greater than 0"), config->nband[j]);
2419  rtdealloc_config(config);
2420  exit(1);
2421  }
2422  }
2423  }
2424  /* tile size */
2425  else if (CSEQUAL(argv[i], "-t") && i < argc - 1) {
2426  if (CSEQUAL(argv[++i], "auto")) {
2427  config->tile_size[0] = -1;
2428  config->tile_size[1] = -1;
2429  }
2430  else {
2431  elements = strsplit(argv[i], "x", &n);
2432  if (n != 2) {
2433  rterror(_("Could not process -t"));
2434  rtdealloc_config(config);
2435  exit(1);
2436  }
2437 
2438  for (j = 0; j < n; j++) {
2439  char *t = trim(elements[j]);
2440  config->tile_size[j] = atoi(t);
2441  rtdealloc(t);
2442  rtdealloc(elements[j]);
2443  }
2444  rtdealloc(elements);
2445  elements = NULL;
2446  n = 0;
2447 
2448  for (j = 0; j < 2; j++) {
2449  if (config->tile_size[j] < 1) {
2450  rterror(_("Tile size must be greater than 0x0"));
2451  rtdealloc_config(config);
2452  exit(1);
2453  }
2454  }
2455  }
2456  }
2457  /* pad tiles */
2458  else if (CSEQUAL(argv[i], "-P")) {
2459  config->pad_tile = 1;
2460  }
2461  /* out-of-db raster */
2462  else if (CSEQUAL(argv[i], "-R")) {
2463  config->outdb = 1;
2464  }
2465  /* drop table and recreate */
2466  else if (CSEQUAL(argv[i], "-d")) {
2467  config->opt = 'd';
2468  }
2469  /* append to table */
2470  else if (CSEQUAL(argv[i], "-a")) {
2471  config->opt = 'a';
2472  }
2473  /* create new table */
2474  else if (CSEQUAL(argv[i], "-c")) {
2475  config->opt = 'c';
2476  }
2477  /* prepare only */
2478  else if (CSEQUAL(argv[i], "-p")) {
2479  config->opt = 'p';
2480  }
2481  /* raster column name */
2482  else if (CSEQUAL(argv[i], "-f") && i < argc - 1) {
2483  config->raster_column = rtalloc(sizeof(char) * (strlen(argv[++i]) + 1));
2484  if (config->raster_column == NULL) {
2485  rterror(_("Could not allocate memory for storing raster column name"));
2486  rtdealloc_config(config);
2487  exit(1);
2488  }
2489  strncpy(config->raster_column, argv[i], strlen(argv[i]) + 1);
2490  }
2491  /* filename column */
2492  else if (CSEQUAL(argv[i], "-F")) {
2493  config->file_column = 1;
2494  }
2495  /* filename column name */
2496  else if (CSEQUAL(argv[i], "-n") && i < argc - 1) {
2497  config->file_column_name = rtalloc(sizeof(char) * (strlen(argv[++i]) + 1));
2498  if (config->file_column_name == NULL) {
2499  rterror(_("Could not allocate memory for storing filename column name"));
2500  rtdealloc_config(config);
2501  exit(1);
2502  }
2503  strncpy(config->file_column_name, argv[i], strlen(argv[i]) + 1);
2504  config->file_column = 1;
2505  }
2506  /* overview factors */
2507  else if (CSEQUAL(argv[i], "-l") && i < argc - 1) {
2508  elements = strsplit(argv[++i], ",", &n);
2509  if (n < 1) {
2510  rterror(_("Could not process -l"));
2511  rtdealloc_config(config);
2512  exit(1);
2513  }
2514 
2515  config->overview_count = n;
2516  config->overview = rtalloc(sizeof(int) * n);
2517  if (config->overview == NULL) {
2518  rterror(_("Could not allocate memory for storing overview factors"));
2519  rtdealloc_config(config);
2520  exit(1);
2521  }
2522  for (j = 0; j < n; j++) {
2523  char *t = trim(elements[j]);
2524  config->overview[j] = atoi(t);
2525  rtdealloc(t);
2526  rtdealloc(elements[j]);
2527  }
2528  rtdealloc(elements);
2529  elements = NULL;
2530  n = 0;
2531 
2532  for (j = 0; j < config->overview_count; j++) {
2533  if (config->overview[j] < MINOVFACTOR || config->overview[j] > MAXOVFACTOR) {
2534  rterror(_("Overview factor %d is not between %d and %d"), config->overview[j], MINOVFACTOR, MAXOVFACTOR);
2535  rtdealloc_config(config);
2536  exit(1);
2537  }
2538  }
2539  }
2540  /* quote identifiers */
2541  else if (CSEQUAL(argv[i], "-q")) {
2542  config->quoteident = 1;
2543  }
2544  /* create index */
2545  else if (CSEQUAL(argv[i], "-I")) {
2546  config->idx = 1;
2547  }
2548  /* maintenance */
2549  else if (CSEQUAL(argv[i], "-M")) {
2550  config->maintenance = 1;
2551  }
2552  /* set constraints */
2553  else if (CSEQUAL(argv[i], "-C")) {
2554  config->constraints = 1;
2555  }
2556  /* disable extent constraint */
2557  else if (CSEQUAL(argv[i], "-x")) {
2558  config->max_extent = 0;
2559  }
2560  /* enable regular_blocking */
2561  else if (CSEQUAL(argv[i], "-r")) {
2562  config->regular_blocking = 1;
2563  }
2564  /* tablespace of new table */
2565  else if (CSEQUAL(argv[i], "-T") && i < argc - 1) {
2566  config->tablespace = rtalloc(sizeof(char) * (strlen(argv[++i]) + 1));
2567  if (config->tablespace == NULL) {
2568  rterror(_("Could not allocate memory for storing tablespace of new table"));
2569  rtdealloc_config(config);
2570  exit(1);
2571  }
2572  strncpy(config->tablespace, argv[i], strlen(argv[i]) + 1);
2573  }
2574  /* tablespace of new index */
2575  else if (CSEQUAL(argv[i], "-X") && i < argc - 1) {
2576  config->idx_tablespace = rtalloc(sizeof(char) * (strlen(argv[++i]) + 1));
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[i], strlen(argv[i]) + 1);
2583  }
2584  /* nodata value */
2585  else if (CSEQUAL(argv[i], "-N") && i < argc - 1) {
2586  config->hasnodata = 1;
2587  config->nodataval = atof(argv[++i]);
2588  }
2589  /* skip NODATA value check for bands */
2590  else if (CSEQUAL(argv[i], "-k")) {
2591  config->skip_nodataval_check = 1;
2592  }
2593  /* endianness */
2594  else if (CSEQUAL(argv[i], "-E") && i < argc - 1) {
2595  config->endian = atoi(argv[++i]);
2596  config->endian = 1;
2597  }
2598  /* version */
2599  else if (CSEQUAL(argv[i], "-V") && i < argc - 1) {
2600  config->version = atoi(argv[++i]);
2601  config->version = 0;
2602  }
2603  /* transaction */
2604  else if (CSEQUAL(argv[i], "-e")) {
2605  config->transaction = 0;
2606  }
2607  /* COPY statements */
2608  else if (CSEQUAL(argv[i], "-Y")) {
2609  config->copy_statements = 1;
2610  }
2611  /* GDAL formats */
2612  else if (CSEQUAL(argv[i], "-G")) {
2613  uint32_t drv_count = 0;
2614  rt_gdaldriver drv_set = rt_raster_gdal_drivers(&drv_count, 0);
2615  if (drv_set == NULL || !drv_count) {
2616  rterror(_("Could not get list of available GDAL raster formats"));
2617  }
2618  else {
2619  printf(_("Supported GDAL raster formats:\n"));
2620  for (j = 0; j < drv_count; j++) {
2621  printf(_(" %s\n"), drv_set[j].long_name);
2622 
2623  rtdealloc(drv_set[j].short_name);
2624  rtdealloc(drv_set[j].long_name);
2625  rtdealloc(drv_set[j].create_options);
2626  }
2627  rtdealloc(drv_set);
2628  }
2629 
2630  rtdealloc_config(config);
2631  exit(0);
2632  }
2633  /* help */
2634  else if (CSEQUAL(argv[i], "-?")) {
2635  usage();
2636  rtdealloc_config(config);
2637  exit(0);
2638  }
2639  else {
2640  config->rt_file_count++;
2641  config->rt_file = (char **) rtrealloc(config->rt_file, sizeof(char *) * config->rt_file_count);
2642  if (config->rt_file == NULL) {
2643  rterror(_("Could not allocate memory for storing raster files"));
2644  rtdealloc_config(config);
2645  exit(1);
2646  }
2647 
2648  config->rt_file[config->rt_file_count - 1] = rtalloc(sizeof(char) * (strlen(argv[i]) + 1));
2649  if (config->rt_file[config->rt_file_count - 1] == NULL) {
2650  rterror(_("Could not allocate memory for storing raster filename"));
2651  rtdealloc_config(config);
2652  exit(1);
2653  }
2654  strncpy(config->rt_file[config->rt_file_count - 1], argv[i], strlen(argv[i]) + 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:793
void rtdealloc(void *mem)
Definition: rt_api.c:882
#define CSEQUAL(a, b)
Definition: raster2pgsql.h:46
static void rtdealloc_stringbuffer(STRINGBUFFER *buffer, int freebuffer)
Definition: raster2pgsql.c:767
#define _(String)
Definition: shpcommon.h:23
static int array_range(int min, int max, int step, int **range, int *len)
Definition: raster2pgsql.c:94
Datum buffer(PG_FUNCTION_ARGS)
void rtwarn(const char *fmt,...)
Definition: rt_api.c:920
#define MINOVFACTOR
Definition: raster2pgsql.h:56
static char * strtolower(char *str)
Definition: raster2pgsql.c:187
static int process_rasters(RTLOADERCFG *config, STRINGBUFFER *buffer)
static void rt_init_allocators(void)
Definition: raster2pgsql.c:65
#define MAXNAMELEN
Definition: raster2pgsql.h:53
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_api.c:8891
static void rtdealloc_config(RTLOADERCFG *config)
Definition: raster2pgsql.c:721
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
static void init_stringbuffer(STRINGBUFFER *buffer)
Definition: raster2pgsql.c:761
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
static char ** strsplit(const char *str, const char *delimiter, int *n)
Definition: raster2pgsql.c:198
static char * trim(const char *input)
Definition: raster2pgsql.c:263
static void init_config(RTLOADERCFG *config)
Definition: raster2pgsql.c:684
#define MAXOVFACTOR
Definition: raster2pgsql.h:57
static void usage()
Definition: raster2pgsql.c:325
void * rtrealloc(void *mem, size_t size)
Definition: rt_api.c:875

Here is the call graph for this function: