Skip to content

Commit 03d9bb8

Browse files
authored
Merge pull request #2020 from joto/raster-gen-condition
Add config option for WHERE clause to tile-raster generalizer
2 parents 57875ca + 6473d09 commit 03d9bb8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/gen/gen-tile-raster.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ gen_tile_raster_union_t::gen_tile_raster_union_t(pg_conn_t *connection,
4141
m_turdsize = static_cast<int>(
4242
uint_in_range(*params, "turdsize", 0, 65536, m_turdsize));
4343

44+
std::string const where_condition = get_params().get_string("where", "");
45+
4446
if (get_params().has("img_path")) {
4547
m_image_path = get_params().get_string("img_path");
4648
}
@@ -89,30 +91,37 @@ CREATE TABLE IF NOT EXISTS "{}" (
8991
log_gen("Image extent: {}px, buffer: {}px, margin: {}", m_image_extent,
9092
m_image_buffer, m_margin);
9193

94+
std::string prepare;
9295
if (with_group_by()) {
93-
dbexec(R"(
96+
prepare = R"(
9497
PREPARE get_geoms (real, real, real, real) AS
9598
SELECT "{geom_column}", "{group_by_column}"
9699
FROM {src}
97100
WHERE "{geom_column}" && ST_MakeEnvelope($1, $2, $3, $4, 3857)
98-
)");
101+
)";
99102
dbexec(R"(
100103
PREPARE insert_geoms (geometry, int, int, text) AS
101104
INSERT INTO {dest} ("{geom_column}", x, y, "{group_by_column}")
102105
VALUES ({geom_sql}, $2, $3, $4)
103106
)");
104107
} else {
105-
dbexec(R"(
108+
prepare = R"(
106109
PREPARE get_geoms (real, real, real, real) AS
107110
SELECT "{geom_column}", NULL AS param
108111
FROM {src}
109112
WHERE "{geom_column}" && ST_MakeEnvelope($1, $2, $3, $4, 3857)
110-
)");
113+
)";
111114
dbexec(R"(
112115
PREPARE insert_geoms (geometry, int, int, text) AS
113116
INSERT INTO {dest} ("{geom_column}", x, y) VALUES ({geom_sql}, $2, $3)
114117
)");
115118
}
119+
120+
if (!where_condition.empty()) {
121+
prepare.append(fmt::format(" AND ({})", where_condition));
122+
}
123+
124+
dbexec(prepare);
116125
}
117126

118127
static void save_image_to_table(pg_conn_t *connection, canvas_t const &canvas,

0 commit comments

Comments
 (0)