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

Definition at line 1983 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_from(), copy_from_end(), 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::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().

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

Here is the call graph for this function:

Here is the caller graph for this function: