[mapnik-vector-tile] 01/04: Imported Upstream version 1.1.0+dfsg

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Wed Apr 13 05:59:31 UTC 2016


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 bc20576835d90b100e4b84c5219a8ac604e57fbe
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Wed Apr 13 07:34:18 2016 +0200

    Imported Upstream version 1.1.0+dfsg
---
 .travis.yml                             |  4 ++
 CHANGELOG.md                            |  6 +++
 package.json                            |  2 +-
 src/vector_tile_featureset_pbf.ipp      |  2 +-
 src/vector_tile_geometry_clipper.hpp    |  1 -
 src/vector_tile_geometry_simplifier.hpp |  1 -
 src/vector_tile_is_valid.hpp            | 29 ++++-------
 src/vector_tile_load_tile.hpp           | 86 +++++++++++++++++++++++----------
 src/vector_tile_merc_tile.hpp           |  2 +-
 test/unit/load/merge.cpp                | 68 ++++++++++++++++++++++++++
 test/utils/encoding_util.cpp            |  3 +-
 test/vector_tile_pbf.cpp                | 40 +++++++--------
 12 files changed, 174 insertions(+), 70 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d4ef065..656058f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -50,3 +50,7 @@ before_script:
 script:
  # make sure tileinfo command works
  - ./build/${BUILDTYPE:-Release}/tileinfo examples/data/14_2620_6331.vector.mvt.z
+
+notifications:
+  slack:
+    secure: eP79cXpZ3zyVarMooLYi75C5XBS65SJkf12h25hLDmoaQD+aX0u3+/hivE3jxi8KI8v1Izpzf06aCGHL1lx/xXGg2uuiM6dtZTou1mJJ4oFsxzOJFfLXhsUO1+qXkJJG1xoaLpbSdX/y+2dfe0xKTm4zAlluj2DvwZO+R9djLGM=
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e126a5..9f9343d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # Changelog
 
+
+## 1.1.0
+
+- Changed defaults for `merge_from_buffer`. Now the tile loading API does not auto-upgrade from v1->v2 or validate by default.
+  The `upgrade` and `validate` behavior are now options to `merge_from_buffer` and `merge_from_compressed_buffer`
+
 ## 1.0.6
 
 - Removed boost simplification and implemented custom douglas peucker for big speed boost.
diff --git a/package.json b/package.json
index fa74330..fe9c7b0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "mapnik-vector-tile",
-    "version": "1.0.6",
+    "version": "1.1.0",
     "description": "Mapnik Vector Tile API",
     "main": "./package.json",
     "repository"   :  {
diff --git a/src/vector_tile_featureset_pbf.ipp b/src/vector_tile_featureset_pbf.ipp
index 191341d..978b198 100644
--- a/src/vector_tile_featureset_pbf.ipp
+++ b/src/vector_tile_featureset_pbf.ipp
@@ -306,7 +306,7 @@ feature_ptr tile_featureset_pbf<Filter>::next()
                     #endif
                     feature->set_geometry(std::move(geom));
                 }
-                catch (std::exception& e)
+                catch (std::exception const& e)
                 {
                     // For v1 any invalid geometry errors lets just skip the feature
                     continue;
diff --git a/src/vector_tile_geometry_clipper.hpp b/src/vector_tile_geometry_clipper.hpp
index 13a8029..348b345 100644
--- a/src/vector_tile_geometry_clipper.hpp
+++ b/src/vector_tile_geometry_clipper.hpp
@@ -8,7 +8,6 @@
 // mapnik
 #include <mapnik/box2d.hpp>
 #include <mapnik/geometry.hpp>
-#include <mapnik/geometry_adapters.hpp>
 
 // angus clipper
 // http://www.angusj.com/delphi/clipper.php
diff --git a/src/vector_tile_geometry_simplifier.hpp b/src/vector_tile_geometry_simplifier.hpp
index 8977764..617815c 100644
--- a/src/vector_tile_geometry_simplifier.hpp
+++ b/src/vector_tile_geometry_simplifier.hpp
@@ -7,7 +7,6 @@
 
 // mapnik
 #include <mapnik/geometry.hpp>
-#include <mapnik/geometry_adapters.hpp>
 
 namespace mapnik
 {
diff --git a/src/vector_tile_is_valid.hpp b/src/vector_tile_is_valid.hpp
index ce83407..18e5266 100644
--- a/src/vector_tile_is_valid.hpp
+++ b/src/vector_tile_is_valid.hpp
@@ -27,7 +27,7 @@ enum validity_error : std::uint8_t
     LAYER_HAS_MULTIPLE_EXTENT,
     LAYER_HAS_MULTIPLE_VERSION,
     LAYER_HAS_NO_FEATURES,
-    LAYER_HAS_INVALID_VERSION,
+    LAYER_HAS_UNSUPPORTED_VERSION,
     LAYER_HAS_RASTER_AND_VECTOR,
     LAYER_HAS_UNKNOWN_TAG,
     VALUE_MULTIPLE_VALUES,
@@ -67,8 +67,8 @@ inline std::string validity_error_to_string(validity_error err)
             return "Vector Tile Layer message has no features";
         case LAYER_HAS_MULTIPLE_VERSION:
             return "Vector Tile Layer message has multiple version tags";
-        case LAYER_HAS_INVALID_VERSION:
-            return "Vector Tile Layer message has an invalid version";
+        case LAYER_HAS_UNSUPPORTED_VERSION:
+            return "Vector Tile Layer message has an unsupported version";
         case LAYER_HAS_RASTER_AND_VECTOR:
             return "Vector Tile Layer contains raster and vector features";
         case LAYER_HAS_UNKNOWN_TAG:
@@ -271,8 +271,6 @@ inline void value_is_valid(protozero::pbf_reader & value_msg, std::set<validity_
 
 inline void layer_is_valid(protozero::pbf_reader & layer_msg, 
                     std::set<validity_error> & errors, 
-                    std::string & layer_name,
-                    std::uint32_t & version,
                     std::uint64_t & point_feature_count,
                     std::uint64_t & line_feature_count,
                     std::uint64_t & polygon_feature_count,
@@ -295,7 +293,7 @@ inline void layer_is_valid(protozero::pbf_reader & layer_msg,
                         errors.insert(LAYER_HAS_MULTIPLE_NAME);
                     }
                     contains_a_name = true;
-                    layer_name = layer_msg.get_string();
+                    layer_msg.skip();
                     break;
                 case Layer_Encoding::FEATURES:
                     {
@@ -333,7 +331,7 @@ inline void layer_is_valid(protozero::pbf_reader & layer_msg,
                         errors.insert(LAYER_HAS_MULTIPLE_VERSION);
                     }
                     contains_a_version = true;
-                    version = layer_msg.get_uint32();
+                    layer_msg.skip();
                     break;
                 default:
                     errors.insert(LAYER_HAS_UNKNOWN_TAG);
@@ -350,24 +348,18 @@ inline void layer_is_valid(protozero::pbf_reader & layer_msg,
     {
         errors.insert(LAYER_HAS_NO_NAME);
     }
-    if (version > 2 || version == 0)
-    {
-        errors.insert(LAYER_HAS_INVALID_VERSION);
-    }
-    if (!contains_an_extent && version != 1)
+    if (!contains_an_extent)
     {
         errors.insert(LAYER_HAS_NO_EXTENT);
     }
-    if (!contains_a_feature && version != 1)
+    if (!contains_a_feature)
     {
         errors.insert(LAYER_HAS_NO_FEATURES);
     }
 }
 
 inline void layer_is_valid(protozero::pbf_reader & layer_msg, 
-                           std::set<validity_error> & errors, 
-                           std::string & layer_name,
-                           std::uint32_t & version)
+                           std::set<validity_error> & errors)
 {
 
     std::uint64_t point_feature_count = 0;
@@ -376,9 +368,7 @@ inline void layer_is_valid(protozero::pbf_reader & layer_msg,
     std::uint64_t unknown_feature_count = 0;
     std::uint64_t raster_feature_count = 0;
     return layer_is_valid(layer_msg, 
-                          errors, 
-                          layer_name, 
-                          version,
+                          errors,
                           point_feature_count,
                           line_feature_count,
                           polygon_feature_count,
@@ -386,6 +376,7 @@ inline void layer_is_valid(protozero::pbf_reader & layer_msg,
                           raster_feature_count);
 }
 
+
 } // end ns vector_tile_impl
 
 } // end ns mapnik
diff --git a/src/vector_tile_load_tile.hpp b/src/vector_tile_load_tile.hpp
index 5858c13..9cc1d3c 100644
--- a/src/vector_tile_load_tile.hpp
+++ b/src/vector_tile_load_tile.hpp
@@ -7,6 +7,7 @@
 #include "vector_tile_tile.hpp"
 #include "vector_tile_datasource_pbf.hpp"
 #include "vector_tile_is_valid.hpp"
+#include "vector_tile_processor.hpp"
 
 // mapnik
 #include <mapnik/map.hpp>
@@ -28,7 +29,29 @@ namespace mapnik
 namespace vector_tile_impl
 {
 
-void merge_from_buffer(merc_tile & t, const char * data, std::size_t size)
+std::pair<std::string,std::uint32_t> get_layer_name_and_version(protozero::pbf_reader & layer_msg)
+{
+    std::string name;
+    std::uint32_t version = 1;
+    while (layer_msg.next())
+    {
+        switch (layer_msg.tag())
+        {
+            case Layer_Encoding::NAME:
+                name = layer_msg.get_string();
+                break;
+            case Layer_Encoding::VERSION:
+                version = layer_msg.get_uint32();;
+                break;
+            default:
+                layer_msg.skip();
+                break;
+        }
+    }
+    return std::make_pair(name,version);
+}
+
+void merge_from_buffer(merc_tile & t, const char * data, std::size_t size, bool validate = false, bool upgrade = false)
 {
     using ds_ptr = std::shared_ptr<mapnik::vector_tile_impl::tile_datasource_pbf>;
     protozero::pbf_reader tile_msg(data, size);
@@ -40,31 +63,44 @@ void merge_from_buffer(merc_tile & t, const char * data, std::size_t size)
             case Tile_Encoding::LAYERS:
                 {
                     auto layer_data = tile_msg.get_data();
-                    protozero::pbf_reader layer_valid_msg(layer_data);
-                    std::set<validity_error> errors;             
-                    std::string layer_name;
-                    std::uint32_t version = 1;
-                    layer_is_valid(layer_valid_msg, errors, layer_name, version);
-                    if (!errors.empty())
-                    {   
-                        std::string layer_errors;
-                        validity_error_to_string(errors, layer_errors);
-                        throw std::runtime_error(layer_errors);
+                    protozero::pbf_reader layer_props_msg(layer_data);
+                    auto layer_info = get_layer_name_and_version(layer_props_msg);
+                    std::string const& layer_name = layer_info.first;
+                    std::uint32_t version = layer_info.second;
+                    if (validate)
+                    {
+                        std::set<validity_error> errors;
+                        if (version < 1 || version > 2)
+                        {
+                            errors.insert(LAYER_HAS_UNSUPPORTED_VERSION);
+                        }
+                        if (t.has_layer(layer_name))
+                        {
+                            errors.insert(TILE_REPEATED_LAYER_NAMES);
+                        }
+                        protozero::pbf_reader layer_valid_msg(layer_data);
+                        layer_is_valid(layer_valid_msg, errors);
+                        if (!errors.empty())
+                        {
+                            std::string layer_errors;
+                            validity_error_to_string(errors, layer_errors);
+                            throw std::runtime_error(layer_errors);
+                        }
                     }
-                    if (t.has_layer(layer_name))
+                    else if (layer_name.empty() || t.has_layer(layer_name))
                     {
                         continue;
                     }
-                    if (version == 1)
+                    if (upgrade && version == 1)
                     {
-                        // v1 tiles will be converted to v2
-                        protozero::pbf_reader layer_msg(layer_data);
-                        ds_vec.push_back(std::make_shared<mapnik::vector_tile_impl::tile_datasource_pbf>(
-                                    layer_msg,
-                                    t.x(),
-                                    t.y(),
-                                    t.z(),
-                                    true));
+                            // v1 tiles will be converted to v2
+                            protozero::pbf_reader layer_msg(layer_data);
+                            ds_vec.push_back(std::make_shared<mapnik::vector_tile_impl::tile_datasource_pbf>(
+                                        layer_msg,
+                                        t.x(),
+                                        t.y(),
+                                        t.z(),
+                                        true));
                     }
                     else
                     {
@@ -90,7 +126,7 @@ void merge_from_buffer(merc_tile & t, const char * data, std::size_t size)
         ds->set_envelope(t.get_buffered_extent());
         mapnik::layer lyr(ds->get_name(), "+init=epsg:3857");
         lyr.set_datasource(ds);
-        map.add_layer(lyr);
+        map.add_layer(std::move(lyr));
     }
     mapnik::vector_tile_impl::processor ren(map);
     ren.set_multi_polygon_union(true);
@@ -101,18 +137,18 @@ void merge_from_buffer(merc_tile & t, const char * data, std::size_t size)
     t.buffer_size(prev_buffer_size);
 }
 
-void merge_from_compressed_buffer(merc_tile & t, const char * data, std::size_t size)
+void merge_from_compressed_buffer(merc_tile & t, const char * data, std::size_t size, bool validate = false, bool upgrade = false)
 {
     if (mapnik::vector_tile_impl::is_gzip_compressed(data,size) ||
         mapnik::vector_tile_impl::is_zlib_compressed(data,size))
     {
         std::string decompressed;
         mapnik::vector_tile_impl::zlib_decompress(data, size, decompressed);
-        return merge_from_buffer(t, decompressed.data(), decompressed.size());
+        return merge_from_buffer(t, decompressed.data(), decompressed.size(), validate, upgrade);
     }
     else
     {
-        return merge_from_buffer(t, data, size); 
+        return merge_from_buffer(t, data, size, validate, upgrade);
     }
 }
 
diff --git a/src/vector_tile_merc_tile.hpp b/src/vector_tile_merc_tile.hpp
index ffd1a31..6f0efdf 100644
--- a/src/vector_tile_merc_tile.hpp
+++ b/src/vector_tile_merc_tile.hpp
@@ -32,7 +32,7 @@ public:
 
     merc_tile(merc_tile && rhs) = default;
     
-    bool same_extent(merc_tile & other)
+    bool same_extent(merc_tile const& other)
     {
         return x_ == other.x_ &&
                y_ == other.y_ &&
diff --git a/test/unit/load/merge.cpp b/test/unit/load/merge.cpp
new file mode 100644
index 0000000..f5f825f
--- /dev/null
+++ b/test/unit/load/merge.cpp
@@ -0,0 +1,68 @@
+#include "catch.hpp"
+
+// mvt
+#include "vector_tile_load_tile.hpp"
+
+//protozero
+#include <protozero/pbf_reader.hpp>
+
+// std
+#include <fstream>
+#include <string>
+
+TEST_CASE( "merge_from_compressed_buffer" )
+{
+    std::ifstream stream("./test/data/0.0.0.vector.mvt",std::ios_base::in|std::ios_base::binary);
+    REQUIRE(stream.is_open());
+    std::string buffer(std::istreambuf_iterator<char>(stream.rdbuf()),(std::istreambuf_iterator<char>()));
+    REQUIRE(buffer.size() == 3812);
+    mapnik::vector_tile_impl::merc_tile tile(0,0,0);
+    // not validating or upgrading
+    mapnik::vector_tile_impl::merge_from_compressed_buffer(tile, buffer.data(), buffer.size());
+    CHECK(tile.get_layers().size() == 1);
+    {
+        protozero::pbf_reader tile_msg(tile.get_buffer());
+        while (tile_msg.next(mapnik::vector_tile_impl::Tile_Encoding::LAYERS))
+        {
+            auto layer_data = tile_msg.get_data();
+            protozero::pbf_reader layer_props_msg(layer_data);
+            auto layer_info = mapnik::vector_tile_impl::get_layer_name_and_version(layer_props_msg);
+            std::string const& layer_name = layer_info.first;
+            std::uint32_t version = layer_info.second;
+            CHECK(layer_name == "water");
+            CHECK(version == 1);
+            std::set<mapnik::vector_tile_impl::validity_error> errors;
+            protozero::pbf_reader layer_valid_msg(layer_data);
+            layer_is_valid(layer_valid_msg, errors);
+            CHECK(errors.size() == 0);
+        }
+    }
+
+    // re-adding silently skips existing layer by the same name
+    mapnik::vector_tile_impl::merge_from_compressed_buffer(tile, buffer.data(), buffer.size());
+    CHECK(tile.get_layers().size() == 1);
+
+    // re-adding and validating throws on duplicate layer name
+    REQUIRE_THROWS(mapnik::vector_tile_impl::merge_from_compressed_buffer(tile, buffer.data(), buffer.size(), true));
+
+    mapnik::vector_tile_impl::merc_tile tile2(0,0,0);
+    mapnik::vector_tile_impl::merge_from_compressed_buffer(tile2, buffer.data(), buffer.size(), true, true);
+    {
+        protozero::pbf_reader tile_msg(tile2.get_buffer());
+        while (tile_msg.next(mapnik::vector_tile_impl::Tile_Encoding::LAYERS))
+        {
+            auto layer_data = tile_msg.get_data();
+            protozero::pbf_reader layer_props_msg(layer_data);
+            auto layer_info = mapnik::vector_tile_impl::get_layer_name_and_version(layer_props_msg);
+            std::string const& layer_name = layer_info.first;
+            std::uint32_t version = layer_info.second;
+            CHECK(layer_name == "water");
+            CHECK(version == 2);
+            std::set<mapnik::vector_tile_impl::validity_error> errors;
+            protozero::pbf_reader layer_valid_msg(layer_data);
+            layer_is_valid(layer_valid_msg, errors);
+            CHECK(errors.size() == 0);
+        }
+    }
+
+}
diff --git a/test/utils/encoding_util.cpp b/test/utils/encoding_util.cpp
index 6f28b87..60521f6 100644
--- a/test/utils/encoding_util.cpp
+++ b/test/utils/encoding_util.cpp
@@ -7,13 +7,14 @@
 // mapnik
 #include <mapnik/vertex.hpp>
 #include <mapnik/geometry.hpp>
-#include <mapnik/geometry_adapters.hpp>
 #include <mapnik/vertex_processor.hpp>
 
 // test utils
 #include "encoding_util.hpp"
 #include "decoding_util.hpp"
 
+#include <iostream>
+
 using namespace mapnik::geometry;
 
 struct show_path
diff --git a/test/vector_tile_pbf.cpp b/test/vector_tile_pbf.cpp
index 5c3f5d9..e6b7764 100644
--- a/test/vector_tile_pbf.cpp
+++ b/test/vector_tile_pbf.cpp
@@ -522,32 +522,32 @@ TEST_CASE("pbf raster tile output -- should be able to overzoom raster")
 
 TEST_CASE("Check that we throw on various valid-but-we-don't-handle PBF encoded files")
 {
-    std::vector<std::string> filenames = {"test/data/tile_with_extra_feature_field.pbf",
-                                          "test/data/tile_with_extra_layer_fields.pbf",
-                                          "test/data/tile_with_invalid_layer_value_type.pbf",
-                                          "test/data/tile_with_unexpected_geomtype.pbf"};
+    std::vector<std::string> filenames = {"test/data/tile_with_extra_feature_field.mvt",
+                                          "test/data/tile_with_extra_layer_fields.mvt",
+                                          "test/data/tile_with_invalid_layer_value_type.mvt",
+                                          "test/data/tile_with_unexpected_geomtype.mvt"};
 
     for (auto const& f : filenames)
     {
-      CHECK_THROWS({
         std::ifstream t(f);
+        REQUIRE(t.is_open());
         std::string buffer((std::istreambuf_iterator<char>(t)),
-                            std::istreambuf_iterator<char>());
-
-        mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
-        unsigned tile_size = 4096;
-          protozero::pbf_reader pbf_tile(buffer);
-          pbf_tile.next();
-          protozero::pbf_reader layer2 = pbf_tile.get_message();
-          mapnik::vector_tile_impl::tile_datasource_pbf ds(layer2,0,0,0);
-          mapnik::featureset_ptr fs;
-          mapnik::feature_ptr f_ptr;
-          fs = ds.features(mapnik::query(bbox));
-          f_ptr = fs->next();
-          while (f_ptr != mapnik::feature_ptr()) {
+                        std::istreambuf_iterator<char>());
+        CHECK_THROWS({
+            mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
+            unsigned tile_size = 4096;
+              protozero::pbf_reader pbf_tile(buffer);
+              pbf_tile.next();
+              protozero::pbf_reader layer2 = pbf_tile.get_message();
+              mapnik::vector_tile_impl::tile_datasource_pbf ds(layer2,0,0,0);
+              mapnik::featureset_ptr fs;
+              mapnik::feature_ptr f_ptr;
+              fs = ds.features(mapnik::query(bbox));
               f_ptr = fs->next();
-          }
-      });
+              while (f_ptr != mapnik::feature_ptr()) {
+                  f_ptr = fs->next();
+              }
+        });
    }
 
 }

-- 
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