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.

Fig1: Polygon Shape Fig2: Centerline

  • 2
    You may want to look at this answer: gis.stackexchange.com/questions/29863/… I know it uses ArcGIS instead, but the approach may be useful. Sep 20, 2014 at 19:31
  • 2
    How about: postgis.net/docs/ST_StraightSkeleton.html ? Sep 22, 2014 at 23:15
  • @Jakub I am trying to configure SFCGAL (necessary for Skeleton function) to my already existing PostGIS db. Although I have installed the libSFCGAL.so file in /usr/local/lib directory but don't know how to bring ST_StriaghtSkeleton() in the db? Any idea?
    – Zia
    Sep 23, 2014 at 13:11
  • PostGIS needs to be compiled with SFCGAL support, but that's a diffrent question and not something I'm too familiar with. Sep 23, 2014 at 17:53
  • @Jakub Thanks. I have somehow solved this SFCGAL configuration by myself here
    – Zia
    Sep 24, 2014 at 7:35

3 Answers 3


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.

enter image description here

Entry points digitized on a separate layer. Points must snap to vertices on the polygon boundary.

enter image description here

Use the Skeletonizer tools and fill in the fields

enter image description here

Get the result

enter image description here

  • Unfortunately the jar file contains no manual. Could you please guide me how to add this plugin to my OpenJump-GUI?
    – Zia
    Sep 23, 2014 at 13:53
  • Look inside the zip, in skeletonizer-1.0\doc\ you should find file "SkeletonizerUserGuide.doc". Installation is done by dropping the jar files from skeletonizer-1.0\lib\ into lib\ext directory in OpenJUMP.
    – user30184
    Sep 23, 2014 at 14:01
  • However, it looks like most jars or newer versions of those are already included in OpenJUMP either in \lib or in \lib\ext. Perhaps it is best to copy just those which seem to be missing. Restart is needed after adding new jars.
    – user30184
    Sep 23, 2014 at 14:08
  • I found this jar here. But I am getting this error java.lang.Exception: Could not determine shapefile type - data is either all GeometryCollections or empty (Illegal State Exception) while running this Skeletonizer plugin
    – Zia
    Sep 23, 2014 at 14:34

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)


enter image description here

Disclaimer: I'm the developer of pygeoops

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.