planetiler icon indicating copy to clipboard operation
planetiler copied to clipboard

[FEATURE] Polygon centerlines

Open msbarry opened this issue 4 years ago • 3 comments

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 avatar Oct 29 '21 00:10 msbarry

Here are a few implementations:

  • https://github.com/ungarj/label_centerlines
  • https://github.com/fitodic/centerline

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.

msbarry avatar Oct 29 '21 00:10 msbarry

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

bdon avatar Jan 26 '23 06:01 bdon

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.

vycius avatar Apr 22 '24 16:04 vycius