Skip to content

Commit

Permalink
Use the right message numbers for splines; additional spline support
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Oct 18, 2018
1 parent af66a8a commit cf81880
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 11 deletions.
7 changes: 6 additions & 1 deletion decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, u
for (size_t i = 0; i < tile.layers.size(); i++) {
state.json_write_string(tile.layers[i].name);

size_t points = 0, lines = 0, polygons = 0;
size_t points = 0, lines = 0, polygons = 0, splines = 0;
for (size_t j = 0; j < tile.layers[i].features.size(); j++) {
if (tile.layers[i].features[j].type == mvt_point) {
points++;
} else if (tile.layers[i].features[j].type == mvt_linestring) {
lines++;
} else if (tile.layers[i].features[j].type == mvt_polygon) {
polygons++;
} else if (tile.layers[i].features[j].type == mvt_spline) {
splines++;
}
}

Expand All @@ -73,6 +75,9 @@ void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, u
state.json_write_string("polygons");
state.json_write_unsigned(polygons);

state.json_write_string("splines");
state.json_write_unsigned(splines);

state.json_write_string("extent");
state.json_write_signed(tile.layers[i].extent);

Expand Down
1 change: 1 addition & 0 deletions geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define VT_POINT 1
#define VT_LINE 2
#define VT_POLYGON 3
#define VT_SPLINE 4

#define VT_END 0
#define VT_MOVETO 1
Expand Down
1 change: 1 addition & 0 deletions mbtiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct layermap_entry {
size_t points = 0;
size_t lines = 0;
size_t polygons = 0;
size_t splines = 0;
size_t retain = 0; // keep for tilestats, even if no features directly here

layermap_entry(size_t _id) {
Expand Down
12 changes: 10 additions & 2 deletions mvt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ bool mvt_tile::decode(std::string &message, bool &was_compressed) {
break;
}

case 11: /* knots */
case 8: /* knots */
{
auto pi = feature_reader.get_packed_uint64();
for (auto it = pi.first; it != pi.second; ++it) {
Expand All @@ -384,6 +384,10 @@ bool mvt_tile::decode(std::string &message, bool &was_compressed) {
break;
}

case 9: /* spline degree */
feature.spline_degree = feature_reader.get_uint32();
break;

default:
feature_reader.skip();
break;
Expand Down Expand Up @@ -649,7 +653,11 @@ std::string mvt_tile::encode(int z) {
feature_writer.add_packed_sint32(7, std::begin(elevations), std::end(elevations));
}

feature_writer.add_packed_uint64(11, std::begin(layers[i].features[f].knots), std::end(layers[i].features[f].knots));
feature_writer.add_packed_uint64(8, std::begin(layers[i].features[f].knots), std::end(layers[i].features[f].knots));

if (layers[i].features[f].spline_degree != 2) {
feature_writer.add_uint32(9, layers[i].features[f].spline_degree);
}

layer_writer.add_message(2, feature_string);
}
Expand Down
3 changes: 2 additions & 1 deletion mvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ enum mvt_geometry_type {
mvt_point = 1,
mvt_linestring = 2,
mvt_polygon = 3,
mvt_curve = 4,
mvt_spline = 4,
};

struct mvt_feature {
std::vector<unsigned> tags{};
std::vector<unsigned long> properties{};
std::vector<mvt_geometry> geometry{};
std::vector<unsigned long> knots{};
size_t spline_degree = 2;
int /* mvt_geometry_type */ type = 0;
unsigned long long id = 0;
bool has_id = false;
Expand Down
4 changes: 4 additions & 0 deletions plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
fk->second.lines++;
} else if (feature.type == mvt_polygon) {
fk->second.polygons++;
} else if (feature.type == mvt_spline) {
fk->second.splines++;
}

for (size_t i = 0; i < properties->length; i++) {
Expand Down Expand Up @@ -508,6 +510,8 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
fk->second.lines++;
} else if (sf.t == mvt_polygon) {
fk->second.polygons++;
} else if (sf.t == mvt_spline) {
fk->second.splines++;
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/muni/decode/multi.mbtiles.stats.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
{ "zoom": 11, "x": 326, "y": 791, "bytes": 366, "compressed": true, "layers": { "muni": { "points": 14, "lines": 0, "polygons": 0, "extent": 4096 } } }
{ "zoom": 11, "x": 326, "y": 791, "bytes": 366, "compressed": true, "layers": { "muni": { "points": 14, "lines": 0, "polygons": 0, "splines": 0, "extent": 4096 } } }
,
{ "zoom": 11, "x": 327, "y": 792, "bytes": 6207, "compressed": true, "layers": { "muni": { "points": 528, "lines": 0, "polygons": 0, "extent": 4096 } } }
{ "zoom": 11, "x": 327, "y": 792, "bytes": 6207, "compressed": true, "layers": { "muni": { "points": 528, "lines": 0, "polygons": 0, "splines": 0, "extent": 4096 } } }
,
{ "zoom": 11, "x": 327, "y": 791, "bytes": 43268, "compressed": true, "layers": { "muni": { "points": 4285, "lines": 0, "polygons": 0, "extent": 4096 }, "subway": { "points": 19, "lines": 0, "polygons": 0, "extent": 4096 } } }
{ "zoom": 11, "x": 327, "y": 791, "bytes": 43268, "compressed": true, "layers": { "muni": { "points": 4285, "lines": 0, "polygons": 0, "splines": 0, "extent": 4096 }, "subway": { "points": 19, "lines": 0, "polygons": 0, "splines": 0, "extent": 4096 } } }
,
{ "zoom": 11, "x": 954, "y": 791, "bytes": 73, "compressed": true, "layers": { "muni": { "points": 12, "lines": 0, "polygons": 0, "extent": 4096 } } }
{ "zoom": 11, "x": 954, "y": 791, "bytes": 73, "compressed": true, "layers": { "muni": { "points": 12, "lines": 0, "polygons": 0, "splines": 0, "extent": 4096 } } }
]
4 changes: 4 additions & 0 deletions tile-join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
v.string_value = "LineString";
} else if (feat.type == mvt_polygon) {
v.string_value = "Polygon";
} else if (feat.type == mvt_spline) {
v.string_value = "Spline";
}

attributes.insert(std::pair<std::string, mvt_value>("$type", v));
Expand Down Expand Up @@ -414,6 +416,8 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
file_keys->second.lines++;
} else if (feat.type == mvt_polygon) {
file_keys->second.polygons++;
} else if (feat.type == mvt_spline) {
file_keys->second.splines++;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,8 @@ serial_feature next_feature(FILE *geoms, std::atomic<long long> *geompos_in, cha
v.string_value = "LineString";
} else if (sf.t == mvt_polygon) {
v.string_value = "Polygon";
} else if (sf.t == mvt_spline) {
v.string_value = "Spline";
}

attributes.insert(std::pair<std::string, mvt_value>("$type", v));
Expand Down
16 changes: 13 additions & 3 deletions write_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
state.json_end_array();
}
}
} else if (feat.type == VT_LINE) {
} else if (feat.type == VT_LINE || feat.type == VT_SPLINE) {
int movetos = 0;
for (size_t i = 0; i < ops.size(); i++) {
if (ops[i].op == VT_MOVETO) {
Expand All @@ -555,7 +555,12 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y

if (movetos < 2) {
state.json_write_string("type");
state.json_write_string("LineString");

if (feat.type == VT_LINE) {
state.json_write_string("LineString");
} else {
state.json_write_string("Spline");
}

for (auto c : coordinate_writers) {
state.json_write_string(c.tag);
Expand All @@ -569,7 +574,12 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
}
} else {
state.json_write_string("type");
state.json_write_string("MultiLineString");

if (feat.type == VT_LINE) {
state.json_write_string("MultiLineString");
} else {
state.json_write_string("MultiSpline");
}

for (auto c : coordinate_writers) {
state.json_write_string(c.tag);
Expand Down

0 comments on commit cf81880

Please sign in to comment.