Answered by:
Why can a closed line not contain anything?
Question

I don't see the point of a closed line. I would have thought that a closed line could contain other geometries. However it seems only polygons can contain other geometries, which makes sense as it is 2 dimensional and a line is 1 dimensional.
Monday, December 10, 2007 3:04 PM
Answers

It sounds like you answered your own question? :) A closed line is useful for lots of cases where you only care about the boundaries of the object such as an island or a lake. If you extract the Rings from a Polygon (using STExteriorRing/STInteriorRingN on geometry, and RingN on geography), they will be represented as closed linestrings.
As a a closed linestring has no boundary, it will contain (STContains) any point on any of its edges.
Monday, December 10, 2007 7:54 PM
All replies

It sounds like you answered your own question? :) A closed line is useful for lots of cases where you only care about the boundaries of the object such as an island or a lake. If you extract the Rings from a Polygon (using STExteriorRing/STInteriorRingN on geometry, and RingN on geography), they will be represented as closed linestrings.
As a a closed linestring has no boundary, it will contain (STContains) any point on any of its edges.
Monday, December 10, 2007 7:54 PM 
Monday, December 10, 2007 7:58 PM

Yupthat's pretty much right.
Cheers,
Isaac
Tuesday, December 11, 2007 12:59 AM 
I have a SqlGeometry that is a polygon with donut holes cut out. All I really want is the outer perimeter as a polygon with no holes. What would the best approach be to get this as a polygon, given that STExteriorRing returns a LineString?
Friday, February 8, 2008 11:04 PM 
I can't think of anything other than the STExterior ring:
Code SnippetDECLARE @poly Geometry;
SET @poly = Geometry::STGeomFromText('POLYGON((0 0,0 10, 10 10, 10 0, 0 0),(2 2,8 2,8 8,2 8,2 2))',4326);SELECT @poly.STExteriorRing();
But as you say, this gives you a linestring though  NOT a polygon.
Instead you might be able to use the convex hull instead, if you need the polygon:
Code SnippetSELECT @poly.STConvexHull();That will only work if your polygon is convex though!
There is also a not very pretty way if doing it, by converting the exterior ring linestring to a polygon using some string manipulation (please tell me there's a better way to do this! :):
Code SnippetSELECT Geometry::STGeomFromText(REPLACE(@poly.STExteriorRing().ToString(),'LINESTRING (','POLYGON ((')+')',@poly.STSrid);
Saturday, February 9, 2008 3:52 AMAnswerer