File: geometry.cpp

package info (click to toggle)
mapnik 4.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 18,548 kB
  • sloc: cpp: 163,861; python: 1,190; sh: 690; xml: 161; makefile: 123; perl: 28; lisp: 13
file content (53 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "catch.hpp"

#include <mapnik/geometry.hpp>
#include <mapnik/util/file_io.hpp>
#include <mapnik/json/geometry_parser.hpp>
#include <mapnik/util/geometry_to_geojson.hpp>

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));
    }

    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);
    }

    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);
    }
}