From 62ee53992b6ab24d9e0e9ee1120556e20bdbb5a3 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 14 Jul 2017 17:23:41 -0700 Subject: [PATCH] Track how many features of each type are in each layer --- geojson.cpp | 19 +++++++++++++++++++ mbtiles.cpp | 6 ++++++ mbtiles.hpp | 7 +++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/geojson.cpp b/geojson.cpp index bc5f621..05b865f 100644 --- a/geojson.cpp +++ b/geojson.cpp @@ -295,10 +295,29 @@ int serialize_geometry(json_object *geometry, json_object *properties, json_obje if (ai != layermap->end()) { layer = ai->second.id; layername = tippecanoe_layername; + + if (mb_geometry[t] == VT_POINT) { + ai->second.points++; + } else if (mb_geometry[t] == VT_LINE) { + ai->second.lines++; + } else if (mb_geometry[t] == VT_POLYGON) { + ai->second.polygons++; + } } else { fprintf(stderr, "Internal error: can't find layer name %s\n", tippecanoe_layername.c_str()); exit(EXIT_FAILURE); } + } else { + auto fk = layermap->find(layername); + if (fk != layermap->end()) { + if (mb_geometry[t] == VT_POINT) { + fk->second.points++; + } else if (mb_geometry[t] == VT_LINE) { + fk->second.lines++; + } else if (mb_geometry[t] == VT_POLYGON) { + fk->second.polygons++; + } + } } size_t nprop = 0; diff --git a/mbtiles.cpp b/mbtiles.cpp index ab9aeb3..be64f17 100644 --- a/mbtiles.cpp +++ b/mbtiles.cpp @@ -378,6 +378,12 @@ std::map merge_layermaps(std::vectorsecond.maxzoom > out_entry->second.maxzoom) { out_entry->second.maxzoom = map->second.maxzoom; } + + out_entry->second.points += map->second.points; + out_entry->second.lines += map->second.lines; + out_entry->second.polygons += map->second.polygons; + + printf("%zu %zu %zu\n", out_entry->second.points, out_entry->second.lines, out_entry->second.polygons); } } diff --git a/mbtiles.hpp b/mbtiles.hpp index 6cb1bdc..fe0ac67 100644 --- a/mbtiles.hpp +++ b/mbtiles.hpp @@ -9,7 +9,7 @@ struct type_and_string { std::string string; size_t attribute_count = 0; - std::vector sample_values; + std::set sample_values; double min = INFINITY; double max = -INFINITY; @@ -21,7 +21,10 @@ struct layermap_entry { std::set file_keys; int minzoom; int maxzoom; - size_t feature_count = 0; + + size_t points = 0; + size_t lines = 0; + size_t polygons = 0; layermap_entry(size_t _id) { id = _id;