Skip to content

Commit

Permalink
pull in the vector tile v1.0.1 spec (+ experimental raster) + separat…
Browse files Browse the repository at this point in the history
…e namespacing
  • Loading branch information
Dane Springmeyer committed Oct 18, 2014
1 parent de1d542 commit 1532ccc
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 158 deletions.
12 changes: 6 additions & 6 deletions examples/c++/tileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char** argv)
stream.close();

// now attemp to open protobuf
mapnik::vector::tile tile;
vector_tile::Tile tile;
if (mapnik::vector::is_compressed(message))
{
std::string uncompressed;
Expand All @@ -75,7 +75,7 @@ int main(int argc, char** argv)
std::cout << "layers: " << tile.layers_size() << "\n";
for (unsigned i=0;i<tile.layers_size();++i)
{
mapnik::vector::tile_layer const& layer = tile.layers(i);
vector_tile::Tile_Layer const& layer = tile.layers(i);
std::cout << layer.name() << ":\n";
std::cout << " version: " << layer.version() << "\n";
std::cout << " extent: " << layer.extent() << "\n";
Expand All @@ -91,7 +91,7 @@ int main(int argc, char** argv)
unsigned degenerate = 0;
for (unsigned j=0;j<layer.features_size();++j)
{
mapnik::vector::tile_feature const & f = layer.features(j);
vector_tile::Tile_Feature const & f = layer.features(j);
total_repeated += f.geometry_size();
eGeomType g_type = static_cast<eGeomType>(f.type());
int cmd = -1;
Expand Down Expand Up @@ -150,7 +150,7 @@ int main(int argc, char** argv)
} else {
for (unsigned i=0;i<tile.layers_size();++i)
{
mapnik::vector::tile_layer const& layer = tile.layers(i);
vector_tile::Tile_Layer const& layer = tile.layers(i);
std::cout << "layer: " << layer.name() << "\n";
std::cout << " version: " << layer.version() << "\n";
std::cout << " extent: " << layer.extent() << "\n";
Expand All @@ -167,7 +167,7 @@ int main(int argc, char** argv)
std::cout << " values: ";
for (unsigned i=0;i<layer.values_size();++i)
{
mapnik::vector::tile_value const & value = layer.values(i);
vector_tile::Tile_Value const & value = layer.values(i);
if (value.has_string_value()) {
std::cout << value.string_value();
} else if (value.has_int_value()) {
Expand All @@ -192,7 +192,7 @@ int main(int argc, char** argv)
std::cout << "\n";
for (unsigned i=0;i<layer.features_size();++i)
{
mapnik::vector::tile_feature const & feat = layer.features(i);
vector_tile::Tile_Feature const & feat = layer.features(i);
std::cout << " feature: " << feat.id() << "\n";
std::cout << " type: ";
unsigned feat_type = feat.type();
Expand Down
67 changes: 37 additions & 30 deletions proto/vector_tile.proto
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Protocol Version 1

package mapnik.vector;
package vector_tile;

option optimize_for = LITE_RUNTIME;

message tile {
message Tile {
enum GeomType {
Unknown = 0;
Point = 1;
LineString = 2;
Polygon = 3;
UNKNOWN = 0;
POINT = 1;
LINESTRING = 2;
POLYGON = 3;
}

// Variant type encoding
message value {
message Value {
// Exactly one of these values may be present in a valid message
optional string string_value = 1;
optional float float_value = 2;
Expand All @@ -26,17 +26,20 @@ message tile {
extensions 8 to max;
}

message feature {
optional uint64 id = 1;
message Feature {
optional uint64 id = 1 [ default = 0 ];

// Tags of this feature. Even numbered values refer to the nth
// value in the keys list on the tile message, odd numbered
// values refer to the nth value in the values list on the tile
// message.
// Tags of this feature are encoded as repeated pairs of
// integers. Even indexed values (n, beginning with 0) are
// themselves indexes into the layer's keys list. Odd indexed
// values (n+1) are indexes into the layer's values list.
// The first (n=0) tag of a feature, therefore, has a key of
// layer.keys[feature.tags[0]] and a value of
// layer.values[feature.tags[1]].
repeated uint32 tags = 2 [ packed = true ];

// The type of geometry stored in this feature.
optional GeomType type = 3 [ default = Unknown ];
optional GeomType type = 3 [ default = UNKNOWN ];

// Contains a stream of commands and parameters (vertices). The
// repeat count is shifted to the left by 3 bits. This means
Expand All @@ -47,25 +50,29 @@ message tile {
// - LineTo: 2 (2 parameters follow)
// - ClosePath: 7 (no parameters follow)
//
// Commands are encoded as uint32 varints. Vertex parameters
// are encoded as deltas to the previous position and, as they
// may be negative, are further "zigzag" encoded as unsigned
// 32-bit ints:
//
// n = (n << 1) ^ (n >> 31)
//
// Ex.: MoveTo(3, 6), LineTo(8, 12), LineTo(20, 34), ClosePath
// Encoded as: [ 9 3 6 18 5 6 12 22 15 ]
// == command type 7 (ClosePath), length 1
// ===== relative LineTo(+12, +22) == LineTo(20, 34)
// === relative LineTo(+5, +6) == LineTo(8, 12)
// == [00010 010] = command type 2 (LineTo), length 2
// === relative MoveTo(+3, +6)
// == [00001 001] = command type 1 (MoveTo), length 1
// Commands are encoded as uint32 varints, vertex parameters are
// encoded as sint32 varints (zigzag). Vertex parameters are
// also encoded as deltas to the previous position. The original
// position is (0,0)
// Encoded as: [ 9 6 12 18 10 12 24 44 15 ]
// | | `> [00001 111] command type 7 (ClosePath), length 1
// | | ===== relative LineTo(+12, +22) == LineTo(20, 34)
// | | ===== relative LineTo(+5, +6) == LineTo(8, 12)
// | `> [00010 010] = command type 2 (LineTo), length 2
// | ==== relative MoveTo(+3, +6)
// `> [00001 001] = command type 1 (MoveTo), length 1
//
// The original position is (0,0).
repeated uint32 geometry = 4 [ packed = true ];

optional bytes raster = 5;

}

message layer {
message Layer {
// Any compliant implementation must first read the version
// number encoded in this message and choose the correct
// implementation for this version number before proceeding to
Expand All @@ -75,21 +82,21 @@ message tile {
required string name = 1;

// The actual features in this tile.
repeated feature features = 2;
repeated Feature features = 2;

// Dictionary encoding for keys
repeated string keys = 3;

// Dictionary encoding for values
repeated value values = 4;
repeated Value values = 4;

// The bounding box in this tile spans from 0..4095 units
optional uint32 extent = 5 [ default = 4096 ];

extensions 16 to max;
}

repeated layer layers = 3;
repeated Layer layers = 3;

extensions 16 to 8191;
}
18 changes: 9 additions & 9 deletions src/vector_tile_backend_pbf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include MAPNIK_VARIANT_INCLUDE

namespace mapnik { namespace vector {
namespace mapnik { namespace vector_tile_impl {

struct to_tile_value: public MAPNIK_STATIC_VISITOR<>
{
public:
to_tile_value(tile_value * value):
to_tile_value(vector_tile::Tile_Value * value):
value_(value) {}

void operator () ( value_integer val ) const
Expand Down Expand Up @@ -56,23 +56,23 @@ namespace mapnik { namespace vector {
// do nothing
}
private:
tile_value * value_;
vector_tile::Tile_Value * value_;
};

struct backend_pbf
{
typedef std::map<std::string, unsigned> keys_container;
typedef boost::unordered_map<mapnik::value, unsigned> values_container;
private:
tile & tile_;
vector_tile::Tile & tile_;
unsigned path_multiplier_;
mutable tile_layer * current_layer_;
mutable tile_feature * current_feature_;
mutable vector_tile::Tile_Layer * current_layer_;
mutable vector_tile::Tile_Feature * current_feature_;
keys_container keys_;
values_container values_;
int32_t x_, y_;
public:
explicit backend_pbf(tile & _tile,
explicit backend_pbf(vector_tile::Tile & _tile,
unsigned path_multiplier)
: tile_(_tile),
path_multiplier_(path_multiplier),
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace mapnik { namespace vector {

inline void stop_tile_layer()
{
//std::cerr << "stop_tile_layer()" << std::endl;
//std::cerr << "stop_vector_tile::Tile_Layer()" << std::endl;
}

template <typename T>
Expand All @@ -184,7 +184,7 @@ namespace mapnik { namespace vector {
if (current_feature_)
{
return encode_geometry(path,
static_cast<tile_GeomType>(type),
static_cast<vector_tile::Tile_GeomType>(type),
*current_feature_,
x_,
y_,
Expand Down
2 changes: 1 addition & 1 deletion src/vector_tile_compression.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdexcept>
#include <zlib.h>

namespace mapnik { namespace vector {
namespace mapnik { namespace vector_tile_impl {

inline bool is_compressed(std::string const& data)
{
Expand Down
22 changes: 11 additions & 11 deletions src/vector_tile_datasource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
#include MAPNIK_SHARED_INCLUDE
#include MAPNIK_VIEW_TRANSFORM_INCLUDE

namespace mapnik { namespace vector {
namespace mapnik { namespace vector_tile_impl {

void add_attributes(mapnik::feature_ptr feature,
mapnik::vector::tile_feature const& f,
mapnik::vector::tile_layer const& layer,
vector_tile::Tile_Feature const& f,
vector_tile::Tile_Layer const& layer,
mapnik::transcoder const& tr)
{
std::size_t num_keys = static_cast<std::size_t>(layer.keys_size());
Expand All @@ -55,7 +55,7 @@ namespace mapnik { namespace vector {
std::string const& name = layer.keys(key_name);
if (feature->has_key(name))
{
mapnik::vector::tile_value const& value = layer.values(key_value);
vector_tile::Tile_Value const& value = layer.values(key_value);
if (value.has_string_value())
{
std::string str = value.string_value();
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace mapnik { namespace vector {
mapnik::box2d<double> const& tile_extent,
mapnik::box2d<double> const& unbuffered_query,
std::set<std::string> const& attribute_names,
mapnik::vector::tile_layer const& layer,
vector_tile::Tile_Layer const& layer,
double tile_x,
double tile_y,
double scale)
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace mapnik { namespace vector {
{
while (itr_ < end_)
{
mapnik::vector::tile_feature const& f = layer_.features(itr_);
vector_tile::Tile_Feature const& f = layer_.features(itr_);
mapnik::value_integer feature_id = itr_++;
if (f.has_raster())
{
Expand Down Expand Up @@ -281,7 +281,7 @@ namespace mapnik { namespace vector {
Filter filter_;
mapnik::box2d<double> tile_extent_;
mapnik::box2d<double> unbuffered_query_;
mapnik::vector::tile_layer const& layer_;
vector_tile::Tile_Layer const& layer_;
double tile_x_;
double tile_y_;
double scale_;
Expand All @@ -294,7 +294,7 @@ namespace mapnik { namespace vector {
class tile_datasource : public datasource
{
public:
tile_datasource(mapnik::vector::tile_layer const& layer,
tile_datasource(vector_tile::Tile_Layer const& layer,
unsigned x,
unsigned y,
unsigned z,
Expand All @@ -311,7 +311,7 @@ namespace mapnik { namespace vector {
private:
mutable mapnik::layer_descriptor desc_;
mutable bool attributes_added_;
mapnik::vector::tile_layer const& layer_;
vector_tile::Tile_Layer const& layer_;
unsigned x_;
unsigned y_;
unsigned z_;
Expand All @@ -324,7 +324,7 @@ namespace mapnik { namespace vector {
};

// tile_datasource impl
inline tile_datasource::tile_datasource(mapnik::vector::tile_layer const& layer,
inline tile_datasource::tile_datasource(vector_tile::Tile_Layer const& layer,
unsigned x,
unsigned y,
unsigned z,
Expand Down Expand Up @@ -378,7 +378,7 @@ namespace mapnik { namespace vector {

inline box2d<double> tile_datasource::get_tile_extent() const
{
mapnik::vector::spherical_mercator merc(tile_size_);
spherical_mercator merc(tile_size_);
double minx,miny,maxx,maxy;
merc.xyz(x_,y_,z_,minx,miny,maxx,maxy);
return box2d<double>(minx,miny,maxx,maxy);
Expand Down
8 changes: 4 additions & 4 deletions src/vector_tile_geometry_encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <mapnik/vertex.hpp>
#include <mapnik/version.hpp>

namespace mapnik { namespace vector {
namespace mapnik { namespace vector_tile_impl {

inline void handle_skipped_last(tile_feature & current_feature,
inline void handle_skipped_last(vector_tile::Tile_Feature & current_feature,
int32_t skipped_index,
int32_t cur_x,
int32_t cur_y,
Expand All @@ -29,8 +29,8 @@ inline void handle_skipped_last(tile_feature & current_feature,

template <typename T>
unsigned encode_geometry(T & path,
tile_GeomType type,
tile_feature & current_feature,
vector_tile::Tile_GeomType type,
vector_tile::Tile_Feature & current_feature,
int32_t & x_,
int32_t & y_,
unsigned tolerance,
Expand Down
2 changes: 1 addition & 1 deletion src/vector_tile_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include MAPNIK_VIEW_TRANSFORM_INCLUDE
#include MAPNIK_TRANSFORM_PATH_INCLUDE

namespace mapnik { namespace vector {
namespace mapnik { namespace vector_tile_impl {


/*
Expand Down
2 changes: 1 addition & 1 deletion src/vector_tile_projection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define M_PI 3.141592653589793238462643
#endif

namespace mapnik { namespace vector {
namespace mapnik { namespace vector_tile_impl {

class spherical_mercator
{
Expand Down
Loading

0 comments on commit 1532ccc

Please sign in to comment.