Skip to content

Commit 67543d7

Browse files
committed
Generalization: Get extent of source layer also for raster layers
When generalizations are calculated by tile we need to know which extent to work on. If we are not working with a full planet we get that information from the (estimated) extent of the source layer. This adds support for determining the extent for raster-based source layers. This is needed when we generalize source layers into rasters and then use those rasters as source for even lower level tiles.
1 parent 770083d commit 67543d7

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/gen/osm2pgsql-gen.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,22 @@ bool table_is_empty(pg_conn_t const &db_connection, std::string const &schema,
102102
tile_extent get_extent_from_db(pg_conn_t const &db_connection,
103103
std::string const &schema,
104104
std::string const &table,
105-
std::string const &column, uint32_t zoom)
105+
std::string const &column, bool raster,
106+
uint32_t zoom)
106107
{
107108
if (table_is_empty(db_connection, schema, table)) {
108109
return {};
109110
}
110111

111-
auto const result = db_connection.exec(
112-
"SELECT ST_XMin(e), ST_YMin(e), ST_XMax(e), ST_YMax(e)"
113-
" FROM ST_EstimatedExtent('{}', '{}', '{}') AS e",
114-
schema, table, column);
112+
std::string const sql =
113+
raster ? "SELECT ST_XMin(extent), ST_YMin(extent),"
114+
" ST_XMax(extent), ST_YMax(extent)"
115+
" FROM raster_columns WHERE r_table_schema='{}'"
116+
" AND r_table_name='{}' AND r_raster_column = '{}'"
117+
: "SELECT ST_XMin(e), ST_YMin(e), ST_XMax(e), ST_YMax(e)"
118+
" FROM ST_EstimatedExtent('{}', '{}', '{}') AS e";
119+
120+
auto const result = db_connection.exec(sql, schema, table, column);
115121

116122
if (result.num_tuples() == 0 || result.is_null(0, 0)) {
117123
return {};
@@ -135,6 +141,7 @@ tile_extent get_extent_from_db(pg_conn_t const &db_connection,
135141
params_t const &params, uint32_t zoom)
136142
{
137143
auto const schema = params.get_string("schema", default_schema);
144+
138145
std::string table;
139146
if (params.has("src_table")) {
140147
table = params.get_string("src_table");
@@ -147,8 +154,15 @@ tile_extent get_extent_from_db(pg_conn_t const &db_connection,
147154
} else {
148155
throw std::runtime_error{"Need 'src_table' or 'src_tables' param."};
149156
}
157+
150158
auto const geom_column = params.get_string("geom_column", "geom");
151-
return get_extent_from_db(db_connection, schema, table, geom_column, zoom);
159+
auto const raster_column = params.get_string("raster_column", "");
160+
161+
bool const is_raster = raster_column != "";
162+
163+
return get_extent_from_db(db_connection, schema, table,
164+
is_raster ? raster_column : geom_column,
165+
is_raster, zoom);
152166
}
153167

154168
void get_tiles_from_table(pg_conn_t const &connection, std::string const &table,

0 commit comments

Comments
 (0)