[mapnik-vector-tile] 02/15: Imported Upstream version 0.8.2+dfsg

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sat Sep 12 11:06:50 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository mapnik-vector-tile.

commit ac61df0d6736fe061ef2619028b2333f5603e342
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Fri Sep 11 22:55:04 2015 +0200

    Imported Upstream version 0.8.2+dfsg
---
 .travis.yml                            |   4 +
 CHANGELOG.md                           |   4 +
 bench/vtile-transform.cpp              |  76 ++++++++++++++
 bootstrap.sh                           |   2 +-
 gyp/build.gyp                          |  18 +++-
 package.json                           |   2 +-
 scripts/build.sh                       |   2 +
 src/vector_tile_processor.ipp          |   3 +-
 src/vector_tile_strategy.hpp           | 182 +++++++++++++++++++++++++++------
 test/data/poly-lat-invalid-4269.dbf    | Bin 0 -> 77 bytes
 test/data/poly-lat-invalid-4269.prj    |   1 +
 test/data/poly-lat-invalid-4269.shp    | Bin 0 -> 316 bytes
 test/data/poly-lat-invalid-4269.shx    | Bin 0 -> 108 bytes
 test/data/polygon-style.xml            |   7 ++
 test/fixtures/transform-expected-1.png | Bin 0 -> 2374 bytes
 test/geometry_encoding.cpp             |  10 +-
 test/raster_tile.cpp                   |   2 -
 test/test_main.cpp                     |   2 +
 test/vector_tile.cpp                   |  83 ++++++++++++++-
 test/vector_tile_pbf.cpp               |   1 -
 20 files changed, 355 insertions(+), 44 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 165123e..ca0a2ce 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -35,6 +35,10 @@ matrix:
       compiler: clang
       env: JOBS=10 COVERAGE=true BUILDTYPE=Debug
       sudo: false
+    - os: osx
+      compiler: clang
+      env: JOBS=10
+      sudo: false
 
 before_install:
  - source ./bootstrap.sh
diff --git a/CHANGELOG.md b/CHANGELOG.md
index da1f497..0f40bc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Changelog
 
+## 0.8.2
+
+ - Optimized coordinate transform that skips proj4 failures (#116)
+
 ## 0.8.1
 
  - Added `tile_datasource_pbf` - It should be used in places where you need to plug
diff --git a/bench/vtile-transform.cpp b/bench/vtile-transform.cpp
new file mode 100644
index 0000000..01cc25f
--- /dev/null
+++ b/bench/vtile-transform.cpp
@@ -0,0 +1,76 @@
+#include <mapnik/projection.hpp>
+#include <mapnik/geometry_transform.hpp>
+#include <mapnik/util/file_io.hpp>
+#include <mapnik/json/geometry_parser.hpp>
+#include <mapnik/timer.hpp>
+
+#include "vector_tile_strategy.hpp"
+#include "vector_tile_projection.hpp"
+
+/*
+
+# 10000 times
+    no reserve + transform_visitor
+     - 2.77
+
+    with reserve
+     - 1.69
+
+    boost::geometry::transform
+     - 2.3
+
+*/
+
+int main() {
+    mapnik::projection merc("+init=epsg:3857",true);
+    mapnik::proj_transform prj_trans(merc,merc); // no-op
+    unsigned tile_size = 256;
+    mapnik::vector_tile_impl::spherical_mercator merc_tiler(tile_size);
+    double minx,miny,maxx,maxy;
+    merc_tiler.xyz(9664,20435,15,minx,miny,maxx,maxy);
+    mapnik::box2d<double> z15_extent(minx,miny,maxx,maxy);
+    mapnik::view_transform tr(tile_size,tile_size,z15_extent,0,0);
+    std::string geojson_file("./test/data/poly.geojson");
+    mapnik::util::file input(geojson_file);
+    if (!input.open())
+    {
+        throw std::runtime_error("failed to open geojson");
+    }
+    mapnik::geometry::geometry<double> geom;
+    std::string json_string(input.data().get(), input.size());
+    if (!mapnik::json::from_geojson(json_string, geom))
+    {
+        throw std::runtime_error("failed to parse geojson");
+    }
+    mapnik::geometry::correct(geom);
+
+    unsigned count = 0;
+    unsigned count2 = 0;
+    {
+        mapnik::vector_tile_impl::vector_tile_strategy vs(prj_trans, tr, 16);
+        mapnik::progress_timer __stats__(std::clog, "boost::geometry::transform");
+        for (unsigned i=0;i<10000;++i)
+        {
+            mapnik::geometry::geometry<std::int64_t> new_geom = mapnik::geometry::transform<std::int64_t>(geom, vs);
+            auto const& poly = mapnik::util::get<mapnik::geometry::multi_polygon<std::int64_t>>(new_geom);
+            count += poly.size();
+        }
+    }
+    {
+        mapnik::vector_tile_impl::vector_tile_strategy vs(prj_trans, tr, 16);
+        mapnik::progress_timer __stats__(std::clog, "transform_visitor with reserve");
+        mapnik::vector_tile_impl::transform_visitor transit(vs);
+        for (unsigned i=0;i<10000;++i)
+        {
+            mapnik::geometry::geometry<std::int64_t> new_geom = mapnik::util::apply_visitor(transit,geom);        
+            auto const& poly = mapnik::util::get<mapnik::geometry::multi_polygon<std::int64_t>>(new_geom);
+            count2 += poly.size();
+        }
+        if (count != count2)
+        {
+            std::clog << "tests did not run as expected!\n";
+            return -1;
+        }
+    }
+    return 0;
+}
\ No newline at end of file
diff --git a/bootstrap.sh b/bootstrap.sh
index 6e47b2f..d98f431 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -22,7 +22,7 @@ function install() {
 }
 
 function install_mason_deps() {
-    install mapnik 3.0.0-rc3
+    install mapnik latest
     install protobuf 2.6.1
     install freetype 2.5.5
     install harfbuzz 0.9.40
diff --git a/gyp/build.gyp b/gyp/build.gyp
index 42a4b71..5b976bc 100644
--- a/gyp/build.gyp
+++ b/gyp/build.gyp
@@ -131,7 +131,7 @@
       "defines": [
         "<@(common_defines)",
         "MAPNIK_PLUGINDIR=<(MAPNIK_PLUGINDIR)"
-      ], 
+      ],
       "sources": [
         "<!@(find ../test/ -name '*.cpp')"
       ],
@@ -141,6 +141,22 @@
       ]
     },
     {
+      "target_name": "vtile-transform",
+      'dependencies': [ 'mapnik_vector_tile_impl' ],
+      "type": "executable",
+      "defines": [
+        "<@(common_defines)",
+        "MAPNIK_PLUGINDIR=<(MAPNIK_PLUGINDIR)"
+      ],
+      "sources": [
+        "../bench/vtile-transform.cpp"
+      ],
+      "include_dirs": [
+        "../src",
+        '../deps/pbf'
+      ]
+    },
+    {
       "target_name": "tileinfo",
       'dependencies': [ 'vector_tile' ],
       "type": "executable",
diff --git a/package.json b/package.json
index 515480b..66b7b07 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "mapnik-vector-tile",
-    "version": "0.8.1",
+    "version": "0.8.2",
     "description": "Mapnik vector tile API",
     "main": "./package.json",
     "repository"   :  {
diff --git a/scripts/build.sh b/scripts/build.sh
index 6cd618b..26410ac 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -6,6 +6,8 @@ if [[ ${COVERAGE:-false} == true ]]; then
     export CXXFLAGS="--coverage"
 fi
 
+echo $PROJ_LIB
+ls $PROJ_LIB/
 make -j${JOBS} test BUILDTYPE=${BUILDTYPE:-Release} V=1
 
 set +e +u
\ No newline at end of file
diff --git a/src/vector_tile_processor.ipp b/src/vector_tile_processor.ipp
index 8851fd3..27f7368 100644
--- a/src/vector_tile_processor.ipp
+++ b/src/vector_tile_processor.ipp
@@ -1244,7 +1244,8 @@ unsigned processor<T>::handle_geometry(mapnik::feature_impl const& feature,
     mapnik::geometry::point<std::int64_t> p2_min = mapnik::geometry::transform<std::int64_t>(p1_min, vs);
     mapnik::geometry::point<std::int64_t> p2_max = mapnik::geometry::transform<std::int64_t>(p1_max, vs);
     box2d<int> bbox(p2_min.x, p2_min.y, p2_max.x, p2_max.y);
-    mapnik::geometry::geometry<std::int64_t> new_geom = mapnik::geometry::transform<std::int64_t>(geom, vs);
+    mapnik::vector_tile_impl::transform_visitor skipping_transformer(vs);
+    mapnik::geometry::geometry<std::int64_t> new_geom = mapnik::util::apply_visitor(skipping_transformer,geom);
     encoder_visitor<T> encoder(backend_,feature,bbox, area_threshold_);
     if (simplify_distance_ > 0)
     {
diff --git a/src/vector_tile_strategy.hpp b/src/vector_tile_strategy.hpp
index 1f8c045..aa80caa 100644
--- a/src/vector_tile_strategy.hpp
+++ b/src/vector_tile_strategy.hpp
@@ -1,25 +1,3 @@
-/*****************************************************************************
- *
- * This file is part of Mapnik (c++ mapping toolkit)
- *
- * Copyright (C) 2014 Artem Pavlenko
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- *****************************************************************************/
-
 #ifndef MAPNIK_VECTOR_TILE_STRATEGY_HPP
 #define MAPNIK_VECTOR_TILE_STRATEGY_HPP
 
@@ -49,7 +27,8 @@ struct vector_tile_strategy
                          double scaling)
         : prj_trans_(prj_trans),
           tr_(tr),
-          scaling_(scaling) {}
+          scaling_(scaling),
+          not_equal_(!prj_trans_.equal()) {}
 
     template <typename P1, typename P2>
     inline bool apply(P1 const& p1, P2 & p2) const
@@ -58,14 +37,10 @@ struct vector_tile_strategy
         double x = boost::geometry::get<0>(p1);
         double y = boost::geometry::get<1>(p1);
         double z = 0.0;
-        if (!prj_trans_.backward(x, y, z)) return false;
+        if (not_equal_ && !prj_trans_.backward(x, y, z)) return false;
         tr_.forward(&x,&y);
-        x = x * scaling_;
-        y = y * scaling_;
-        x = std::round(x);
-        y = std::round(y);
-        boost::geometry::set<0>(p2, static_cast<p2_type>(x));
-        boost::geometry::set<1>(p2, static_cast<p2_type>(y));
+        boost::geometry::set<0>(p2, static_cast<p2_type>(std::round(x * scaling_)));
+        boost::geometry::set<1>(p2, static_cast<p2_type>(std::round(y * scaling_)));
         return true;
     }
     
@@ -80,6 +55,153 @@ struct vector_tile_strategy
     proj_transform const& prj_trans_;
     view_transform const& tr_;
     double const scaling_;
+    bool not_equal_;
+};
+
+// TODO - avoid creating degenerate polygons when first/last point of ring is skipped
+struct transform_visitor {
+
+    transform_visitor(vector_tile_strategy const& tr) :
+      tr_(tr) {}
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::point<double> const& geom)
+    {
+        mapnik::geometry::point<std::int64_t> new_geom;
+        if (!tr_.apply(geom,new_geom)) return mapnik::geometry::geometry_empty();
+        return new_geom;
+    }
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::multi_point<double> const& geom)
+    {
+        mapnik::geometry::multi_point<std::int64_t> new_geom;
+        new_geom.reserve(geom.size());
+        for (auto const& pt : geom)
+        {
+            mapnik::geometry::point<std::int64_t> pt2;
+            if (tr_.apply(pt,pt2))
+            {
+                new_geom.push_back(std::move(pt2));
+            }
+        }
+        return new_geom;
+    }
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::line_string<double> const& geom)
+    {
+        mapnik::geometry::line_string<std::int64_t> new_geom;
+        new_geom.reserve(geom.size());
+        for (auto const& pt : geom)
+        {
+            mapnik::geometry::point<std::int64_t> pt2;
+            if (tr_.apply(pt,pt2))
+            {
+                new_geom.push_back(std::move(pt2));
+            }
+        }
+        return new_geom;
+    }
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::multi_line_string<double> const& geom)
+    {
+        mapnik::geometry::multi_line_string<std::int64_t> new_geom;
+        new_geom.reserve(geom.size());
+        for (auto const& line : geom)
+        {
+            mapnik::geometry::line_string<std::int64_t> new_line;
+            new_line.reserve(line.size());
+            for (auto const& pt : line)
+            {
+                mapnik::geometry::point<std::int64_t> pt2;
+                if (tr_.apply(pt,pt2))
+                {
+                    new_line.push_back(std::move(pt2));
+                }
+            }
+            new_geom.push_back(std::move(new_line));
+        }
+        return new_geom;
+    }
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::polygon<double> const& geom)
+    {
+        mapnik::geometry::polygon<std::int64_t> new_geom;
+        new_geom.exterior_ring.reserve(geom.exterior_ring.size());
+        for (auto const& pt : geom.exterior_ring)
+        {
+            mapnik::geometry::point<std::int64_t> pt2;
+            if (tr_.apply(pt,pt2))
+            {
+                new_geom.exterior_ring.push_back(std::move(pt2));
+            }
+        }
+        for (auto const& ring : geom.interior_rings)
+        {
+            mapnik::geometry::linear_ring<std::int64_t> new_ring;
+            new_ring.reserve(ring.size());
+            for (auto const& pt : ring)
+            {
+                mapnik::geometry::point<std::int64_t> pt2;
+                if (tr_.apply(pt,pt2))
+                {
+                    new_ring.push_back(std::move(pt2));
+                }
+            }
+            new_geom.interior_rings.push_back(std::move(new_ring));
+        }
+        return new_geom;
+    }
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::multi_polygon<double> const& geom)
+    {
+        mapnik::geometry::multi_polygon<std::int64_t> new_geom;
+        new_geom.reserve(geom.size());
+        for (auto const& poly : geom)
+        {
+            mapnik::geometry::polygon<std::int64_t> new_poly;
+            new_poly.exterior_ring.reserve(poly.exterior_ring.size());
+            for (auto const& pt : poly.exterior_ring)
+            {
+                mapnik::geometry::point<std::int64_t> pt2;
+                if (tr_.apply(pt,pt2))
+                {
+                    new_poly.exterior_ring.push_back(std::move(pt2));
+                }
+            }
+            for (auto const& ring : poly.interior_rings)
+            {
+                mapnik::geometry::linear_ring<std::int64_t> new_ring;
+                new_ring.reserve(ring.size());
+                for (auto const& pt : ring)
+                {
+                    mapnik::geometry::point<std::int64_t> pt2;
+                    if (tr_.apply(pt,pt2))
+                    {
+                        new_ring.push_back(std::move(pt2));
+                    }
+                }
+                new_poly.interior_rings.push_back(std::move(new_ring));
+            }
+            new_geom.push_back(std::move(new_poly));
+        }
+        return new_geom;
+    }
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::geometry_collection<double> const& geom)
+    {
+        mapnik::geometry::geometry_collection<std::int64_t> new_geom;
+        new_geom.reserve(geom.size());
+        for (auto const& g : geom)
+        {
+            new_geom.push_back(mapnik::util::apply_visitor((*this), g));
+        }
+        return new_geom;
+     }
+
+    inline mapnik::geometry::geometry<std::int64_t> operator() (mapnik::geometry::geometry_empty const& geom)
+    {
+        return geom;
+    }
+    vector_tile_strategy const& tr_;
 };
 
 }
diff --git a/test/data/poly-lat-invalid-4269.dbf b/test/data/poly-lat-invalid-4269.dbf
new file mode 100644
index 0000000..aa21090
Binary files /dev/null and b/test/data/poly-lat-invalid-4269.dbf differ
diff --git a/test/data/poly-lat-invalid-4269.prj b/test/data/poly-lat-invalid-4269.prj
new file mode 100644
index 0000000..747df58
--- /dev/null
+++ b/test/data/poly-lat-invalid-4269.prj
@@ -0,0 +1 @@
+GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
\ No newline at end of file
diff --git a/test/data/poly-lat-invalid-4269.shp b/test/data/poly-lat-invalid-4269.shp
new file mode 100644
index 0000000..8a31511
Binary files /dev/null and b/test/data/poly-lat-invalid-4269.shp differ
diff --git a/test/data/poly-lat-invalid-4269.shx b/test/data/poly-lat-invalid-4269.shx
new file mode 100644
index 0000000..f80e0a5
Binary files /dev/null and b/test/data/poly-lat-invalid-4269.shx differ
diff --git a/test/data/polygon-style.xml b/test/data/polygon-style.xml
new file mode 100644
index 0000000..3725c90
--- /dev/null
+++ b/test/data/polygon-style.xml
@@ -0,0 +1,7 @@
+<Map>
+<Style name="style">
+    <Rule>
+        <PolygonSymbolizer fill="red" />
+    </Rule>
+</Style>
+</Map>
\ No newline at end of file
diff --git a/test/fixtures/transform-expected-1.png b/test/fixtures/transform-expected-1.png
new file mode 100644
index 0000000..cb58d79
Binary files /dev/null and b/test/fixtures/transform-expected-1.png differ
diff --git a/test/geometry_encoding.cpp b/test/geometry_encoding.cpp
index b599580..69a94eb 100644
--- a/test/geometry_encoding.cpp
+++ b/test/geometry_encoding.cpp
@@ -173,7 +173,7 @@ TEST_CASE( "polygon with degenerate exterior ring ", "should be culled" ) {
     p0.exterior_ring.add_coord(0,10);
 
     std::string wkt0;
-    CHECK( mapnik::util::to_wkt(wkt0,p0) );
+    CHECK( mapnik::util::to_wkt(wkt0,mapnik::geometry::geometry<std::int64_t>(p0)) );
     // wkt writer copes with busted polygon
     std::string expected_wkt0("POLYGON((0 0,0 10))");
     CHECK( wkt0 == expected_wkt0);
@@ -226,7 +226,7 @@ TEST_CASE( "polygon with valid exterior ring but degenerate interior ring", "sho
     p0.add_hole(std::move(hole));
 
     std::string wkt0;
-    CHECK( mapnik::util::to_wkt(wkt0,p0) );
+    CHECK( mapnik::util::to_wkt(wkt0,mapnik::geometry::geometry<std::int64_t>(p0)) );
     // wkt writer copes with busted polygon
     std::string expected_wkt0("POLYGON((0 0,0 10,-10 10,-10 0,0 0),(-7 7,-3 7))");
     CHECK( wkt0 == expected_wkt0);
@@ -267,7 +267,7 @@ TEST_CASE( "polygon with valid exterior ring but one degenerate interior ring of
     }
 
     std::string wkt0;
-    CHECK( mapnik::util::to_wkt(wkt0,p0) );
+    CHECK( mapnik::util::to_wkt(wkt0,mapnik::geometry::geometry<std::int64_t>(p0)) );
     // wkt writer copes with busted polygon
     std::string expected_wkt0("POLYGON((0 0,0 10,-10 10,-10 0,0 0),(-7 7,-3 7),(-6 4,-6 6,-4 6,-4 4,-6 4))");
     CHECK( wkt0 == expected_wkt0);
@@ -304,14 +304,14 @@ TEST_CASE( "(multi)polygon with hole", "should round trip without changes" ) {
     mapnik::box2d<double> extent = mapnik::geometry::envelope(p0);
 
     std::string wkt0;
-    CHECK( mapnik::util::to_wkt(wkt0,p0) );
+    CHECK( mapnik::util::to_wkt(wkt0,mapnik::geometry::geometry<std::int64_t>(p0) ) );
     std::string expected_wkt0("POLYGON((0 0,0 10,-10 10,-10 0,0 0),(-7 7,-3 7,-3 3,-7 3,-7 7))");
     CHECK( wkt0 == expected_wkt0);
     // ensure correcting geometry has no effect
     // as a way of confirming the original was correct
     mapnik::geometry::correct(p0);
     wkt0.clear();
-    CHECK( mapnik::util::to_wkt(wkt0,p0) );
+    CHECK( mapnik::util::to_wkt(wkt0,mapnik::geometry::geometry<std::int64_t>(p0)) );
     CHECK( wkt0 == expected_wkt0);
 
     vector_tile::Tile_Feature feature = geometry_to_feature<std::int64_t>(p0);
diff --git a/test/raster_tile.cpp b/test/raster_tile.cpp
index 1cf98b2..05be15d 100644
--- a/test/raster_tile.cpp
+++ b/test/raster_tile.cpp
@@ -21,7 +21,6 @@
 #include <fstream>
 
 TEST_CASE( "raster tile output 1", "should create raster tile with one raster layer" ) {
-    mapnik::datasource_cache::instance().register_datasources(MAPNIK_PLUGINDIR);
     typedef mapnik::vector_tile_impl::backend_pbf backend_type;
     typedef mapnik::vector_tile_impl::processor<backend_type> renderer_type;
     typedef vector_tile::Tile tile_type;
@@ -141,7 +140,6 @@ TEST_CASE( "raster tile output 1", "should create raster tile with one raster la
 }
 
 TEST_CASE( "raster tile output 2", "should be able to overzoom raster" ) {
-    mapnik::datasource_cache::instance().register_datasources(MAPNIK_PLUGINDIR);
     typedef vector_tile::Tile tile_type;
     tile_type tile;
     {
diff --git a/test/test_main.cpp b/test/test_main.cpp
index e12617c..c49e5e8 100644
--- a/test/test_main.cpp
+++ b/test/test_main.cpp
@@ -3,6 +3,7 @@
 #include "catch.hpp"
 
 #include <google/protobuf/stubs/common.h>
+#include <mapnik/datasource_cache.hpp>
 
 int main (int argc, char* const argv[])
 {
@@ -14,6 +15,7 @@ int main (int argc, char* const argv[])
         std::clog << ex.what() << "\n";
         return -1;
     }
+    mapnik::datasource_cache::instance().register_datasources(MAPNIK_PLUGINDIR);
     int result = Catch::Session().run( argc, argv );
     if (!result) printf("\x1b[1;32m ✓ \x1b[0m\n");
     google::protobuf::ShutdownProtobufLibrary();
diff --git a/test/vector_tile.cpp b/test/vector_tile.cpp
index 3a15986..886c6f7 100644
--- a/test/vector_tile.cpp
+++ b/test/vector_tile.cpp
@@ -19,6 +19,7 @@
 #include <mapnik/geometry_strategy.hpp>
 #include <mapnik/proj_strategy.hpp>
 #include <mapnik/geometry.hpp>
+#include <mapnik/datasource_cache.hpp>
 
 #include <boost/optional/optional_io.hpp>
 
@@ -562,11 +563,13 @@ TEST_CASE( "encoding single line 2", "should maintain start/end vertex" ) {
         geom.set_exterior_ring(std::move(ring));
     }
     mapnik::geometry::scale_rounding_strategy scale_strat(backend.get_path_multiplier());
-    mapnik::geometry::polygon<std::int64_t> poly = mapnik::geometry::transform<std::int64_t>(geom, scale_strat);
+    mapnik::geometry::geometry<std::int64_t> geom2 = mapnik::geometry::transform<std::int64_t>(geom, scale_strat);
     std::string foo;
-    mapnik::util::to_wkt(foo, poly);
+    mapnik::util::to_wkt(foo, geom2);
     INFO(foo);
     backend.current_feature_->set_type(vector_tile::Tile_GeomType_POLYGON);
+    REQUIRE( geom2.is<mapnik::geometry::polygon<std::int64_t> >() );
+    auto const& poly = mapnik::util::get<mapnik::geometry::polygon<std::int64_t>>(geom2);
     backend.add_path(poly);
     backend.stop_tile_feature();
     backend.stop_tile_layer();
@@ -1056,3 +1059,79 @@ TEST_CASE( "vector tile line_string is verify direction", "should line string wi
     auto const& line2 = mapnik::util::get<mapnik::geometry::multi_line_string<double> >(new_geom);
     CHECK( line2.size() == 2 );
 }
+
+TEST_CASE( "vector tile transform", "should not throw on coords outside merc range" ) {
+    typedef mapnik::vector_tile_impl::backend_pbf backend_type;
+    typedef mapnik::vector_tile_impl::processor<backend_type> renderer_type;
+    typedef vector_tile::Tile tile_type;
+    tile_type tile;
+    backend_type backend(tile,64);
+    unsigned tile_size = 256;
+    mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
+    mapnik::Map map(tile_size,tile_size,"+init=epsg:3857");
+    // Note: 4269 is key. 4326 will trigger custom mapnik reprojection code
+    // that does not hit proj4 and clamps values
+    mapnik::layer lyr("layer","+init=epsg:4269");
+    mapnik::parameters params;
+    params["type"] = "shape";
+    params["file"] = "./test/data/poly-lat-invalid-4269.shp";
+    std::shared_ptr<mapnik::datasource> ds =
+        mapnik::datasource_cache::instance().create(params);
+    lyr.set_datasource(ds);
+    map.add_layer(lyr);
+    map.zoom_to_box(bbox);
+    mapnik::request m_req(tile_size,tile_size,bbox);
+    renderer_type ren(backend,map,m_req);
+    // should no longer throw after https://github.com/mapbox/mapnik-vector-tile/issues/116
+    ren.apply();
+
+    // serialize to message
+    std::string buffer;
+    CHECK(tile.SerializeToString(&buffer));
+    CHECK(70 == buffer.size());
+    // now create new objects
+    mapnik::Map map2(tile_size,tile_size,"+init=epsg:3857");
+    tile_type tile2;
+    CHECK(tile2.ParseFromString(buffer));
+    std::string key("");
+    CHECK(false == mapnik::vector_tile_impl::is_solid_extent(tile2,key));
+    CHECK("" == key);
+    CHECK(1 == tile2.layers_size());
+    vector_tile::Tile_Layer const& layer2 = tile2.layers(0);
+    CHECK(std::string("layer") == layer2.name());
+    CHECK(1 == layer2.features_size());
+
+    mapnik::layer lyr2("layer",map.srs());
+    std::shared_ptr<mapnik::vector_tile_impl::tile_datasource> ds2 = std::make_shared<
+                                    mapnik::vector_tile_impl::tile_datasource>(
+                                        layer2,0,0,0,map2.width());
+    ds2->set_envelope(bbox);
+    CHECK( ds2->type() == mapnik::datasource::Vector );
+    CHECK( ds2->get_geometry_type() == mapnik::datasource_geometry_t::Collection );
+    mapnik::layer_descriptor lay_desc = ds2->get_descriptor();
+    std::vector<std::string> expected_names;
+    expected_names.push_back("FID");
+    std::vector<std::string> names;
+    for (auto const& desc : lay_desc.get_descriptors())
+    {
+        names.push_back(desc.get_name());
+    }
+    CHECK(names == expected_names);
+    lyr2.set_datasource(ds2);
+    lyr2.add_style("style");
+    map2.add_layer(lyr2);
+    mapnik::load_map(map2,"test/data/polygon-style.xml");
+    //std::clog << mapnik::save_map_to_string(map2) << "\n";
+    map2.zoom_to_box(bbox);
+    mapnik::image_rgba8 im(map2.width(),map2.height());
+    mapnik::agg_renderer<mapnik::image_rgba8> ren2(map2,im);
+    ren2.apply();
+    if (!mapnik::util::exists("test/fixtures/transform-expected-1.png")) {
+        mapnik::save_to_file(im,"test/fixtures/transform-expected-1.png","png32");
+    }
+    unsigned diff = testing::compare_images(im,"test/fixtures/transform-expected-1.png");
+    CHECK(0 == diff);
+    if (diff > 0) {
+        mapnik::save_to_file(im,"test/fixtures/transform-actual-1.png","png32");
+    }
+}
diff --git a/test/vector_tile_pbf.cpp b/test/vector_tile_pbf.cpp
index 25482e5..a74f93b 100644
--- a/test/vector_tile_pbf.cpp
+++ b/test/vector_tile_pbf.cpp
@@ -442,7 +442,6 @@ TEST_CASE( "pbf vector tile from simplified geojson", "should create vector tile
 
 
 TEST_CASE( "pbf raster tile output", "should be able to overzoom raster" ) {
-    mapnik::datasource_cache::instance().register_datasources(MAPNIK_PLUGINDIR);
     typedef vector_tile::Tile tile_type;
     tile_type tile;
     {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapnik-vector-tile.git



More information about the Pkg-grass-devel mailing list