locked
Polygon from Linestring and Circularstring RRS feed

  • Question

  • Is it possible to combine multiple linestrings and circular strings to form a closed polygon in a SQL geometry field without losing data points (ie, converting the arcs described by circularstrings into segmented lines)?  If so, how?
    Friday, December 16, 2011 10:46 AM

Answers

  • Ah sorry, no. If you want to work with CircularStrings, CompoundCurves, or CurvePolygons then you'll have to use SQL Server 2012.
    twitter: @alastaira blog: http://alastaira.wordpress.com/
    • Marked as answer by Stephanie Lv Thursday, December 22, 2011 6:33 AM
    Friday, December 16, 2011 12:22 PM
    Answerer

All replies

  • You can combine LineStrings and CircularStrings together using STUnion() without worrying about converting the curves to lines first - the result will not "lose any data points".

    However, since LineStrings and CircularStrings are both themselves one dimensional, what you'll be left with is not a closed (Curve)Polygon, but a one-dimensional CompoundCurve representing only the exterior border of that Polygon:

    DECLARE @l geometry = 'MULTILINESTRING((0 0, 10 0), (10 0, 10 2), (10 2, 16 2))';
    DECLARE @c geometry = 'CIRCULARSTRING(0 0, 8 5, 16 2)';
    
    SELECT 
    @l.STUnion(@c);
    

     

    If you want to create a CurvePolygon from this curve, I don't think you can do so in T-SQL alone (well, not without using some coordinate-ripping text pattern matching) - you'll have to use the SqlGeometryBuilder or SqlGeographyBuilder class instead and construct the CurvePolygon programatically by adding each line/arc segment.


    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Friday, December 16, 2011 11:01 AM
    Answerer
  • I'm working with SQL Server 2008 (hadn't noticed that CIRCULARSTRING was 2011 when researching it - does 2008 happen to have a similar function?
    Friday, December 16, 2011 11:58 AM
  • Ah sorry, no. If you want to work with CircularStrings, CompoundCurves, or CurvePolygons then you'll have to use SQL Server 2012.
    twitter: @alastaira blog: http://alastaira.wordpress.com/
    • Marked as answer by Stephanie Lv Thursday, December 22, 2011 6:33 AM
    Friday, December 16, 2011 12:22 PM
    Answerer