Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/geom-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,14 @@ namespace {

double spherical_area(polygon_t const &geom)
{
boost::geometry::strategy::area::spherical<> const spherical_earth{
6371008.8};

using sph_point = boost::geometry::model::point<
double, 2,
boost::geometry::cs::spherical_equatorial<boost::geometry::degree>>;
double, 2, boost::geometry::cs::geographic<boost::geometry::degree>>;

boost::geometry::model::polygon<sph_point> sph_geom;
boost::geometry::convert(geom, sph_geom);
return boost::geometry::area(sph_geom, spherical_earth);
return boost::geometry::area(sph_geom,
boost::geometry::strategy::area::geographic<
boost::geometry::strategy::vincenty>{});
}

} // anonymous namespace
Expand Down
2 changes: 2 additions & 0 deletions tests/test-geom-linestrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TEST_CASE("line geometry", "[NoDB]")
REQUIRE(dimension(geom) == 1);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(1.41421));
REQUIRE(geometry_type(geom) == "LINESTRING");
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.5, 1.5}});
Expand Down Expand Up @@ -87,6 +88,7 @@ TEST_CASE("create_linestring from OSM data", "[NoDB]")
REQUIRE(dimension(geom) == 1);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(1.41421));
REQUIRE(geom.get<geom::linestring_t>() ==
geom::linestring_t{{1, 1}, {2, 2}});
Expand Down
3 changes: 3 additions & 0 deletions tests/test-geom-multilinestrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TEST_CASE("create_multilinestring with single line", "[NoDB]")
REQUIRE(dimension(geom) == 1);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(1.0));
auto const &ml = geom.get<geom::multilinestring_t>();
REQUIRE(ml.num_geometries() == 1);
Expand All @@ -60,6 +61,7 @@ TEST_CASE("create_multilinestring with single line and no force_multi",
REQUIRE(geometry_type(geom) == "LINESTRING");
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(1.0));
auto const &l = geom.get<geom::linestring_t>();
REQUIRE(l.num_geometries() == 1);
Expand Down Expand Up @@ -93,6 +95,7 @@ TEST_CASE(
REQUIRE(geometry_type(geom) == "LINESTRING");
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(1.0));
auto const &l = geom.get<geom::linestring_t>();
REQUIRE(l.num_geometries() == 1);
Expand Down
4 changes: 4 additions & 0 deletions tests/test-geom-multipoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ TEST_CASE("multipoint_t with a single point", "[NoDB]")
REQUIRE(dimension(geom) == 0);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(reverse(geom) == geom);
REQUIRE(centroid(geom) == geom::geometry_t{point});
Expand All @@ -55,6 +56,7 @@ TEST_CASE("multipoint_t with several points", "[NoDB]")
REQUIRE(geometry_type(geom) == "MULTIPOINT");
REQUIRE(num_geometries(geom) == 3);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(reverse(geom) == geom);
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{2, 1}});
Expand Down Expand Up @@ -92,6 +94,7 @@ TEST_CASE("create_multipoint from OSM data", "[NoDB]")
REQUIRE(c[3] == geom::point_t{3, 1});

REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{2, 1}});
}
Expand All @@ -118,6 +121,7 @@ TEST_CASE("create_multipoint from OSM data with only a single point", "[NoDB]")
REQUIRE(num_geometries(geom) == 1);
REQUIRE(geom.get<geom::point_t>() == geom::point_t{1, 0});
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1, 0}});
}
4 changes: 2 additions & 2 deletions tests/test-geom-multipolygons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST_CASE("multipolygon geometry with single outer, no inner", "[NoDB]")
REQUIRE(dimension(geom) == 2);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(1.0));
REQUIRE(spherical_area(geom) == Approx(12364031798.5));
REQUIRE(spherical_area(geom) == Approx(12308778361.469454).epsilon(0.00001));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{0.5, 0.5}});
REQUIRE(geometry_n(geom, 1) ==
Expand Down Expand Up @@ -59,7 +59,7 @@ TEST_CASE("multipolygon geometry with two polygons", "[NoDB]")
REQUIRE(dimension(geom) == 2);
REQUIRE(num_geometries(geom) == 2);
REQUIRE(area(geom) == Approx(9.0));
REQUIRE(spherical_area(geom) == Approx(111106540105.7));
REQUIRE(spherical_area(geom) == Approx(110615268622.783).epsilon(0.00001));
REQUIRE(length(geom) == Approx(0.0));
}

Expand Down
3 changes: 2 additions & 1 deletion tests/test-geom-null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ TEST_CASE("null geometry", "[NoDB]")

REQUIRE(dimension(geom) == 0);
REQUIRE(num_geometries(geom) == 0);
REQUIRE(area(geom) == 0.0);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(geometry_type(geom) == "NULL");
REQUIRE(centroid(geom).is_null());
Expand Down
1 change: 1 addition & 0 deletions tests/test-geom-points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ TEST_CASE("create_point from OSM data", "[NoDB]")
REQUIRE(dimension(geom) == 0);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(0.0));
REQUIRE(spherical_area(geom) == Approx(0.0));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.1, 2.2}});
REQUIRE(geometry_n(geom, 1) == geom);
Expand Down
6 changes: 3 additions & 3 deletions tests/test-geom-polygons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TEST_CASE("polygon geometry without inner", "[NoDB]")
REQUIRE(dimension(geom) == 2);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(1.0));
REQUIRE(spherical_area(geom) == Approx(12364031798.5));
REQUIRE(spherical_area(geom) == Approx(12308778361.469454).epsilon(0.00001));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(geometry_type(geom) == "POLYGON");
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{0.5, 0.5}});
Expand All @@ -41,7 +41,7 @@ TEST_CASE("polygon geometry without inner (reverse)", "[NoDB]")
REQUIRE(dimension(geom) == 2);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(1.0));
REQUIRE(spherical_area(geom) == Approx(12364031798.5));
REQUIRE(spherical_area(geom) == Approx(12308778361.469454).epsilon(0.00001));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(geometry_type(geom) == "POLYGON");
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{0.5, 0.5}});
Expand All @@ -65,7 +65,7 @@ TEST_CASE("geom::polygon_t", "[NoDB]")
REQUIRE(dimension(geom) == 2);
REQUIRE(num_geometries(geom) == 1);
REQUIRE(area(geom) == Approx(8.0));
REQUIRE(spherical_area(geom) == Approx(98893356298.4));
REQUIRE(spherical_area(geom) == Approx(98452667625.52686).epsilon(0.00001));
REQUIRE(length(geom) == Approx(0.0));
REQUIRE(geometry_type(geom) == "POLYGON");
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.5, 1.5}});
Expand Down
Loading