Skip to content

Commit

Permalink
Avoid crash if the first bin gets clipped away (#294)
Browse files Browse the repository at this point in the history
* Avoid crash if the first bin gets clipped away

* Add test

* Update version and changelog
  • Loading branch information
e-n-f authored Nov 13, 2024
1 parent 794ae2b commit 6d46578
Show file tree
Hide file tree
Showing 6 changed files with 594 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.69.0

* Fix crash when the first bin gets clipped away

# 2.68.0

* Adds `--no-tile-compression` option to `tippecanoe-overzoom`
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ overzoom-test: tippecanoe-overzoom
./tippecanoe-decode tests/pbf/0-0-0-pop-0-0-0.pbf.out 0 0 0 > tests/pbf/0-0-0-pop-0-0-0.pbf.out.json.check
cmp tests/pbf/0-0-0-pop-0-0-0.pbf.out.json.check tests/pbf/0-0-0-pop-0-0-0.pbf.out.json
rm tests/pbf/0-0-0-pop-0-0-0.pbf.out tests/pbf/0-0-0-pop-0-0-0.pbf.out.json.check
# Verify fix for crash
./tippecanoe-overzoom '-o' tests/10188-crash/out.pbf '-t' '3/2/2' '--assign-to-bins' 'tests/10188-crash/bins.json' '--bin-by-id-list' 'felt:bin_features' '-b5' 'tests/10188-crash/2-0-0.pbf' '2/0/0'
rm tests/10188-crash/out.pbf

join-test: tippecanoe tippecanoe-decode tile-join
./tippecanoe -q -f -z12 -o tests/join-population/tabblock_06001420.mbtiles -YALAND10:'Land area' -L'{"file": "tests/join-population/tabblock_06001420.json", "description": "population"}'
Expand Down
35 changes: 20 additions & 15 deletions clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,8 @@ static void handle_closepath_from_mvt(drawvec &geom) {
}
}

static void feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer,
// returns true if a feature was output; false if it was clipped away
static bool feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer,
std::set<std::string> const &keep,
std::set<std::string> const &exclude,
std::vector<std::string> const &exclude_prefix,
Expand Down Expand Up @@ -1427,7 +1428,10 @@ static void feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
}

outlayer.features.push_back(std::move(outfeature));
return true;
}

return false;
}

static struct preservecmp {
Expand Down Expand Up @@ -1719,21 +1723,22 @@ mvt_tile assign_to_bins(mvt_tile &features,

for (size_t i = 0; i < outfeatures.size(); i++) {
if (outfeatures[i].size() > 1) {
feature_out(outfeatures[i], outlayer,
keep, exclude, exclude_prefix, attribute_accum,
accumulate_numeric, key_pool, buffer);
mvt_feature &nfeature = outlayer.features.back();
mvt_value val;
val.type = mvt_uint;
val.numeric_value.uint_value = outfeatures[i].size() - 1;

std::string attrname;
if (accumulate_numeric.size() == 0) {
attrname = "tippecanoe:count";
} else {
attrname = accumulate_numeric + ":count";
if (feature_out(outfeatures[i], outlayer,
keep, exclude, exclude_prefix, attribute_accum,
accumulate_numeric, key_pool, buffer)) {
mvt_feature &nfeature = outlayer.features.back();
mvt_value val;
val.type = mvt_uint;
val.numeric_value.uint_value = outfeatures[i].size() - 1;

std::string attrname;
if (accumulate_numeric.size() == 0) {
attrname = "tippecanoe:count";
} else {
attrname = accumulate_numeric + ":count";
}
outlayer.tag(nfeature, attrname, val);
}
outlayer.tag(nfeature, attrname, val);
}
}

Expand Down
Loading

0 comments on commit 6d46578

Please sign in to comment.