I would like to know if it's possible to intersect feature datasets (multipolygon, polygon, multilinestring and linestring) to get a result as a set of linestrings being split at each intersection point.

enter image description here

Output should give:

  • 4 linestrings for the square
  • 3 linestrings for the line
  • 2 linestrings for the polygon
  • 1
    [ST_Intersection][1] [1]: postgis.refractions.net/docs/ST_Intersection.html Aug 25, 2014 at 16:50
  • 1
    To clarify, are you interested solely in the line portions of the features that fall inside the square, or do you want all possible intersections? The former would equal 1 linestring each for the line and polygon. The latter would equal 1 linestring for the line feature, and 2 for the overlapping polygon features. Also, what is your desired use for the result? Do you wish to be able to relate back to the original features? Aug 25, 2014 at 17:52
  • @GetSpatial - I am looking for all possible intersections in order to be able to reconstruct the original features from the output linestrings later. See edit for number of linestrings needed in output Aug 25, 2014 at 17:55
  • Just to be sure I'm reading this correctly. You want to be able to reconstruct the original features, so you are going to want to maintain some identity of which features the parts belonged to. That changes the functions you will want to use. Aug 25, 2014 at 18:12
  • @GetSpatial, yes, so I suppose I have to add a field that will contains the original feature Id Aug 25, 2014 at 19:09

1 Answer 1


First, for polygons, you want the outer boundary of the polygon as a line using ST_Boundary. Then you want a combination of ST_Intersection and ST_SymDifference

So something like (untested):

WITH firststep AS( SELECT id, ST_BOUNDARY(geom) AS boundary
FROM polygons)

SELECT p.id, ST_Intersection(boundary, geom), o.id
FROM firststep p
INNER JOIN othergeoms o ON ST_INTERSECTS(boundary, geom)


SELECT p.id, ST_SymDifference(boundary, geom), o.id
FROM firststep p
INNER JOIN othergeoms o ON ST_INTERSECTS(boundary, geom)

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.