-
-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathgen-tile-vector.cpp
More file actions
104 lines (95 loc) · 2.89 KB
/
Copy pathgen-tile-vector.cpp
File metadata and controls
104 lines (95 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2026 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include "gen-tile-vector.hpp"
#include "logging.hpp"
#include "params.hpp"
#include "pgsql.hpp"
#include "tile.hpp"
gen_tile_vector_union_t::gen_tile_vector_union_t(pg_conn_t *connection,
bool append, params_t *params)
: gen_tile_t(connection, append, params),
m_timer_simplify(add_timer("simplify"))
{
check_src_dest_table_params_exist();
if (!get_params().has("margin")) {
params->set("margin", 0.0);
} else {
// We don't need the result, just checking that this is a real number
get_params().get_double("margin");
}
if (!get_params().has("buffer_size")) {
params->set("buffer_size", static_cast<int64_t>(10));
} else {
// We don't need the result, just checking that this is an integer
get_params().get_int64("buffer_size");
}
if (with_group_by()) {
dbprepare("gen_geoms", R"(
WITH gen_tile_input AS (
SELECT "{group_by_column}" AS col, "{geom_column}" AS geom FROM {src}
WHERE "{geom_column}" &&
ST_TileEnvelope($1::int, $2::int, $3::int, margin => {margin})
),
buffered AS (
SELECT col, ST_Buffer(geom, {buffer_size}) AS geom
FROM gen_tile_input
),
merged AS (
SELECT col, ST_Union(geom) AS geom
FROM buffered GROUP BY col
),
unbuffered AS (
SELECT col, ST_Buffer(ST_Buffer(geom, -2 * {buffer_size}), {buffer_size}) AS geom
FROM merged
)
INSERT INTO {dest} (x, y, "{group_by_column}", "{geom_column}")
SELECT $2::int, $3::int, col, (ST_Dump(geom)).geom FROM unbuffered
)");
} else {
dbprepare("gen_geoms", R"(
WITH gen_tile_input AS (
SELECT "{geom_column}" AS geom FROM {src}
WHERE "{geom_column}" &&
ST_TileEnvelope($1::int, $2::int, $3::int, margin => {margin})
),
buffered AS (
SELECT ST_Buffer(geom, {buffer_size}) AS geom
FROM gen_tile_input
),
merged AS (
SELECT ST_Union(geom) AS geom
FROM buffered
),
unbuffered AS (
SELECT ST_Buffer(ST_Buffer(geom, -2 * {buffer_size}), {buffer_size}) AS geom
FROM merged
)
INSERT INTO {dest} (x, y, "{geom_column}")
SELECT $2::int, $3::int, (ST_Dump(geom)).geom FROM unbuffered
)");
}
}
void gen_tile_vector_union_t::process(tile_t const &tile)
{
connection().exec("BEGIN");
delete_existing(tile);
log_gen("Generalize...");
timer(m_timer_simplify).start();
auto const result = connection().exec_prepared("gen_geoms", tile.zoom(),
tile.x(), tile.y());
connection().exec("COMMIT");
timer(m_timer_simplify).stop();
log_gen("Inserted {} generalized polygons", result.affected_rows());
}
void gen_tile_vector_union_t::post()
{
if (!append_mode()) {
dbexec("ANALYZE {dest}");
}
}