Put all that behind an --accumulate-numeric flag

This commit is contained in:
Erica Fischer
2024-09-12 16:10:24 -07:00
parent 9739f342e6
commit e2cc71b42f
5 changed files with 29 additions and 17 deletions
+13 -9
View File
@@ -1081,7 +1081,8 @@ std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int n
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
std::vector<std::string> const &unidecode_data, double simplification,
double tiny_polygon_size, std::vector<mvt_layer> const &bins) {
double tiny_polygon_size, std::vector<mvt_layer> const &bins,
bool accumulate_numeric) {
std::vector<source_tile> decoded;
for (auto const &t : tiles) {
@@ -1107,7 +1108,7 @@ std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int n
decoded.push_back(out);
}
return overzoom(decoded, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins);
return overzoom(decoded, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);
}
struct tile_feature {
@@ -1120,9 +1121,11 @@ struct tile_feature {
size_t seq = 0;
};
bool accumulate_numeric = true; // XXX
static void feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer, std::set<std::string> const &keep, std::unordered_map<std::string, attribute_op> const &attribute_accum, std::shared_ptr<std::string> const &tile_stringpool) {
static void feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer,
std::set<std::string> const &keep,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
std::shared_ptr<std::string> const &tile_stringpool,
bool accumulate_numeric) {
// Add geometry to output feature
mvt_feature outfeature;
@@ -1565,7 +1568,8 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
std::vector<std::string> const &unidecode_data, double simplification,
double tiny_polygon_size, std::vector<mvt_layer> const &bins) {
double tiny_polygon_size, std::vector<mvt_layer> const &bins,
bool accumulate_numeric) {
mvt_tile outtile;
std::shared_ptr<std::string> tile_stringpool = std::make_shared<std::string>();
@@ -1691,7 +1695,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
if (flush_multiplier_cluster) {
if (pending_tile_features.size() > 0) {
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool);
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool, accumulate_numeric);
pending_tile_features.clear();
}
}
@@ -1748,7 +1752,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
}
if (pending_tile_features.size() > 0) {
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool);
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool, accumulate_numeric);
pending_tile_features.clear();
}
@@ -1781,7 +1785,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
std::string child = overzoom(sts,
nz + 1, nx * 2 + x, ny * 2 + y,
detail, buffer, keep, false, NULL,
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins);
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);
if (child.size() > 0) {
next_overzoomed_tiles->emplace_back(nx * 2 + x, ny * 2 + y);
}
+4 -2
View File
@@ -121,7 +121,8 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
std::vector<std::string> const &unidecode_data, double simplification,
double tiny_polygon_size, std::vector<mvt_layer> const &bins);
double tiny_polygon_size, std::vector<mvt_layer> const &bins,
bool accumulate_numeric);
std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
@@ -129,7 +130,8 @@ std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int n
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
std::vector<std::string> const &unidecode_data, double simplification,
double tiny_polygon_size, std::vector<mvt_layer> const &bins);
double tiny_polygon_size, std::vector<mvt_layer> const &bins,
bool accumulate_numeric);
draw center_of_mass_mp(const drawvec &dv);
+7 -1
View File
@@ -22,6 +22,7 @@ bool preserve_input_order = false;
std::unordered_map<std::string, attribute_op> attribute_accum;
std::vector<std::string> unidecode_data;
std::vector<mvt_layer> bins;
bool accumulate_numeric = false;
std::set<std::string> keep;
@@ -57,6 +58,7 @@ int main(int argc, char **argv) {
{"tiny-polygon-size", required_argument, 0, 's' & 0x1F},
{"source-tile", required_argument, 0, 't'},
{"assign-to-bins", required_argument, 0, 'b' & 0x1F},
{"accumulate-numeric-attributes", no_argument, 0, 'a' & 0x1F},
{0, 0, 0, 0},
};
@@ -127,6 +129,10 @@ int main(int argc, char **argv) {
assign_to_bins = optarg;
break;
case 'a' & 0x1F:
accumulate_numeric = true;
break;
default:
fprintf(stderr, "Unrecognized flag -%c\n", i);
usage(argv);
@@ -227,7 +233,7 @@ int main(int argc, char **argv) {
its.push_back(std::move(t));
}
std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins);
std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);
FILE *f = fopen(outfile, "wb");
if (f == NULL) {
+4 -4
View File
@@ -4,14 +4,14 @@
] }
,
{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_populated_places", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "FEATURECLA": "Populated place", "NAME": "San Francisco", "NAMEALT": "San Francisco-Oakland", "NAMEASCII": "San Francisco", "SOV0NAME": "United States", "SOV_A3": "USA", "ADM0NAME": "United States of America", "ADM0_A3": "USA", "ADM1NAME": "California", "ISO_A2": "US", "MEGANAME": "San Francisco-Oakland", "LS_NAME": "San Francisco1", "TIMEZONE": "America/Los_Angeles", "WIKIDATAID": "Q62", "NAME_EN": "San Francisco", "NAME_DE": "San Francisco", "NAME_ES": "San Francisco", "NAME_FR": "San Francisco", "NAME_PT": "São Francisco", "NAME_RU": "Сан-Франциско", "NAME_ZH": "旧金山", "NAME_AR": "سان فرانسيسكو", "NAME_BN": "সান ফ্রান্সিস্কো", "NAME_EL": "Σαν Φρανσίσκο", "NAME_HI": "सैन फ्रांसिस्को", "NAME_HU": "San Francisco", "NAME_ID": "San Francisco", "NAME_IT": "San Francisco", "NAME_JA": "サンフランシスコ", "NAME_KO": "샌프란시스코", "NAME_NL": "San Francisco", "NAME_PL": "San Francisco", "NAME_SV": "San Francisco", "NAME_TR": "San Francisco", "NAME_VI": "San Francisco", "NAME_FA": "سان فرانسیسکو", "NAME_HE": "סן פרנסיסקו", "NAME_UK": "Сан-Франциско", "NAME_UR": "سان فرانسسکو", "NAME_ZHT": "舊金山", "SCALERANK": 1, "NATSCALE": 300, "LABELRANK": 1, "ADM0CAP": 0, "WORLDCITY": 1, "MEGACITY": 1, "LATITUDE": 37.769196, "LONGITUDE": -122.417169, "POP_MAX": 3450000, "POP_MIN": 732072, "POP_OTHER": 27400, "RANK_MAX": 12, "RANK_MIN": 11, "MAX_POP10": 988636, "MAX_POP20": 1130999, "MAX_POP50": 1371285, "MAX_POP300": 4561697, "MAX_POP310": 4561697, "MAX_NATSCA": 300, "MIN_AREAKM": 218, "MAX_AREAKM": 1748, "MIN_AREAMI": 84, "MAX_AREAMI": 675, "MIN_PERKM": 126, "MAX_PERKM": 755, "MIN_PERMI": 78, "MAX_PERMI": 469, "MIN_BBXMIN": -122.516667, "MAX_BBXMIN": -122.516667, "MIN_BBXMAX": -122.358333, "MAX_BBXMAX": -121.733333, "MIN_BBYMIN": 37.191667, "MAX_BBYMIN": 37.575, "MIN_BBYMAX": 37.816667, "MAX_BBYMAX": 38.041667, "MEAN_BBXC": -122.301354, "MEAN_BBYC": 37.622288, "UN_FID": 570, "POP1950": 1855, "POP1955": 2021, "POP1960": 2200, "POP1965": 2361, "POP1970": 2529, "POP1975": 2590, "POP1980": 2656, "POP1985": 2805, "POP1990": 2961, "POP1995": 3095, "POP2000": 3236, "POP2005": 3387, "POP2010": 3450, "POP2015": 3544, "POP2020": 3684, "POP2025": 3803, "POP2050": 3898, "MIN_ZOOM": 2.7, "WOF_ID": 85922583, "CAPALT": 0, "NE_ID": 1159151479, "GEONAMESID": 5391959 }, "geometry": { "type": "Point", "coordinates": [ -122.399583, 37.784249 ] } }
{ "type": "Feature", "properties": { "SCALERANK": 1, "NATSCALE": 300, "LABELRANK": 1, "FEATURECLA": "Populated place", "NAME": "San Francisco", "NAMEALT": "San Francisco-Oakland", "NAMEASCII": "San Francisco", "ADM0CAP": 0, "WORLDCITY": 1, "MEGACITY": 1, "SOV0NAME": "United States", "SOV_A3": "USA", "ADM0NAME": "United States of America", "ADM0_A3": "USA", "ADM1NAME": "California", "ISO_A2": "US", "LATITUDE": 37.769196, "LONGITUDE": -122.417169, "POP_MAX": 3450000, "POP_MIN": 732072, "POP_OTHER": 27400, "RANK_MAX": 12, "RANK_MIN": 11, "MEGANAME": "San Francisco-Oakland", "LS_NAME": "San Francisco1", "MAX_POP10": 988636, "MAX_POP20": 1130999, "MAX_POP50": 1371285, "MAX_POP300": 4561697, "MAX_POP310": 4561697, "MAX_NATSCA": 300, "MIN_AREAKM": 218, "MAX_AREAKM": 1748, "MIN_AREAMI": 84, "MAX_AREAMI": 675, "MIN_PERKM": 126, "MAX_PERKM": 755, "MIN_PERMI": 78, "MAX_PERMI": 469, "MIN_BBXMIN": -122.516667, "MAX_BBXMIN": -122.516667, "MIN_BBXMAX": -122.358333, "MAX_BBXMAX": -121.733333, "MIN_BBYMIN": 37.191667, "MAX_BBYMIN": 37.575, "MIN_BBYMAX": 37.816667, "MAX_BBYMAX": 38.041667, "MEAN_BBXC": -122.301354, "MEAN_BBYC": 37.622288, "TIMEZONE": "America/Los_Angeles", "UN_FID": 570, "POP1950": 1855, "POP1955": 2021, "POP1960": 2200, "POP1965": 2361, "POP1970": 2529, "POP1975": 2590, "POP1980": 2656, "POP1985": 2805, "POP1990": 2961, "POP1995": 3095, "POP2000": 3236, "POP2005": 3387, "POP2010": 3450, "POP2015": 3544, "POP2020": 3684, "POP2025": 3803, "POP2050": 3898, "MIN_ZOOM": 2.7, "WIKIDATAID": "Q62", "WOF_ID": 85922583, "CAPALT": 0, "NAME_EN": "San Francisco", "NAME_DE": "San Francisco", "NAME_ES": "San Francisco", "NAME_FR": "San Francisco", "NAME_PT": "São Francisco", "NAME_RU": "Сан-Франциско", "NAME_ZH": "旧金山", "NAME_AR": "سان فرانسيسكو", "NAME_BN": "সান ফ্রান্সিস্কো", "NAME_EL": "Σαν Φρανσίσκο", "NAME_HI": "सैन फ्रांसिस्को", "NAME_HU": "San Francisco", "NAME_ID": "San Francisco", "NAME_IT": "San Francisco", "NAME_JA": "サンフランシスコ", "NAME_KO": "샌프란시스코", "NAME_NL": "San Francisco", "NAME_PL": "San Francisco", "NAME_SV": "San Francisco", "NAME_TR": "San Francisco", "NAME_VI": "San Francisco", "NE_ID": 1159151479, "NAME_FA": "سان فرانسیسکو", "NAME_HE": "סן פרנסיסקו", "NAME_UK": "Сан-Франциско", "NAME_UR": "سان فرانسسکو", "NAME_ZHT": "舊金山", "GEONAMESID": 5391959 }, "geometry": { "type": "Point", "coordinates": [ -122.399583, 37.784249 ] } }
] }
,
{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_roads", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "101", "ne_part": "ne_1d4_original", "continent": "North America", "level": "Federal", "scalerank": 4, "question": 0, "length_km": 11, "toll": 0, "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 118705, "expressway": 1, "min_zoom": 4, "min_label": 7 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.407351, 37.767933 ], [ -122.412586, 37.781841 ], [ -122.419496, 37.788760 ] ] } }
{ "type": "Feature", "properties": { "scalerank": 4, "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "101", "question": 0, "length_km": 11, "toll": 0, "ne_part": "ne_1d4_original", "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 118705, "continent": "North America", "expressway": 1, "level": "Federal", "min_zoom": 4, "min_label": 7 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.407351, 37.767933 ], [ -122.412586, 37.781841 ], [ -122.419496, 37.788760 ] ] } }
,
{ "type": "Feature", "properties": { "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "80", "ne_part": "ne_1d4_original", "continent": "North America", "level": "Interstate", "scalerank": 3, "question": 0, "length_km": 14, "toll": 1, "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 311505, "expressway": 1, "min_zoom": 3, "min_label": 6 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.407351, 37.767933 ], [ -122.388253, 37.785300 ], [ -122.386837, 37.786453 ] ] } }
{ "type": "Feature", "properties": { "scalerank": 3, "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "80", "question": 0, "length_km": 14, "toll": 1, "ne_part": "ne_1d4_original", "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 311505, "continent": "North America", "expressway": 1, "level": "Interstate", "min_zoom": 3, "min_label": 6 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.407351, 37.767933 ], [ -122.388253, 37.785300 ], [ -122.386837, 37.786453 ] ] } }
,
{ "type": "Feature", "properties": { "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "280", "ne_part": "ne_1d4_original", "continent": "North America", "level": "Interstate", "scalerank": 4, "question": 0, "length_km": 52, "toll": 0, "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 124805, "expressway": 1, "min_zoom": 4, "min_label": 7 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.405677, 37.752665 ], [ -122.407351, 37.767933 ] ] } }
{ "type": "Feature", "properties": { "scalerank": 4, "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "280", "question": 0, "length_km": 52, "toll": 0, "ne_part": "ne_1d4_original", "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 124805, "continent": "North America", "expressway": 1, "level": "Interstate", "min_zoom": 4, "min_label": 7 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.405677, 37.752665 ], [ -122.407351, 37.767933 ] ] } }
] }
] }
+1 -1
View File
@@ -712,7 +712,7 @@ struct tileset_reader {
t.y = parent_tile.y;
tv.push_back(std::move(t));
std::string ret = overzoom(tv, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map<std::string, attribute_op>(), unidecode_data, 0, 0, std::vector<mvt_layer>());
std::string ret = overzoom(tv, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map<std::string, attribute_op>(), unidecode_data, 0, 0, std::vector<mvt_layer>(), false);
return ret;
}