Any idea how to extract the centerline of the following polygon (Fig1) using PostGIS functions or Python modules? I was trying Voronoi Function but thats not helpful for this kind of shape. I want something like Fig2 blackline.
Any idea how to extract the centerline of the following polygon (Fig1) using PostGIS functions or Python modules? I was trying Voronoi Function but thats not helpful for this kind of shape. I want something like Fig2 blackline.
This may be a wrong tool for you, but you can do it simply with OpenJUMP and Skeletonizer plugin. Plugin can be downloaded from http://sourceforge.net/projects/jump-pilot/files/OpenJUMP_plugins/More%20Plugins/JUMP%20Skeletonizer%20Plugin/
Zip file contains a good manual. Plugin is meant for streams and water bodies but your polygon mimics a stream to me.
This is your polygon as I digitized it. Notice vertices in the center lines of inputs/outlets.
Entry points digitized on a separate layer. Points must snap to vertices on the polygon boundary.
Use the Skeletonizer tools and fill in the fields
Get the result
If your polygon is raster, digitize it.
Once your polygon is really a polygon :), a first solution lies, like @WhiteboxDev said, it's the straight skeleton, but it has the problem that, besides the centerline you want, it also returns a lot of segments radiating from that line to the border of your polygon. But if you have PostGIS 2.2+, you can use ST_ApproximateMedialAxis()
instead, which is what you want.
The library pygeoops has an implementation to calculate a centerline of a polygon: pygeoops.centerline. It also removes short branches, simplifies the result,... to get a "clean" result.
Sample script:
import pygeoops
import shapely
polygon = shapely.from_wkt("POLYGON ((0 0, 0 8, -2 10, 4 10, 2 8, 2 2, 10 2, 10 0, 0 0))")
centerline = pygeoops.centerline(polygon)
Result:
Disclaimer: I'm the developer of pygeoops
libSFCGAL.so
file in/usr/local/lib
directory but don't know how to bringST_StriaghtSkeleton()
in the db? Any idea?