mapnik/test/unit/geometry/geometry.cpp

54 lines
1.9 KiB
C++
Raw Normal View History

2015-02-24 07:45:11 +00:00
#include "catch.hpp"
#include <mapnik/geometry.hpp>
2015-02-24 07:45:11 +00:00
#include <mapnik/util/file_io.hpp>
#include <mapnik/json/geometry_parser.hpp>
2015-03-18 11:43:05 +00:00
#include <mapnik/util/geometry_to_geojson.hpp>
2015-02-24 07:45:11 +00:00
2022-01-26 22:25:53 +00:00
TEST_CASE("geometry")
{
SECTION("json point")
{
mapnik::util::file input("./test/data/json/point1.json");
REQUIRE(input);
mapnik::geometry::geometry<double> geom;
REQUIRE(input.data());
std::string json_string(input.data().get(), input.size());
REQUIRE(mapnik::json::from_geojson(json_string, geom));
REQUIRE(geom.is<mapnik::geometry::point<double>>());
auto const& point = mapnik::util::get<mapnik::geometry::point<double>>(geom);
REQUIRE(point.x == 30);
REQUIRE(point.y == 10);
std::string new_json;
REQUIRE(mapnik::util::to_geojson(new_json, geom));
}
2015-02-24 07:45:11 +00:00
2022-01-26 22:25:53 +00:00
SECTION("json point reversed")
{
mapnik::util::file input("./test/data/json/point2.json");
REQUIRE(input);
mapnik::geometry::geometry<double> geom;
REQUIRE(input.data());
std::string json_string(input.data().get(), input.size());
REQUIRE(mapnik::json::from_geojson(json_string, geom));
REQUIRE(geom.is<mapnik::geometry::point<double>>());
auto const& point = mapnik::util::get<mapnik::geometry::point<double>>(geom);
REQUIRE(point.x == 30);
REQUIRE(point.y == 10);
}
2015-12-14 11:39:42 +00:00
2022-01-26 22:25:53 +00:00
SECTION("json point reversed + extra attributes")
{
mapnik::util::file input("./test/data/json/point3.json");
REQUIRE(input);
mapnik::geometry::geometry<double> geom;
REQUIRE(input.data());
std::string json_string(input.data().get(), input.size());
REQUIRE(mapnik::json::from_geojson(json_string, geom));
REQUIRE(geom.is<mapnik::geometry::point<double>>());
auto const& point = mapnik::util::get<mapnik::geometry::point<double>>(geom);
REQUIRE(point.x == 30);
REQUIRE(point.y == 10);
}
2015-02-24 07:45:11 +00:00
}