|
| 1 | +/** |
| 2 | + * SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | + * |
| 4 | + * This file is part of osm2pgsql (https://osm2pgsql.org/). |
| 5 | + * |
| 6 | + * Copyright (C) 2006-2022 by the osm2pgsql developer community. |
| 7 | + * For a full list of authors see the git log. |
| 8 | + */ |
| 9 | + |
| 10 | +#include <catch.hpp> |
| 11 | + |
| 12 | +#include "common-buffer.hpp" |
| 13 | + |
| 14 | +#include "geom-from-osm.hpp" |
| 15 | +#include "geom-functions.hpp" |
| 16 | +#include "geom.hpp" |
| 17 | + |
| 18 | +TEST_CASE("geometry collection with point", "[NoDB]") |
| 19 | +{ |
| 20 | + geom::geometry_t geom{geom::collection_t{}}; |
| 21 | + auto &c = geom.get<geom::collection_t>(); |
| 22 | + |
| 23 | + c.add_geometry(geom::geometry_t{geom::point_t{1, 1}}); |
| 24 | + |
| 25 | + REQUIRE(geometry_type(geom) == "GEOMETRYCOLLECTION"); |
| 26 | + REQUIRE(num_geometries(geom) == 1); |
| 27 | + REQUIRE(area(geom) == Approx(0.0)); |
| 28 | + REQUIRE_THROWS(centroid(geom)); |
| 29 | +} |
| 30 | + |
| 31 | +TEST_CASE("geometry collection with several geometries", "[NoDB]") |
| 32 | +{ |
| 33 | + geom::geometry_t geom{geom::collection_t{}}; |
| 34 | + auto &c = geom.get<geom::collection_t>(); |
| 35 | + |
| 36 | + c.add_geometry(geom::geometry_t{geom::point_t{1, 1}}); |
| 37 | + c.add_geometry(geom::geometry_t{geom::linestring_t{{1, 1}, {2, 2}}}); |
| 38 | + c.add_geometry(geom::geometry_t{geom::point_t{2, 2}}); |
| 39 | + |
| 40 | + REQUIRE(geometry_type(geom) == "GEOMETRYCOLLECTION"); |
| 41 | + REQUIRE(num_geometries(geom) == 3); |
| 42 | + REQUIRE(area(geom) == Approx(0.0)); |
| 43 | + REQUIRE_THROWS(centroid(geom)); |
| 44 | +} |
| 45 | + |
| 46 | +TEST_CASE("create_collection from OSM data", "[NoDB]") |
| 47 | +{ |
| 48 | + test_buffer_t buffer; |
| 49 | + buffer.add_node("n1 x1 y1"); |
| 50 | + buffer.add_way("w20 Nn1x1y1,n2x2y1,n3x2y2,n4x1y2,n1x1y1"); |
| 51 | + buffer.add_way("w21 Nn5x10y10,n6x10y20"); |
| 52 | + buffer.add_relation("r30 Mw20@"); |
| 53 | + |
| 54 | + auto const geom = geom::create_collection(buffer.buffer()); |
| 55 | + |
| 56 | + REQUIRE(geometry_type(geom) == "GEOMETRYCOLLECTION"); |
| 57 | + REQUIRE(num_geometries(geom) == 3); |
| 58 | + |
| 59 | + auto const &c = geom.get<geom::collection_t>(); |
| 60 | + REQUIRE(c[0] == geom::geometry_t{geom::point_t{1, 1}}); |
| 61 | + REQUIRE(c[1] == geom::geometry_t{geom::linestring_t{ |
| 62 | + {1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}); |
| 63 | + REQUIRE(c[2] == geom::geometry_t{geom::linestring_t{{10, 10}, {10, 20}}}); |
| 64 | + |
| 65 | + REQUIRE(area(geom) == Approx(0.0)); |
| 66 | + REQUIRE_THROWS(centroid(geom)); |
| 67 | +} |
| 68 | + |
| 69 | +TEST_CASE("create_collection from no OSM data returns null geometry", "[NoDB]") |
| 70 | +{ |
| 71 | + test_buffer_t buffer; |
| 72 | + buffer.add_relation("r30 Mw20@"); |
| 73 | + |
| 74 | + auto const geom = geom::create_collection(buffer.buffer()); |
| 75 | + |
| 76 | + REQUIRE(geometry_type(geom) == "NULL"); |
| 77 | + REQUIRE(num_geometries(geom) == 0); |
| 78 | +} |
0 commit comments