This script reads polygon datasets such as i.e. the geographic regions from Natural Earth and extracts smoothed centerlines for better label placement. This method is used to create the label layer of EOX Maps
To do so, it basically creates a Voronoi diagram to get the polygon skeleton. Finally, the centerline is selected and smoothed.
Steps:
- Extract outline.
- Segmentize outline to get more evenly distributed outline points.
- Extract points.
- If there are too many points, simplify the segmentized outline and Extract points again.
- Create Voronoi diagram.
- Select all Voronoi edges which are inside the source polygon.
- Determine the best line.
- Smooth line.
Basic usage:
create_centerlines.py <input_file> <output_file>
Parameters:
--segmentize
: maximum length of line segment (default 0.5)--max_points
: maximum number of points allowed before generating the Voronoi diagram (huge influence on performance) (default 3000)--simplification
: stepwise simplification value until geometry has less than maximum number of points allowed (default 0.05)--smooth
: degree of smoothing to be applied to the final centerline (default 5)