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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2025 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include <catch.hpp>
#include "common-import.hpp"
#include "common-options.hpp"
namespace {
testing::db::import_t db;
char const *const conf_file = "test_output_flex_uni.lua";
} // anonymous namespace
struct options_slim_default
{
static options_t options()
{
return testing::opt_t().slim().flex(conf_file);
}
};
struct options_slim_expire
{
static options_t options()
{
options_t o = options_slim_default::options();
o.expire_tiles_zoom = 10;
return o;
}
};
TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
options_slim_expire)
{
options_t options = TestType::options();
// import a node...
REQUIRE_NOTHROW(db.run_import(options, "n10 v1 dV x10 y10\n"));
auto conn = db.db().connect();
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
// give the node a tag...
options.append = true;
REQUIRE_NOTHROW(
db.run_import(options, "n10 v2 dV x10 y10 Tamenity=restaurant\n"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2",
"x_type = 'N' AND x_id = 10 AND "
"tags->'amenity' = 'restaurant'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = 10 AND "
"tags->'amenity' = 'restaurant'"));
SECTION("remove the tag from node")
{
REQUIRE_NOTHROW(db.run_import(options, "n10 v3 dV x10 y10\n"));
}
SECTION("delete the node")
{
REQUIRE_NOTHROW(db.run_import(options, "n10 v3 dD\n"));
}
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
}
TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
options_slim_expire)
{
options_t options = TestType::options();
// import a simple way...
REQUIRE_NOTHROW(db.run_import(options,
"n10 v1 dV x10.0 y10.1\n"
"n11 v1 dV x10.1 y10.2\n"
"w20 v1 dV Thighway=primary Nn10,n11\n"));
auto conn = db.db().connect();
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2", "x_type = 'W'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id < 0 AND the_id > -1e17"));
REQUIRE(1 ==
conn.get_count(
"osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'highway' = 'primary' "
"AND ST_NumPoints(geom) = 2"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'highway' = 'primary' "
"AND ST_NumPoints(geom) = 2"));
// now change the way itself...
options.append = true;
REQUIRE_NOTHROW(
db.run_import(options, "w20 v2 dV Thighway=secondary Nn10,n11\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2", "x_type = 'W'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id < 0 AND the_id > -1e17"));
REQUIRE(1 ==
conn.get_count("osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'highway' = "
"'secondary' AND ST_NumPoints(geom) = 2"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'highway' = "
"'secondary' AND ST_NumPoints(geom) = 2"));
// now change a node in the way...
REQUIRE_NOTHROW(db.run_import(options, "n10 v2 dV x10.0 y10.3\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2", "x_type = 'W'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id < 0 AND the_id > -1e17"));
REQUIRE(1 ==
conn.get_count("osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'highway' = "
"'secondary' AND ST_NumPoints(geom) = 2"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'highway' = "
"'secondary' AND ST_NumPoints(geom) = 2"));
// now add a node to the way...
REQUIRE_NOTHROW(db.run_import(
options, "n12 v1 dV x10.2 y10.1\n"
"w20 v3 dV Thighway=residential Nn10,n11,n12\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2", "x_type = 'W'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id < 0 AND the_id > -1e17"));
REQUIRE(1 ==
conn.get_count("osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'highway' = "
"'residential' AND ST_NumPoints(geom) = 3"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'highway' = "
"'residential' AND ST_NumPoints(geom) = 3"));
// now delete the way...
REQUIRE_NOTHROW(db.run_import(options, "w20 v4 dD\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'W'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id < 0 AND the_id > -1e17"));
}
TEMPLATE_TEST_CASE("ways as linestrings and polygons", "", options_slim_default,
options_slim_expire)
{
options_t options = TestType::options();
// import a simple way...
REQUIRE_NOTHROW(db.run_import(
options, "n10 v1 dV x10.0 y10.0\n"
"n11 v1 dV x10.0 y10.2\n"
"n12 v1 dV x10.2 y10.2\n"
"n13 v1 dV x10.2 y10.0\n"
"w20 v1 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n"));
auto conn = db.db().connect();
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type != 'W'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id > 0 AND the_id < -1e17"));
REQUIRE(1 ==
conn.get_count(
"osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND "
"tags->'highway' = 'secondary' AND "
"ST_GeometryType(geom) = 'ST_LineString'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND "
"tags->'highway' = 'secondary' AND "
"ST_GeometryType(geom) = 'ST_LineString'"));
// now change the way tags...
options.append = true;
REQUIRE_NOTHROW(db.run_import(
options, "w20 v2 dV Thighway=secondary Nn10,n11,n12,n13,n10\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type != 'W'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id > 0 AND the_id < -1e17"));
REQUIRE(0 ==
conn.get_count(
"osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND "
"tags->'highway' = 'secondary' AND "
"ST_GeometryType(geom) = 'ST_LineString'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND "
"tags->'highway' = 'secondary' AND "
"ST_GeometryType(geom) = 'ST_LineString'"));
// now remove a node from the way...
REQUIRE_NOTHROW(db.run_import(
options, "w20 v3 dV Thighway=secondary Nn10,n11,n12,n13\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type != 'W'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id > 0 AND the_id < -1e17"));
REQUIRE(0 ==
conn.get_count(
"osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND "
"tags->'highway' = 'secondary' AND "
"ST_GeometryType(geom) = 'ST_LineString'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND "
"tags->'highway' = 'secondary' AND "
"ST_GeometryType(geom) = 'ST_LineString'"));
// now change the tag back to an area tag (but the way is not closed)...
REQUIRE_NOTHROW(
db.run_import(options, "w20 v4 dV Tbuilding=yes Nn10,n11,n12,n13\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1"));
// now close the way again
REQUIRE_NOTHROW(db.run_import(
options, "w20 v5 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type != 'W'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id > 0 AND the_id < -1e17"));
REQUIRE(1 ==
conn.get_count(
"osm2pgsql_test_data2",
"x_type = 'W' AND x_id = 20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1",
"the_id = -20 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
}
TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
options_slim_expire)
{
options_t options = TestType::options();
// import a simple multipolygon relation...
REQUIRE_NOTHROW(db.run_import(
options, "n10 v1 dV x10.0 y10.0\n"
"n11 v1 dV x10.0 y10.2\n"
"n12 v1 dV x10.2 y10.2\n"
"n13 v1 dV x10.2 y10.0\n"
"w20 v1 dV Nn10,n11,n12,n13,n10\n"
"r30 v1 dV Ttype=multipolygon,building=yes Mw20@\n"));
auto conn = db.db().connect();
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'W'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id < 0 AND the_id > -1e17"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2", "x_type = 'R'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1", "the_id < -1e17"));
REQUIRE(1 ==
conn.get_count(
"osm2pgsql_test_data2",
"x_type = 'R' AND x_id = 30 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(1 == conn.get_count(
"osm2pgsql_test_data1",
"the_id = (-30 - 1e17) AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
// change tags on that relation...
options.append = true;
REQUIRE_NOTHROW(db.run_import(
options,
"r30 v2 dV Ttype=multipolygon,building=yes,name=Shed Mw20@\n"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'N'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1", "the_id > 0"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2", "x_type = 'W'"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1",
"the_id < 0 AND the_id > -1e17"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data2", "x_type = 'R'"));
REQUIRE(1 == conn.get_count("osm2pgsql_test_data1", "the_id < -1e17"));
REQUIRE(1 ==
conn.get_count(
"osm2pgsql_test_data2",
"x_type = 'R' AND x_id = 30 AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
REQUIRE(1 == conn.get_count(
"osm2pgsql_test_data1",
"the_id = (-30 - 1e17) AND tags->'building' = 'yes' AND "
"ST_GeometryType(geom) = 'ST_Polygon'"));
SECTION("remove relation")
{
REQUIRE_NOTHROW(db.run_import(options, "r30 v3 dD\n"));
}
SECTION("remove multipolygon tag")
{
REQUIRE_NOTHROW(db.run_import(
options, "r30 v3 dV Tbuilding=yes,name=Shed Mw20@\n"));
}
REQUIRE(0 == conn.get_count("osm2pgsql_test_data2"));
REQUIRE(0 == conn.get_count("osm2pgsql_test_data1"));
}
|