2015-02-24 08:45:11 +01:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
2015-03-24 13:32:05 +01:00
|
|
|
#include <mapnik/geometry.hpp>
|
2015-02-24 08:45:11 +01:00
|
|
|
#include <mapnik/util/fs.hpp>
|
|
|
|
#include <mapnik/util/file_io.hpp>
|
|
|
|
#include <mapnik/json/geometry_parser.hpp>
|
2015-03-18 12:43:05 +01:00
|
|
|
#include <mapnik/util/geometry_to_geojson.hpp>
|
2015-02-24 08:45:11 +01:00
|
|
|
|
|
|
|
TEST_CASE("geometry") {
|
|
|
|
|
2015-02-24 08:52:54 +01:00
|
|
|
SECTION("json point") {
|
2015-02-24 08:45:11 +01:00
|
|
|
mapnik::util::file input("./tests/data/json/fixtures/point1.json");
|
|
|
|
auto json = input.data();
|
2015-03-24 14:21:28 +01:00
|
|
|
mapnik::geometry::geometry geom;
|
2015-02-24 08:45:11 +01:00
|
|
|
std::string json_string(json.get());
|
2015-03-18 12:43:05 +01:00
|
|
|
REQUIRE( mapnik::json::from_geojson(json_string, geom) );
|
2015-03-24 14:21:28 +01:00
|
|
|
REQUIRE( geom.is<mapnik::geometry::point>() );
|
|
|
|
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom);
|
2015-02-24 08:52:54 +01:00
|
|
|
REQUIRE( point.x == 30 );
|
|
|
|
REQUIRE( point.y == 10 );
|
|
|
|
std::string new_json;
|
2015-03-18 12:43:05 +01:00
|
|
|
REQUIRE( mapnik::util::to_geojson(new_json, geom) );
|
2015-02-24 08:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("json point reversed") {
|
|
|
|
mapnik::util::file input("./tests/data/json/fixtures/point2.json");
|
|
|
|
auto json = input.data();
|
2015-03-24 14:21:28 +01:00
|
|
|
mapnik::geometry::geometry geom;
|
2015-02-24 08:52:54 +01:00
|
|
|
std::string json_string(json.get());
|
|
|
|
REQUIRE( mapnik::json::from_geojson(json_string,geom) );
|
2015-03-24 14:21:28 +01:00
|
|
|
REQUIRE( geom.is<mapnik::geometry::point>() );
|
|
|
|
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom);
|
2015-02-24 08:52:54 +01:00
|
|
|
REQUIRE( point.x == 30 );
|
|
|
|
REQUIRE( point.y == 10 );
|
2015-02-24 08:45:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|