How to calculate the centerline of a polygon in Python?

How to calculate the centerline of a polygon in Python?

There are two Python scripts. The first one, centerline.py handles the basic computations and can be used as a stand-alone script. The second one, shp2centerline.py has a more specific nature. The input is a Shapefile that contains polygons. It takes each polygon and calculates its centerline by calling the centerline.py.

How to generate a GeoJSON centerline in Python?

Generate geojson centerlines for network-like polygons (e.g. rivers) with Python/scipy.spatial/OGR-shapely – based on the centerline script from python-geospatial-analysis-cookbook. Use Git or checkout with SVN using the web URL.

How is the centerline class used in PyPi?

This library tries to solve this problem by creating the the polygon’s centerline using the Voronoi diagram. For more info on how to use this package, see the official documentation. The Centerline class that allows integration into your own workflow. Download the file for your platform.

How do you create a polygon in Matplotlib?

If you don’t want intersections, one way to achieve this is to order your co-ordinate pairs after some rotation rule. In the example above, I first define a center point (here just the average of all x- and y-values, respectively) and then compute the angle that each co-ordinate pair defines with that center point.

What happens if a polygon does not touch the centerline?

If the centerline does not touch any connecting features, the value in the field will be NULL. For best results, consider running the Eliminate Polygon Part tool first to remove small holes in the polygon features, for example, to remove holes from the middle of river polygons where island polygons exist.

What happens when you fill a hole in a polygon?

If a hole exists in the polygon, the centerline will branch around the hole, potentially creating two short centerline segments. Filling small holes before running Polygon To Centerline will create a single centerline through the section where a hole previously existed.

How to use the centerline package on GitHub?

For more info on how to use this package, see the official documentation. The Centerline class that allows integration into your own workflow.