# [postgis-users] How to get the centerline of a polygon?

Eric Yu ericyu at gmail.com
Fri Jan 18 07:54:45 PST 2008

```Thanks for your comments. The questions you asked are exactly what I faced
while I was searching for answers. It is easy to draw a centerline by human,
but I don't even know where to start. My initial idea was like this:

(Imagine we have a polygon, shaped like a rope, lying on the plane)
1. First we need to find the two ends of the rope
2. From the two "central points" of the two ends (if we can determine),
we can split the exterior ring of the rope into two line strings.
3. Along the two line strings, we can locate the points at 0.01, 0.02, 0.03, ...
with this method, maybe we can ignore the unmatched points on the two edges.

However, the first step is hard  (just as what you said about where to
"start" and "end").
I can't figure out a good way to do this.

In fact, the problem comes from here: I have a highway road network
(up/down line,
and ramp branching off, etc.) and I need to draw a simplified line
So I first use ST_Buffer() and then union the buffers into a
rope-shaped polygon.
And there comes the centerline problem.

Maybe there is some other way to achieve this?

Thanks!

Eric

On Jan 18, 2008 11:11 PM, Stephen Woodbridge <woodbri at swoodbridge.com> wrote:
>
> Eric Yu wrote:
> > Hi,
> >
> > Suppose I have a long shaped polygon, like river area or the road,
> > is it possible to get the centerline of the area using PostGIS?
> > Or with other GIS library/software? I searched and tried but failed to
> > get any solution.
>
> I think the problem to start with is how are you going to define what
> the center line of the polygon in algorithmic terms? Does the center
> line change if you rotate it 90 degrees? Assuming you had a center line
> of a polygon, how would the points of the centerline relate to the polygon.
>
> I assume you want some set of points that approximates a path between
> the two adjacent polygon virtual "edges", but polygons are made of
> multiple points and hence multiple edges so what points belong to which
> "edge". Also if the number of points does not match on the opposite
> "edge" how should that be handled? How does one determine what points
> belong to the "start" and "end" "edge of the polygon that the center
> line needs to "start" on and "end" on?
>
> If you can answer these questions clearly then it is possible to write
> an algorithm to do what you want. But just looking at the polygon and
> intuiting that there should be a centerline that follows some visual
> path the your mind perceives is kind of hard to deal with.
>
> -Steve W

```