PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ process_rasters()

static int process_rasters ( RTLOADERCFG config,
STRINGBUFFER buffer 
)
static

Definition at line 2006 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().

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