mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-04-10 04:19:54 +00:00
Use the right message numbers for splines; additional spline support
This commit is contained in:
parent
af66a8a118
commit
cf81880949
@ -51,7 +51,7 @@ 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++;
|
||||
@ -59,6 +59,8 @@ void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, u
|
||||
lines++;
|
||||
} else if (tile.layers[i].features[j].type == mvt_polygon) {
|
||||
polygons++;
|
||||
} else if (tile.layers[i].features[j].type == mvt_spline) {
|
||||
splines++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
12
mvt.cpp
12
mvt.cpp
@ -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) {
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
|
3
mvt.hpp
3
mvt.hpp
@ -52,7 +52,7 @@ enum mvt_geometry_type {
|
||||
mvt_point = 1,
|
||||
mvt_linestring = 2,
|
||||
mvt_polygon = 3,
|
||||
mvt_curve = 4,
|
||||
mvt_spline = 4,
|
||||
};
|
||||
|
||||
struct mvt_feature {
|
||||
@ -60,6 +60,7 @@ struct mvt_feature {
|
||||
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;
|
||||
|
@ -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++) {
|
||||
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 } } }
|
||||
]
|
||||
|
@ -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));
|
||||
@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
tile.cpp
2
tile.cpp
@ -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));
|
||||
|
@ -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) {
|
||||
@ -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);
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user