-
-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathgen-tile.cpp
More file actions
73 lines (60 loc) · 1.87 KB
/
Copy pathgen-tile.cpp
File metadata and controls
73 lines (60 loc) · 1.87 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
/**
* 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.hpp"
#include "logging.hpp"
#include "params.hpp"
#include "pgsql.hpp"
#include "tile.hpp"
#include <cstdlib>
gen_tile_t::gen_tile_t(pg_conn_t *connection, bool append, params_t *params)
: gen_base_t(connection, append, params), m_timer_delete(add_timer("delete")),
m_zoom(parse_zoom())
{
m_with_group_by = !get_params().get_identifier("group_by_column").empty();
if (append_mode()) {
dbprepare("del_geoms",
"DELETE FROM {dest} WHERE x=$1::int AND y=$2::int");
}
}
uint32_t gen_tile_t::parse_zoom()
{
if (!get_params().has("zoom")) {
throw fmt_error("Missing 'zoom' parameter in generalizer{}.",
context());
}
auto const pval = get_params().get("zoom");
if (!std::holds_alternative<int64_t>(pval)) {
throw fmt_error(
"Invalid value '{}' for 'zoom' parameter in generalizer{}.",
get_params().get_string("zoom"), context());
}
auto const value = std::get<int64_t>(pval);
if (value < 0 || value > 20) {
throw fmt_error(
"Invalid value '{}' for 'zoom' parameter in generalizer{}.", value,
context());
}
return static_cast<uint32_t>(value);
}
void gen_tile_t::delete_existing(tile_t const &tile)
{
if (!append_mode()) {
return;
}
if (debug()) {
log_gen("Delete geometries from destination table...");
}
timer(m_timer_delete).start();
auto const result =
connection().exec_prepared("del_geoms", tile.x(), tile.y());
timer(m_timer_delete).stop();
if (debug()) {
log_gen("Deleted {} rows.", result.affected_rows());
}
}