PostGIS  2.5.0dev-r@@SVN_REVISION@@
static int process_rasters ( RTLOADERCFG config,
STRINGBUFFER buffer 
)
static

Definition at line 2003 of file raster2pgsql.c.

References _, add_overview_constraints(), add_raster_constraints(), analyze_table(), append_sql_to_buffer(), build_overview(), raster_loader_config::constraints, convert_raster(), copy_rastinfo(), raster_loader_config::copy_statements, create_index(), create_table(), diff_rastinfo(), drop_table(), raster_loader_config::file_column, raster_loader_config::file_column_name, flush_stringbuffer(), raster_loader_config::idx, raster_loader_config::idx_tablespace, init_rastinfo(), init_stringbuffer(), insert_records(), stringbuffer_t::length, raster_loader_config::maintenance, raster_loader_config::max_extent, raster_loader_config::opt, raster_loader_config::out_srid, raster_loader_config::overview, raster_loader_config::overview_count, raster_loader_config::overview_table, 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, rtdealloc_rastinfo(), rtdealloc_stringbuffer(), rterror(), raster_loader_config::schema, raster_loader_config::table, raster_loader_config::tablespace, raster_loader_config::transaction, and vacuum_table().

Referenced by main().

2003  {
2004  uint32_t i = 0;
2005 
2006  assert(config != NULL);
2007  assert(config->table != NULL);
2008  assert(config->raster_column != NULL);
2009 
2010  if (config->transaction) {
2011  if (!append_sql_to_buffer(buffer, strdup("BEGIN;"))) {
2012  rterror(_("process_rasters: Could not add BEGIN statement to string buffer"));
2013  return 0;
2014  }
2015  }
2016 
2017  /* drop table */
2018  if (config->opt == 'd') {
2019  if (!drop_table(config->schema, config->table, buffer)) {
2020  rterror(_("process_rasters: Could not add DROP TABLE statement to string buffer"));
2021  return 0;
2022  }
2023 
2024  if (config->overview_count) {
2025  for (i = 0; i < config->overview_count; i++) {
2026  if (!drop_table(config->schema, config->overview_table[i], buffer)) {
2027  rterror(_("process_rasters: Could not add an overview's DROP TABLE statement to string buffer"));
2028  return 0;
2029  }
2030  }
2031  }
2032  }
2033 
2034  /* create table */
2035  if (config->opt != 'a') {
2036  if (!create_table(
2037  config->schema, config->table, config->raster_column,
2038  config->file_column, config->file_column_name,
2039  config->tablespace, config->idx_tablespace,
2040  buffer
2041  )) {
2042  rterror(_("process_rasters: Could not add CREATE TABLE statement to string buffer"));
2043  return 0;
2044  }
2045 
2046  if (config->overview_count) {
2047  for (i = 0; i < config->overview_count; i++) {
2048  if (!create_table(
2049  config->schema, config->overview_table[i], config->raster_column,
2050  config->file_column, config->file_column_name,
2051  config->tablespace, config->idx_tablespace,
2052  buffer
2053  )) {
2054  rterror(_("process_rasters: Could not add an overview's CREATE TABLE statement to string buffer"));
2055  return 0;
2056  }
2057  }
2058  }
2059  }
2060 
2061  /* no need to run if opt is 'p' */
2062  if (config->opt != 'p') {
2063  RASTERINFO refinfo;
2064  init_rastinfo(&refinfo);
2065 
2066  /* process each raster */
2067  for (i = 0; i < config->rt_file_count; i++) {
2068  RASTERINFO rastinfo;
2069  STRINGBUFFER tileset;
2070 
2071  fprintf(stderr, _("Processing %d/%d: %s\n"), i + 1, config->rt_file_count, config->rt_file[i]);
2072 
2073  init_rastinfo(&rastinfo);
2074  init_stringbuffer(&tileset);
2075 
2076  /* convert raster */
2077  if (!convert_raster(i, config, &rastinfo, &tileset, buffer)) {
2078  rterror(_("process_rasters: Could not process raster: %s"), config->rt_file[i]);
2079  rtdealloc_rastinfo(&rastinfo);
2080  rtdealloc_stringbuffer(&tileset, 0);
2081  return 0;
2082  }
2083 
2084  /* process raster tiles into COPY or INSERT statements */
2085  if (tileset.length && !insert_records(
2086  config->schema, config->table, config->raster_column,
2087  (config->file_column ? config->rt_filename[i] : NULL),
2088  config->file_column_name,
2089  config->copy_statements, config->out_srid,
2090  &tileset, buffer
2091  )) {
2092  rterror(_("process_rasters: Could not convert raster tiles into INSERT or COPY statements"));
2093  rtdealloc_rastinfo(&rastinfo);
2094  rtdealloc_stringbuffer(&tileset, 0);
2095  return 0;
2096  }
2097 
2098  rtdealloc_stringbuffer(&tileset, 0);
2099 
2100  /* flush buffer after every raster */
2101  flush_stringbuffer(buffer);
2102 
2103  /* overviews */
2104  if (config->overview_count) {
2105  uint32_t j = 0;
2106 
2107  for (j = 0; j < config->overview_count; j++) {
2108 
2109  if (!build_overview(i, config, &rastinfo, j, &tileset, buffer)) {
2110  rterror(_("process_rasters: Could not create overview of factor %d for raster %s"), config->overview[j], config->rt_file[i]);
2111  rtdealloc_rastinfo(&rastinfo);
2112  rtdealloc_stringbuffer(&tileset, 0);
2113  return 0;
2114  }
2115 
2116  if (tileset.length && !insert_records(
2117  config->schema, config->overview_table[j], config->raster_column,
2118  (config->file_column ? config->rt_filename[i] : NULL), config->file_column_name,
2119  config->copy_statements, config->out_srid,
2120  &tileset, buffer
2121  )) {
2122  rterror(_("process_rasters: Could not convert overview tiles into INSERT or COPY statements"));
2123  rtdealloc_rastinfo(&rastinfo);
2124  rtdealloc_stringbuffer(&tileset, 0);
2125  return 0;
2126  }
2127 
2128  rtdealloc_stringbuffer(&tileset, 0);
2129 
2130  /* flush buffer after every raster */
2131  flush_stringbuffer(buffer);
2132  }
2133  }
2134 
2135  if (config->rt_file_count > 1) {
2136  if (i < 1)
2137  copy_rastinfo(&refinfo, &rastinfo);
2138  else {
2139  diff_rastinfo(&rastinfo, &refinfo);
2140  }
2141  }
2142 
2143  rtdealloc_rastinfo(&rastinfo);
2144  }
2145 
2146  rtdealloc_rastinfo(&refinfo);
2147  }
2148 
2149  /* index */
2150  if (config->idx) {
2151  /* create index */
2152  if (!create_index(
2153  config->schema, config->table, config->raster_column,
2154  config->idx_tablespace,
2155  buffer
2156  )) {
2157  rterror(_("process_rasters: Could not add CREATE INDEX statement to string buffer"));
2158  return 0;
2159  }
2160 
2161  /* analyze */
2162  if (config->opt != 'p') {
2163  if (!analyze_table(
2164  config->schema, config->table,
2165  buffer
2166  )) {
2167  rterror(_("process_rasters: Could not add ANALYZE statement to string buffer"));
2168  return 0;
2169  }
2170  }
2171 
2172  if (config->overview_count) {
2173  for (i = 0; i < config->overview_count; i++) {
2174  /* create index */
2175  if (!create_index(
2176  config->schema, config->overview_table[i], config->raster_column,
2177  config->idx_tablespace,
2178  buffer
2179  )) {
2180  rterror(_("process_rasters: Could not add an overview's CREATE INDEX statement to string buffer"));
2181  return 0;
2182  }
2183 
2184  /* analyze */
2185  if (config->opt != 'p') {
2186  if (!analyze_table(
2187  config->schema, config->overview_table[i],
2188  buffer
2189  )) {
2190  rterror(_("process_rasters: Could not add an overview's ANALYZE statement to string buffer"));
2191  return 0;
2192  }
2193  }
2194  }
2195  }
2196  }
2197 
2198  /* add constraints */
2199  if (config->constraints) {
2201  config->schema, config->table, config->raster_column,
2202  config->regular_blocking, config->max_extent,
2203  buffer
2204  )) {
2205  rterror(_("process:rasters: Could not add AddRasterConstraints statement to string buffer"));
2206  return 0;
2207  }
2208 
2209  if (config->overview_count) {
2210  for (i = 0; i < config->overview_count; i++) {
2212  config->schema, config->overview_table[i], config->raster_column,
2213  config->regular_blocking, config->max_extent,
2214  buffer
2215  )) {
2216  rterror(_("process_rasters: Could not add an overview's AddRasterConstraints statement to string buffer"));
2217  return 0;
2218  }
2219  }
2220  }
2221  }
2222 
2223  /* overview constraint is automatically added */
2224  if (config->overview_count) {
2225  for (i = 0; i < config->overview_count; i++) {
2227  config->schema, config->overview_table[i], config->raster_column,
2228  config->schema, config->table, config->raster_column,
2229  config->overview[i],
2230  buffer
2231  )) {
2232  rterror(_("process_rasters: Could not add an overview's AddOverviewConstraints statement to string buffer"));
2233  return 0;
2234  }
2235  }
2236  }
2237 
2238  if (config->transaction) {
2239  if (!append_sql_to_buffer(buffer, strdup("END;"))) {
2240  rterror(_("process_rasters: Could not add END statement to string buffer"));
2241  return 0;
2242  }
2243  }
2244 
2245  /* maintenance */
2246  if (config->opt != 'p' && config->maintenance) {
2247  if (!vacuum_table(
2248  config->schema, config->table,
2249  buffer
2250  )) {
2251  rterror(_("process_rasters: Could not add VACUUM statement to string buffer"));
2252  return 0;
2253  }
2254 
2255  if (config->overview_count) {
2256  for (i = 0; i < config->overview_count; i++) {
2257  if (!vacuum_table(
2258  config->schema, config->overview_table[i],
2259  buffer
2260  )) {
2261  rterror(_("process_rasters: Could not add an overview's VACUUM statement to string buffer"));
2262  return 0;
2263  }
2264  }
2265  }
2266 
2267  }
2268 
2269  return 1;
2270 }
static void flush_stringbuffer(STRINGBUFFER *buffer)
Definition: raster2pgsql.c:800
static int add_overview_constraints(const char *ovschema, const char *ovtable, const char *ovcolumn, const char *schema, const char *table, const char *column, const int factor, STRINGBUFFER *buffer)
static int analyze_table(const char *schema, const char *table, STRINGBUFFER *buffer)
static void init_rastinfo(RASTERINFO *info)
Definition: raster2pgsql.c:511
static void rtdealloc_stringbuffer(STRINGBUFFER *buffer, int freebuffer)
Definition: raster2pgsql.c:774
#define _(String)
Definition: shpcommon.h:24
static int create_index(const char *schema, const char *table, const char *column, const char *tablespace, STRINGBUFFER *buffer)
static void diff_rastinfo(RASTERINFO *x, RASTERINFO *ref)
Definition: raster2pgsql.c:600
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
uint32_t length
Definition: raster2pgsql.h:196
static int add_raster_constraints(const char *schema, const char *table, const char *column, int regular_blocking, int max_extent, STRINGBUFFER *buffer)
static int drop_table(const char *schema, const char *table, STRINGBUFFER *buffer)
Definition: raster2pgsql.c:995
static int vacuum_table(const char *schema, const char *table, STRINGBUFFER *buffer)
unsigned int uint32_t
Definition: uthash.h:78
static int insert_records(const char *schema, const char *table, const char *column, const char *filename, const char *file_column_name, int copy_statements, int out_srid, STRINGBUFFER *tileset, STRINGBUFFER *buffer)
Definition: raster2pgsql.c:877
static int append_sql_to_buffer(STRINGBUFFER *buffer, const char *str)
Definition: raster2pgsql.c:822
static int build_overview(int idx, RTLOADERCFG *config, RASTERINFO *info, uint32_t ovx, STRINGBUFFER *tileset, STRINGBUFFER *buffer)
static void rtdealloc_rastinfo(RASTERINFO *info)
Definition: raster2pgsql.c:526
static void init_stringbuffer(STRINGBUFFER *buffer)
Definition: raster2pgsql.c:768
static int convert_raster(int idx, RTLOADERCFG *config, RASTERINFO *info, STRINGBUFFER *tileset, STRINGBUFFER *buffer)
static int copy_rastinfo(RASTERINFO *dst, RASTERINFO *src)
Definition: raster2pgsql.c:542
static int create_table(const char *schema, const char *table, const char *column, const int file_column, const char *file_column_name, const char *tablespace, const char *idx_tablespace, STRINGBUFFER *buffer)

Here is the call graph for this function:

Here is the caller graph for this function: