PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ process_rasters()

static int process_rasters ( RTLOADERCFG config,
STRINGBUFFER buffer 
)
static

Definition at line 1992 of file raster2pgsql.c.

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

References _, add_overview_constraints(), add_raster_constraints(), analyze_table(), append_sql_to_buffer(), 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().

Here is the call graph for this function:
Here is the caller graph for this function: