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
Drop small inners #1180
Drop small inners #1180
Conversation
At mid and low zooms, polygons with lots of small inners cause problems for simplification, validation, intercut and MVT generation. Dropping these small holes means that some operations are slightly faster, and many are more robust.
vectordatasource/transform.py
Outdated
return None | ||
|
||
meters_per_pixel_area = calc_meters_per_pixel_area(zoom) | ||
area_tolerance = meters_per_pixel_area**2 * pixel_area |
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.
Do we need to square meters_per_pixel_area
here?
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.
Well spotted!
Yes, I seem to have been confused about whether that was a linear or area ratio. D'oh!
Fixed in 71488a5.
vectordatasource/transform.py
Outdated
polys = [] | ||
for g in shape.geoms: | ||
new_g = _drop_small_inners(g, area_tolerance) | ||
if new_g: |
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.
Is this ever falsey?
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.
Ah, yes, as an object it's probably always truthy. I've swapped that for what I really meant; does the remaining polygon have any area? I think we can omit validity checks, as deleting inners seems like it should always leave a valid polygon still valid.
Fixed in 71488a5.
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.
Ah, yes, as an object it's probably always truthy. I've swapped that for what I really meant; does the remaining polygon have any area?
Perhaps that's what shapely already does? I didn't check, but even so an area check is more explicit.
I think we can omit validity checks, as deleting inners seems like it should always leave a valid polygon still valid.
Yea, I had the same reasoning. 👍
Explicitly check for empty polygons, as a truthy Polygon object can still be empty.
At mid and low zooms, polygons with lots of small inners cause problems for simplification, validation, intercut and MVT generation. Dropping these small holes means that some operations are slightly faster, and many are more robust.