onthegomap / planetiler

Flexible tool to build planet-scale vector tilesets from OpenStreetMap data fast
Apache License 2.0
1.47k stars 115 forks source link

[FEATURE] Polygon centerlines #13

Open msbarry opened 3 years ago

msbarry commented 3 years ago

Currently the basemap profile uses lake centerlines from the unmaintained https://github.com/lukasmartinelli/osm-lakelines repo. It would be nice if flatmap could generate centerlines for polygons itself out of the box. In most cases you would probably want to fall back to a point label if the polygon is not elongated. It might also make sense to limit minzoom based on the length of the line or area of the polygon if it's a point so the entire text fits into the polygon.

msbarry commented 3 years ago

Here are a few implementations:

The standard approach appears to be:

  1. Densify the polygon
  2. Generate voronoi diagram
  3. Extract the line segment going down the middle
  4. Simplify

JTS provides utilities for each of those steps so it should be possible to just piece them together.

bdon commented 1 year ago

another possible approach: https://github.com/micycle1/JMedialAxis

vycius commented 7 months ago

Polygon center lines into can be implemented by leveraging the GeoTools library. Since PlaneTiler already uses org.geotools:gt-shapefile and org.geotools:gt-epsg-hsql. Incorporating the CenterLine::getCenterLine function from the org.geotools:gt-process-geometry library might be one of the easiest solutions.

Here's how I envision the implementation within PlaneTiler:

import org.geotools.process.geometry.CenterLine;

public Geometry computeCenterLine() {
   return CenterLine.getCenterLine(polygonGeometry);
}

Additionally, CenterLine::getCenterLine also takes density argument which might be also integrated into similar function.