-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge polygons in landuse layer. #1791
Conversation
This merges polygons in the landuse layer to improve tile size. Two different types of merging are used; at higher zooms we try to merge into as large a multipolygon as possible and at mid and low zooms we also do a dilate/erode step to try and blend together adjacent polygons. This can be extremely effective when merging large polygons separated by small spaces, such as paths within a forest.
# the buffer & clipping algorithms. | ||
- fn: vectordatasource.transform.drop_small_inners | ||
params: | ||
end_zoom: 15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why is this 1 more zoom at 15 (versus 14) than in v1.6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that we still had some tiles at zoom 13 & 14 which had quite a lot of grass
landuse. In the particular case I was looking at, they were all suburban lawns and, while the polygons couldn't be merged very well, they benefited from being merged into the same MultiPolygon.
So I added the second merge_polygon_features
, which does a simpler merge step at zooms 13 & 14. I extended the range of the drop_small_inners
to cover those zooms too, just to make sure we would be dropping any courtyards or cut-outs in those lawn features, or fields elsewhere.
For the lawns, I didn't get as substantial savings (only about 30% smaller for the layer - 15% smaller for the whole tile), and I figured we could just look at it when we have a global build and figure out whether this merging is doing what we want.
def _props_pre((shape, props, fid)): | ||
# drop area while merging, as we'll recalculate after. | ||
props.pop('area', None) | ||
if merge_min_zooms: | ||
props.pop('min_zoom', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the min_zoom
of the resulting polygon, I'm reading this as it's stripped off?
Could it be the min of the input min_zoom
values instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Perhaps this is answered in the new _props_merge
function below... but can you walk thru an example, please?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that's exactly what's happening. When _merge_features_by_property
runs, it calls our _props_pre
function for each feature, and whatever we return is the "key" used to group features to be merged. We pop
the min_zoom
off the properties so that the merge algorithm will merge adjacent polygons with different min_zoom
- which happens all the time in the patchwork of highly variable-sized fields in the 3dshapes import.
However, _merge_features_by_property
(now) also keeps the original properties, and passes the list of those into our _props_merge
function below, and the merged feature gets assigned whatever we return. The _props_merge
implementation I've used here takes the minimum of all the min_zoom
s, as this will guarantee that we see the merged feature at least at all the zooms of the biggest feature we queried from the database or RAWR tile.
The step-by-step run-through might be something like:
- We call
merge_polygon_features
on a layer with two features,[(shape1, props1, fid1), (shape2, props2, fid2)]
. merge_polygon_features
calls_merge_features_by_property
._merge_features_by_property
calls back intomerge_polygon_features
'_props_pre
for each feature, where we strip the min zoom. In this example,props1.pop('min_zoom') == props2.pop('min_zoom') == props
._merge_features_by_property
stores the features indexed by that result, so we get something like:{props: [(shape1, props1), (shape2, props2)]}
_merge_features_by_property
tries to mergeshape1
andshape2
, gettingshape_merged
_merge_features_by_property
calls back intomerge_polygon_features
'_props_merge
with[props1, props2]
, and we take the min of all themin_zoom
parameters, returningprops_merged
._merge_features_by_property
calls back intomerge_polygon_features
'_props_post
, where it resets thearea
onprops_merged
(and is why we don't bother with that in step 6)._merge_features_by_property
returns a new list of features:[(shape_merged, props_merged, some_fid)]
, wheresome_fid
is one of thefids
of one of the merged features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huge file savings, huzzah!
I had one minor question about min_zoom
(I think some minimum min_zoom
value should still be present on the output). Other than that, LGTM.
Agree that all the landuse / landcover polygons could be added to Bubble Wrap now that we have good coverage. I think they've been in Walkabout for a while... |
This merges polygons in the landuse layer to improve tile size. Two different types of merging are used; at higher zooms we try to merge into as large a multipolygon as possible and at mid and low zooms we also do a dilate/erode step to try and blend together adjacent polygons. This can be extremely effective when merging large polygons separated by small spaces, such as paths within a forest.
For example, tile
9/263/166
near Groningen, the Netherlands originally had a 663kBlanduse
layer, but this reduced to 84kB, a drop of 87%. The total tile size went from 859kB to 280kB, a drop of 67%. Of the remaining size, 155kB is roads.The vast majority of the features in this tile came from
kind: grass
polygons:It looks as if each individual field has been mapped as a separate feature (or rather, imported). There are many small gaps between adjacent polygons, often for small water courses or paths. This means it's hard enough to merge the geometries - and on top of that, the different sizes of adjacent features means that wildly different
min_zoom
values get set.Re-using the buffering merge implemented earlier for buildings in #1698 and allowing different
min_zoom
s to be merged together (it's generally purely area-based, unlike buildings), gives:Which still shows a lot of detail in the boundary, but has almost entirely removed small gaps and voids.
The irony is that the
grass
landuse kind doesn't even seem to be rendered by Bubble Wrap at zoom 10, so here's a screenshot of a slightly modified style:Connects to #1721.