[postgis-users] How to Convert POLYGON to LINESTRING?

Markus Schaber schabi at logix-tt.com
Mon Sep 25 11:17:23 PDT 2006


Hi, Bill,

Bill Thoen wrote:
> Is there a PostGIS function that will convert a POLYGON type to a
> LINESTRING? I'm trying to understand the details of geometries by taking
> one apart, but NumPoints() requires a LINESTRING and Geometry(the_geom,1)
> returns a POLYGON.

There's no 1:1 mapping of Linestrings and Polygons, because a Polygon
can contain several rings (the outer ring, and optional one or more
inner holes).

Boundary(geometry) will give you a MultiLineString with one LineString
for each ring, and a LineString in case there's only one Ring.

ExteriorRing(geometry) gives you the outer ring as a LineString.

NumInteriorRings(geometry) and InteriorRingN(geometry,integer) can be
used to access the inner rings.

HTH,
Markus
-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in Europe! www.ffii.org
www.nosoftwarepatents.org



More information about the postgis-users mailing list