How to combine multiple LineString rows into a single row collection

前端 未结 2 1639
我寻月下人不归
我寻月下人不归 2021-01-19 06:19

I\'m using SQL Server 2008 and the Geometry datatype to store a list of UK a roads, which I\'ve imported from the Ordanance Survey STRATEGI data set.

Ea

相关标签:
2条回答
  • 2021-01-19 06:34

    Just use .STUnion

    BEGIN
    -- create a test table
    DECLARE @test TABLE(seg GEOMETRY);
    INSERT INTO @test VALUES(geometry::STGeomFromText('LINESTRING (0 0, 50 100)', 0))
    INSERT INTO @test VALUES(geometry::STGeomFromText('LINESTRING (50 100, 100 200)', 0))
    INSERT INTO @test VALUES(geometry::STGeomFromText('LINESTRING (100 200, 150 300)', 0))
    --SELECT seg.STAsText() FROM @test
    DECLARE @geom GEOMETRY
    SELECT @geom = (SELECT TOP 1 seg FROM @test)
    -- union all the linestring points
    SELECT @geom = @geom.STUnion([seg]) FROM @test
    -- do what you want with the results
    SELECT @geom
    print(@geom.STAsText())
    END
    
    0 讨论(0)
  • 2021-01-19 06:46

    In SQL 2012 you can use UnionAggregate

    SELECT geometry::UnionAggregate(shape) FROM Table
    

    or if you have a geography column

    SELECT geography ::UnionAggregate(shape) FROM Table
    
    0 讨论(0)
提交回复
热议问题