File: geometry.cpp

package info (click to toggle)
mapnik 3.0.12%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,084 kB
  • ctags: 18,454
  • sloc: cpp: 142,516; python: 1,416; sh: 769; makefile: 170; xml: 140; lisp: 13
file content (51 lines) | stat: -rw-r--r-- 1,863 bytes parent folder | download | duplicates (4)
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
#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 );
}

}