Skip to content
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

Clip tileset to a polygonal boundary #351

Merged
merged 5 commits into from
Feb 3, 2025
Merged

Clip tileset to a polygonal boundary #351

merged 5 commits into from
Feb 3, 2025

Conversation

bdon
Copy link
Member

@bdon bdon commented Jan 9, 2025

Implements #51

This is to address making non-global maps: for example, a map of a single continent, country, or city. The existing tooling has a path to doing this with pmtiles extract on a planet file, but this has a downside: the output tileset is not clipped to the AOI (area of interest) and shows the entire detail of the original source tileset at lower zoom levels.

Additionally, if the input OSM data has features that lie outside of the AOI, like oceans or roads, those extend beyond the boundary. This is not a fatal problem for many use cases, but we can do better in our tile generation program by clipping every feature to the AOI.

The challenges here are:

  • Making this fast: we need a efficient spatial representation of the clipping area, because running a constructive polygon operation like clip on 100% features is extremely slow
  • Robustness: constructive geometry operations can create self-intersections
  • MultiPolygon support: we need to support polygons with holes and multi polygons: for example, South Africa should not include Lesotho, and France should include overseas departments without pulling in lots of extra data.


public Clip(Stats stats, Geometry input) {
this.stats = stats;
var clipGeometry = latLonToWorldCoords(input).buffer(0.00001);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be configurable buffer size via arguments?

@wipfli
Copy link
Collaborator

wipfli commented Jan 12, 2025

Do you store the clipping mask in world coordinates (web mercator x y of the 0/0/0 tile) or do you store it in tile coordinates?

@wipfli
Copy link
Collaborator

wipfli commented Jan 12, 2025

I saw you have a covering tiles mechanism. I think you could get rid of this by using an STRtree https://locationtech.github.io/jts/javadoc/org/locationtech/jts/index/strtree/STRtree.html and use the tile bounds as an envelope for querying

* pass a GeoJSON feature polygon or multipolygon to clip the entire tileset.
* output for country or city sized basemaps looks better when zoomed out.
* implement an internal tiled index so there is minimal performance impact.
@bdon
Copy link
Member Author

bdon commented Feb 3, 2025

Results for small area in Monaco, expanding by 4/256 units:

CleanShot 2025-02-03 at 20 23 31@2x

Copy link

sonarqubecloud bot commented Feb 3, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
76.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@bdon bdon merged commit 0f6ba6b into main Feb 3, 2025
4 of 5 checks passed
@bdon bdon deleted the clip branch February 3, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants