2015-02-24 07:45:11 +00:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
2015-03-24 12:32:05 +00:00
|
|
|
#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
|
|
|
|
|
|
|
TEST_CASE("geometry") {
|
|
|
|
|
2015-02-24 07:52:54 +00:00
|
|
|
SECTION("json point") {
|
2015-04-30 13:57:47 +00:00
|
|
|
mapnik::util::file input("./test/data/json/point1.json");
|
2015-04-26 18:23:02 +00:00
|
|
|
REQUIRE( input.open() );
|
2015-04-09 20:22:51 +00:00
|
|
|
mapnik::geometry::geometry<double> geom;
|
2015-05-22 08:24:45 +00:00
|
|
|
REQUIRE( input.data() );
|
|
|
|
std::string json_string(input.data().get(), input.size());
|
2015-03-18 11:43:05 +00:00
|
|
|
REQUIRE( mapnik::json::from_geojson(json_string, geom) );
|
2015-04-09 20:22:51 +00:00
|
|
|
REQUIRE( geom.is<mapnik::geometry::point<double> >() );
|
|
|
|
auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom);
|
2015-02-24 07:52:54 +00:00
|
|
|
REQUIRE( point.x == 30 );
|
|
|
|
REQUIRE( point.y == 10 );
|
|
|
|
std::string new_json;
|
2015-03-18 11:43:05 +00:00
|
|
|
REQUIRE( mapnik::util::to_geojson(new_json, geom) );
|
2015-02-24 07:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("json point reversed") {
|
2015-04-30 13:57:47 +00:00
|
|
|
mapnik::util::file input("./test/data/json/point2.json");
|
2015-04-26 18:23:02 +00:00
|
|
|
REQUIRE( input.open() );
|
2015-04-09 20:22:51 +00:00
|
|
|
mapnik::geometry::geometry<double> geom;
|
2015-05-22 08:24:45 +00:00
|
|
|
REQUIRE( input.data() );
|
|
|
|
std::string json_string(input.data().get(), input.size());
|
2015-02-24 07:52:54 +00:00
|
|
|
REQUIRE( mapnik::json::from_geojson(json_string,geom) );
|
2015-04-09 20:22:51 +00:00
|
|
|
REQUIRE( geom.is<mapnik::geometry::point<double> >() );
|
|
|
|
auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom);
|
2015-02-24 07:52:54 +00:00
|
|
|
REQUIRE( point.x == 30 );
|
|
|
|
REQUIRE( point.y == 10 );
|
2015-02-24 07:45:11 +00:00
|
|
|
}
|
|
|
|
|
2015-12-14 11:39:42 +00:00
|
|
|
SECTION("json point reversed + extra attributes") {
|
|
|
|
mapnik::util::file input("./test/data/json/point3.json");
|
|
|
|
REQUIRE( input.open() );
|
|
|
|
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
|
|
|
}
|