Fix count accumulation in overzoom (#272)

* Fix count accumulation in overzoom

* Add test

* Increment version and changelog
This commit is contained in:
Erica Fischer
2024-09-24 23:55:43 -07:00
committed by GitHub
parent c5f2f0da34
commit 4822d02f24
7 changed files with 55 additions and 9 deletions
+4
View File
@@ -1,3 +1,7 @@
# 2.62.4
* Fix accumulation of count and mean in overzoom
# 2.62.3
* Summary statistics with --accumulate-numeric-attributes make it from tiling through to binning
+6
View File
@@ -608,6 +608,12 @@ accumulate-test:
test `./tippecanoe-decode -c tests/pbf/bins-0-0-0.pbf 0 0 0 | grep clustered:unrelated | wc -l` == 0
# the cluster sizes still add up to the 243 original features
test `./tippecanoe-decode -c tests/pbf/bins-0-0-0.pbf 0 0 0 | sed 's/.*clustered:cluster_size": //' | awk '{sum += $$1} END {print sum}'` == 243
#
#
# A tile where the counts and means were previously wrong:
./tippecanoe-overzoom --accumulate-numeric-attributes=felt -m -o tests/pbf/yearbuilt-accum.pbf tests/pbf/yearbuilt.pbf 0/0/0 0/0/0
./tippecanoe-decode tests/pbf/yearbuilt-accum.pbf 0 0 0 > tests/pbf/yearbuilt-accum.pbf.json.check
cmp tests/pbf/yearbuilt-accum.pbf.json.check tests/pbf/yearbuilt-accum.pbf.json
join-filter-test: tippecanoe tippecanoe-decode tile-join
# Comes out different from the direct tippecanoe run because null attributes are lost
+2
View File
@@ -159,9 +159,11 @@ void preserve_attribute(attribute_op const &op, std::string const &key, serial_v
s.count = 2;
attribute_accum_state.insert(std::pair<std::string, accum_state>(key, s));
full_values[i].type = mvt_double;
full_values[i].s = std::to_string(s.count);
} else { // already present, incrementing
state->second.count += 1;
full_values[i].type = mvt_double;
full_values[i].s = std::to_string(state->second.count);
}
return;
+30 -3
View File
@@ -1186,13 +1186,18 @@ static void preserve_numeric(const std::string &key, const mvt_value &val, /
// it is the wrong one.
std::string outkey = key;
bool starting_from_accumulation;
if (starts_with(outkey, accumulate_numeric + ":")) {
std::string prefix = accumulate_numeric + ":" + op.first + ":";
if (starts_with(outkey, prefix)) {
outkey = outkey.substr(prefix.size());
starting_from_accumulation = true; // from a subaccumulation
} else {
continue; // to next operation
}
} else {
starting_from_accumulation = false; // from a plain value
}
// and then put it back on for the output field
std::string prefixed = accumulate_numeric + ":" + op.first + ":" + outkey;
@@ -1208,11 +1213,18 @@ static void preserve_numeric(const std::string &key, const mvt_value &val, /
// not present at all, so copy our value to the prefixed output
numeric_out_field.emplace(prefixed, full_keys.size());
full_keys.push_back(prefixed);
if (op.second == op_count) {
if (starting_from_accumulation) {
// copy our count
full_values.push_back(mvt_value_to_serial_val(val));
} else {
// new count of 1
serial_val sv;
sv.type = mvt_double;
sv.s = "1";
full_values.push_back(sv);
}
} else {
full_values.push_back(mvt_value_to_serial_val(val));
}
@@ -1220,24 +1232,39 @@ static void preserve_numeric(const std::string &key, const mvt_value &val, /
// exists unprefixed, so copy it, and then accumulate on our value
numeric_out_field.emplace(prefixed, full_keys.size());
full_keys.push_back(prefixed);
if (op.second == op_count) {
serial_val sv;
sv.type = mvt_double;
sv.s = "1";
if (starting_from_accumulation) {
// sum our count onto the existing 1
sv.s = std::to_string(1 + mvt_value_to_long_long(val));
} else {
// sum our 1 onto the existing 1
sv.s = "2";
}
full_values.push_back(sv);
} else {
full_values.push_back(full_values[out_attr->second]);
}
preserve_attribute(op.second, prefixed, mvt_value_to_serial_val(val), full_keys, full_values, attribute_accum_state);
}
}
} else {
// exists, so accumulate on our value
if (op.second == op_count) {
if (starting_from_accumulation) {
// sum our count onto the existing count
full_values[prefixed_attr->second].s = std::to_string(atoll(full_values[prefixed_attr->second].s.c_str()) + mvt_value_to_long_long(val));
} else {
full_values[prefixed_attr->second].s = std::to_string(atoll(full_values[prefixed_attr->second].s.c_str()) + 1);
}
} else {
preserve_attribute(op.second, prefixed, mvt_value_to_serial_val(val), full_keys, full_values, attribute_accum_state);
}
}
}
}
}
static bool should_keep(std::string const &key,
std::set<std::string> const &keep,
+7
View File
@@ -0,0 +1,7 @@
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "parsed", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "id": 510, "properties": { "blklot": "0858005", "block_num": "0858", "from_st": "222", "landuse": "RESIDENT", "lot_num": "005", "mapblklot": "0858005", "st_type": "ST", "street": "WALLER", "to_st": "222", "bldgsqft": 1765, "cie": 0, "med": 0, "mips": 0, "objectid": 11031, "pdr": 0, "resunits": 1, "retail": 0, "shape_area": 2279.71121678, "shape_leng": 212.495847301, "total_uses": 0, "visitor": 0, "yrbuilt": 1900, "felt:count:bldgsqft": 1134, "felt:max:bldgsqft": 517232, "felt:min:bldgsqft": 0, "felt:sum:bldgsqft": 4857699, "felt:count:cie": 1134, "felt:max:cie": 20780, "felt:min:cie": 0, "felt:sum:cie": 159842, "felt:count:med": 1134, "felt:max:med": 13747, "felt:min:med": 0, "felt:sum:med": 65490, "felt:count:mips": 1134, "felt:max:mips": 35150, "felt:min:mips": 0, "felt:sum:mips": 493890, "felt:count:objectid": 1134, "felt:max:objectid": 155370, "felt:min:objectid": 10714, "felt:sum:objectid": 38161243, "felt:count:pdr": 1134, "felt:max:pdr": 18000, "felt:min:pdr": 0, "felt:sum:pdr": 259718, "felt:count:resunits": 1134, "felt:max:resunits": 94, "felt:min:resunits": 0, "felt:sum:resunits": 4269, "felt:count:retail": 1134, "felt:max:retail": 12898, "felt:min:retail": 0, "felt:sum:retail": 425966, "felt:count:shape_area": 1134, "felt:max:shape_area": 187422.348941, "felt:min:shape_area": 824.484455232, "felt:sum:shape_area": 3770890.8948438765, "felt:count:shape_leng": 1134, "felt:max:shape_leng": 2741.43546213, "felt:min:shape_leng": 121.331962321, "felt:sum:shape_leng": 306327.034212475, "felt:count:total_uses": 1134, "felt:max:total_uses": 63028, "felt:min:total_uses": 0, "felt:sum:total_uses": 1425446, "felt:count:visitor": 1134, "felt:max:visitor": 15000, "felt:min:visitor": 0, "felt:sum:visitor": 20540, "felt:count:yrbuilt": 1134, "felt:max:yrbuilt": 2014, "felt:min:yrbuilt": 1878, "felt:sum:yrbuilt": 2165833, "felt:cluster_size": 113, "felt:mean:bldgsqft": 4283.685185185185, "felt:mean:cie": 140.9541446208113, "felt:mean:med": 57.75132275132275, "felt:mean:mips": 435.5291005291005, "felt:mean:objectid": 33651.8897707231, "felt:mean:pdr": 229.02821869488538, "felt:mean:resunits": 3.7645502645502648, "felt:mean:retail": 375.63139329805997, "felt:mean:shape_area": 3325.3006127371047, "felt:mean:shape_leng": 270.1296597993607, "felt:mean:total_uses": 1257.0070546737214, "felt:mean:visitor": 18.112874779541447, "felt:mean:yrbuilt": 1909.905643738977 }, "geometry": { "type": "Point", "coordinates": [ -122.343750, 37.718590 ] } }
,
{ "type": "Feature", "id": 514, "properties": { "blklot": "0858003", "block_num": "0858", "from_st": "210", "landuse": "MIXRES", "lot_num": "003", "mapblklot": "0858003", "st_type": "ST", "street": "WALLER", "to_st": "210", "bldgsqft": 3050, "cie": 0, "med": 0, "mips": 1678, "objectid": 10950, "pdr": 0, "resunits": 2, "retail": 0, "shape_area": 1885.04187192, "shape_leng": 201.483365997, "total_uses": 1678, "visitor": 0, "yrbuilt": 1900, "felt:cluster_size": 1 }, "geometry": { "type": "Point", "coordinates": [ -122.343750, 37.718590 ] } }
] }
] }
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#define VERSION "v2.62.3"
#define VERSION "v2.62.4"
#endif