diff --git a/src/mbtiles_vector_featureset.cpp b/src/mbtiles_vector_featureset.cpp index 4b0a6e7..4f14134 100644 --- a/src/mbtiles_vector_featureset.cpp +++ b/src/mbtiles_vector_featureset.cpp @@ -42,6 +42,11 @@ mapnik::feature_ptr mbtiles_vector_featureset::next() return mapnik::feature_ptr(); } +int mbtiles_vector_featureset::convert_y(const int y) const +{ + return (1 << zoom_) - 1 - y; +} + bool mbtiles_vector_featureset::next_tile() { ++x_; @@ -56,7 +61,7 @@ bool mbtiles_vector_featureset::next_tile() bool mbtiles_vector_featureset::open_tile() { - std::string sql = (boost::format("SELECT tile_data FROM tiles WHERE zoom_level = %1% AND tile_column = %2% AND tile_row = %3%") % zoom_ % x_ % y_).str(); + std::string sql = (boost::format("SELECT tile_data FROM tiles WHERE zoom_level = %1% AND tile_column = %2% AND tile_row = %3%") % zoom_ % x_ % convert_y(y_)).str(); std::shared_ptr result (database_->execute_query(sql)); int size = 0; char const* blob = nullptr; diff --git a/src/mbtiles_vector_featureset.hpp b/src/mbtiles_vector_featureset.hpp index c380907..22b1865 100644 --- a/src/mbtiles_vector_featureset.hpp +++ b/src/mbtiles_vector_featureset.hpp @@ -55,6 +55,10 @@ class mbtiles_vector_featureset : public mapnik::Featureset int x_ = 0; /// y index of the currently accessed tile int y_ = 0; + /** + * Transform Y index (tile_row) from z/x/y to TMS schema. + */ + int convert_y(const int y) const; bool next_tile(); bool open_tile(); diff --git a/src/mvt_io.cpp b/src/mvt_io.cpp index 2690fb8..79a93fd 100644 --- a/src/mvt_io.cpp +++ b/src/mvt_io.cpp @@ -159,7 +159,7 @@ mapnik::feature_ptr mvt_layer::next_feature() return mapnik::feature_ptr(); } -void mvt_io::read_layer(protozero::pbf_reader& pbf_layer) +bool mvt_io::read_layer(protozero::pbf_reader& pbf_layer) //void mvt_io::read_layer(protozero::pbf_message& pbf_layer) { layer_.reset(new mvt_layer(x_, y_, zoom_)); @@ -252,6 +252,8 @@ void mvt_io::read_layer(protozero::pbf_reader& pbf_layer) } } layer_->finish_reading(); + std::cerr << '\n'; + return !ignore_layer; } mapnik::feature_ptr mvt_io::next() @@ -270,23 +272,15 @@ mvt_io::mvt_io(std::string&& data, const uint32_t x, const uint32_t y, const uin zoom_(zoom), layer_name_(layer_name) { - while (reader_.next()) - { - switch (reader_.tag_and_type()) { - case tag_and_type(static_cast(mvt_message::tile::layer), protozero::pbf_wire_type::length_delimited): { - std::cerr << "got layer\n"; - const auto data_view(reader_.get_view()); + while (reader_.next(static_cast(mvt_message::tile::layer))) { + std::cerr << "got layer\n"; + const auto data_view(reader_.get_view()); // protozero::pbf_message msg_layer(reader_.get_message()); - protozero::pbf_reader msg_layer(data_view); - read_layer(msg_layer); -// read_layers(); - break; - } - default: - std::cerr << "got tag " << reader_.tag() << " type " << static_cast(reader_.wire_type()) << '\n'; - reader_.skip(); + protozero::pbf_reader msg_layer(data_view); + if (read_layer(msg_layer)) { break; } +// read_layers(); } } diff --git a/src/mvt_io.hpp b/src/mvt_io.hpp index 6f3d663..d7a4472 100644 --- a/src/mvt_io.hpp +++ b/src/mvt_io.hpp @@ -121,7 +121,10 @@ class mvt_io const int tile_extent_ = -1; std::unique_ptr layer_; - void read_layer(protozero::pbf_reader& l); + /** + * Read a layer from PBF. Returns true if requested layer was parsed. + */ + bool read_layer(protozero::pbf_reader& l); // void read_layer(protozero::pbf_message& l); // void read_layers();