[buffer] add testcases for (multi) polygon buffer for geographic

This commit is contained in:
Barend Gehrels 2022-10-05 12:29:20 +02:00
parent 475684732c
commit ba23318b1d
6 changed files with 367 additions and 60 deletions

View File

@ -14,30 +14,32 @@ project boost-geometry-algorithms-buffer
test-suite boost-geometry-algorithms-buffer
:
[ run buffer.cpp : : : : algorithms_buffer ]
[ run buffer_gc.cpp : : : : algorithms_buffer_gc ]
[ run buffer_with_strategies.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_with_strategies ]
[ run buffer_piece_border.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_piece_border ]
[ run buffer_point.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_point ]
[ run buffer_point_geo.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_point_geo ]
[ run buffer_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring ]
[ run buffer_linestring_geo.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring_geo ]
[ run buffer_ring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_ring ]
[ run buffer_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_polygon ]
[ run buffer_multi_point.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_point ]
[ run buffer_multi_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_linestring ]
[ run buffer.cpp : : : : algorithms_buffer ]
[ run buffer_gc.cpp : : : : algorithms_buffer_gc ]
[ run buffer_with_strategies.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_with_strategies ]
[ run buffer_piece_border.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_piece_border ]
[ run buffer_point.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_point ]
[ run buffer_point_geo.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_point_geo ]
[ run buffer_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring ]
[ run buffer_linestring_geo.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring_geo ]
[ run buffer_ring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_ring ]
[ run buffer_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_polygon ]
[ run buffer_polygon_geo.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_polygon_geo ]
[ run buffer_multi_point.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_point ]
[ run buffer_multi_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_linestring ]
[ run buffer_multi_linestring_geo.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_linestring_geo ]
[ run buffer_multi_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_polygon ]
[ run buffer_linestring_aimes.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring_aimes ]
[ run buffer_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_linestring_alternative ]
[ run buffer_multi_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_multi_linestring_alternative ]
[ run buffer_ring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_ring_alternative ]
[ run buffer_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_polygon_alternative ]
[ run buffer_multi_point.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_multi_point_alternative ]
[ run buffer_multi_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_multi_polygon_alternative ]
[ run buffer_linestring_aimes.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_linestring_aimes_alternative ]
[ run buffer_multi_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_polygon ]
[ run buffer_multi_polygon_geo.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_multi_polygon_geo ]
[ run buffer_linestring_aimes.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring_aimes ]
[ run buffer_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_linestring_alternative ]
[ run buffer_multi_linestring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_multi_linestring_alternative ]
[ run buffer_ring.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_ring_alternative ]
[ run buffer_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_polygon_alternative ]
[ run buffer_multi_point.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_multi_point_alternative ]
[ run buffer_multi_polygon.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_multi_polygon_alternative ]
[ run buffer_linestring_aimes.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_linestring_aimes_alternative ]
# Uncomment next lines if you want to test this manually; requires access to data/ folder
# [ run buffer_countries.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_countries ]
# [ run buffer_countries.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_countries_alternative ]
# [ run buffer_countries.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_countries ]
# [ run buffer_countries.cpp : : : <define>BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE <define>BOOST_GEOMETRY_ROBUSTNESS_ALTERNATIVE : algorithms_buffer_countries_alternative ]
;

View File

@ -8,35 +8,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_buffer.hpp"
template <typename MultiPolygon>
std::string read_from_file(std::string const& filename)
{
MultiPolygon mp;
std::ifstream in(filename.c_str());
while (in.good())
{
std::string line;
std::getline(in, line);
if (! line.empty())
{
typename boost::range_value<MultiPolygon>::type pol;
bg::read_wkt(line, pol);
mp.push_back(pol);
}
}
std::ostringstream out;
if (! mp.empty())
{
out << std::fixed << std::setprecision(19) << bg::wkt(mp);
}
BOOST_CHECK(! out.str().empty());
return out.str();
}
#include "read_from_wkt_file.hpp"
/*
@ -144,15 +116,15 @@ void test_one(std::string const& caseid, std::string const& wkt, double expected
template <bool Clockwise, typename P>
void test_all()
{
typedef bg::model::polygon<P, Clockwise> pt;
typedef bg::model::multi_polygon<pt> mpt;
using pt = bg::model::polygon<P, Clockwise>;
using mpt = bg::model::multi_polygon<pt>;
std::string base_folder = "data/";
std::string gr = read_from_file<mpt>(base_folder + "gr.wkt");
std::string it = read_from_file<mpt>(base_folder + "it.wkt");
std::string nl = read_from_file<mpt>(base_folder + "nl.wkt");
std::string no = read_from_file<mpt>(base_folder + "no.wkt");
std::string uk = read_from_file<mpt>(base_folder + "uk.wkt");
const std::string base_folder = "data/";
const std::string gr = read_from_wkt_file<mpt>(base_folder + "gr.wkt");
const std::string it = read_from_wkt_file<mpt>(base_folder + "it.wkt");
const std::string nl = read_from_wkt_file<mpt>(base_folder + "nl.wkt");
const std::string no = read_from_wkt_file<mpt>(base_folder + "no.wkt");
const std::string uk = read_from_wkt_file<mpt>(base_folder + "uk.wkt");
test_one<mpt, pt>("gr10", gr, 336279815682, 10);
test_one<mpt, pt>("gr20", gr, 442317491749, 20);

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,75 @@
// Boost.Geometry
// Unit Test
// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_buffer_geo.hpp"
// Testcase "simplex" is just simple (here non-closed) polygon.
static std::string const simplex = "POLYGON((10.4006587 63.4377982,10.4050904 63.4395993,10.4074994 63.4382527))";
// Testcase "Harbour" with several concave parts.
static std::string const harbour = "POLYGON((10.391199 63.436984,10.399588 63.440751,10.401838 63.441614,10.403849 63.444319,10.407099 63.443819,10.406201 63.441410,10.408428 63.441614,10.410235 63.443898,10.414224 63.444932,10.406201 63.435103,10.400019 63.435864,10.392565 63.435194,10.390452 63.434069,10.390258 63.435398,10.391156 63.435717,10.391474 63.436523,10.391838 63.435819,10.400974 63.439285,10.399258 63.440171,10.391319 63.436945))";
// Testcase "Nairobi" near the equator to verify with the QGis measurement tool if the buffer distance is right.
static std::string const nairobi = "POLYGON((36.8294584 -1.3193328,36.8298078 -1.3176255,36.8323390 -1.3181254,36.8320209 -1.3198413))";
template <typename Formula, bool Clockwise, typename PointType>
void test_geometry()
{
using polygon = bg::model::polygon<PointType, Clockwise, true>;
// Because areas can change significantly when another formula is used,
// use a high tolerance.
int const points_per_circle = 36;
ut_settings settings(0.25);
bg::strategies::buffer::geographic<Formula> strategy;
bg::strategy::buffer::geographic_side_straight<Formula> side;
bg::strategy::buffer::geographic_join_miter<Formula> join_miter;
bg::strategy::buffer::geographic_join_round<Formula> join_round(points_per_circle);
bg::strategy::buffer::geographic_point_circle<Formula> circle(points_per_circle);
bg::strategy::buffer::end_flat end_flat;
test_one_geo<polygon, polygon>("simplex_5_m", simplex, strategy, side, circle, join_miter, end_flat, 33015.0, 5.0, settings);
test_one_geo<polygon, polygon>("simplex_5_r", simplex, strategy, side, circle, join_round, end_flat, 32940.0, 5.0, settings);
test_one_geo<polygon, polygon>("harbour_5_m", harbour, strategy, side, circle, join_miter, end_flat, 545015.0, 5.0, settings);
test_one_geo<polygon, polygon>("harbour_5_r", harbour, strategy, side, circle, join_round, end_flat, 544915.0, 5.0, settings);
test_one_geo<polygon, polygon>("harbour_25_m", harbour, strategy, side, circle, join_miter, end_flat, 664343.0, 25.0, settings);
test_one_geo<polygon, polygon>("harbour_25_r", harbour, strategy, side, circle, join_round, end_flat, 662205.0, 25.0, settings);
test_one_geo<polygon, polygon>("harbour_50_m", harbour, strategy, side, circle, join_miter, end_flat, 818290.0, 50.0, settings);
test_one_geo<polygon, polygon>("harbour_50_r", harbour, strategy, side, circle, join_round, end_flat, 805854.0, 50.0, settings);
test_one_geo<polygon, polygon>("harbour_75_m", harbour, strategy, side, circle, join_miter, end_flat, 963064.0, 75.0, settings);
test_one_geo<polygon, polygon>("harbour_75_r", harbour, strategy, side, circle, join_round, end_flat, 932937.0, 75.0, settings);
test_one_geo<polygon, polygon>("harbour_30n_m", harbour, strategy, side, circle, join_miter, end_flat, 370066.0, -30.0, settings);
test_one_geo<polygon, polygon>("harbour_30n_r", harbour, strategy, side, circle, join_round, end_flat, 371540.0, -30.0, settings);
test_one_geo<polygon, polygon>("harbour_80n_m", harbour, strategy, side, circle, join_miter, end_flat, 185494.0, -80.0, settings);
test_one_geo<polygon, polygon>("harbour_80n_r", harbour, strategy, side, circle, join_round, end_flat, 190110.0, -80.0, settings);
test_one_geo<polygon, polygon>("nairobi_50_m", nairobi, strategy, side, circle, join_miter, end_flat, 113889.0, 50.0, settings);
test_one_geo<polygon, polygon>("nairobi_50_r", nairobi, strategy, side, circle, join_round, end_flat, 111707.0, 50.0, settings);
}
int test_main(int, char* [])
{
BoostGeometryWriteTestConfiguration();
test_geometry<bg::strategy::andoyer, true, bg::model::point<default_test_type, 2, bg::cs::geographic<bg::degree> > >();
#if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
test_geometry<bg::strategy::thomas, true, bg::model::point<default_test_type, 2, bg::cs::geographic<bg::degree> > >();
test_geometry<bg::strategy::andoyer, true, bg::model::point<long double, 2, bg::cs::geographic<bg::degree> > >();
#endif
return 0;
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,46 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014-2022 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_TEST_READ_FROM_WKT_FILE_HPP
#define BOOST_GEOMETRY_TEST_READ_FROM_WKT_FILE_HPP
#include <boost/geometry/io/wkt/wkt.hpp>
#include <fstream>
#include <string>
// Reads all geometries from WKT file and return it as one big multi polygon WKT
template <typename MultiPolygon>
inline std::string read_from_wkt_file(std::string const& filename)
{
MultiPolygon mp;
std::ifstream in(filename.c_str());
while (in.good())
{
std::string line;
std::getline(in, line);
if (! line.empty() && line.substr(0, 1) != "#")
{
typename boost::range_value<MultiPolygon>::type geometry;
bg::read_wkt(line, geometry);
mp.push_back(geometry);
}
}
std::ostringstream out;
if (! mp.empty())
{
out << std::fixed << std::setprecision(20) << bg::wkt(mp);
}
BOOST_CHECK(! out.str().empty());
return out.str();
}
#endif