# Polygon intersection and original borders

• ### Question

• Assume I have two polygons, A and B.  Polygon A is the "true" polygon of interest, and polygon B is a "clipping region".  I can easily get the polygon representing the intersection area, but I am curious if there is a simple way to find the "edges" (ring line segments) of the intersection area that are the same as the "edges" of polygon A.  Another way of looking at this would be to determine the "edges" of the intersection that were produced by polygon B.

It can probably be done by plodding thru the collection ring line segments of the and doing something, but I am afraid that would be slow process, tedious to write, and might suffer from some of the possible floating point calculation challenges.  Any chance of some relatively elegant and fast solution?
Wednesday, December 2, 2009 4:44 PM

• ```DECLARE @A geometry = 'POLYGON((0 0, 4 0, 6 5, 14 5, 16 0, 20 0, 13 20, 7 20, 0 0), (7 8, 13 8, 10 16, 7 8))';
DECLARE @B geometry = 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'```

So, A and B look like this:

If I understand you correctly, you want to find the edges of A that intersect B. So, you first identify the edges of A using STBoundary(), and then use STIntersection() to determine those that intersect B, like this:
`SELECT @A.STBoundary().STIntersection(@B);`
Which gives the following: Is this what you wanted?:

Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
• Marked as answer by Wednesday, December 2, 2009 5:22 PM
Wednesday, December 2, 2009 5:03 PM

### All replies

• ```DECLARE @A geometry = 'POLYGON((0 0, 4 0, 6 5, 14 5, 16 0, 20 0, 13 20, 7 20, 0 0), (7 8, 13 8, 10 16, 7 8))';
DECLARE @B geometry = 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'```

So, A and B look like this:

If I understand you correctly, you want to find the edges of A that intersect B. So, you first identify the edges of A using STBoundary(), and then use STIntersection() to determine those that intersect B, like this:
`SELECT @A.STBoundary().STIntersection(@B);`
Which gives the following: Is this what you wanted?:

Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
• Marked as answer by Wednesday, December 2, 2009 5:22 PM
Wednesday, December 2, 2009 5:03 PM
• Thanks a lot, that looks very promising!
Wednesday, December 2, 2009 5:22 PM