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

◆ process_rasters()

static int process_rasters ( RTLOADERCFG config,
STRINGBUFFER buffer 
)
static

Definition at line 2004 of file raster2pgsql.c.

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