question

asif.sha11 avatar image
asif.sha11 asked

Converting 'N' number of LineStrings to Single MultiLineString

. This is the Issue that we are facing , Followed Postgreql query is the existing one . We need an equivalent of this in SQLServer . SELECT ST_AsText(ST_Collect( ARRAY[ ST_GeomFromText('LINESTRING(1 2, 3 4)'), ST_GeomFromText('LINESTRING(3 4, 4 5)') ] )) As wktcollect; Look at the sample query . My input will be multiples of Linestrings . (Eg: LINESTRING(1 2, 3 4)) which comes dynamically . Result : you will get a clubbed Linestrings as single MultiLinestrings . (you can see result of this query in ScreenShot). Same result required in SQL server Kindly Suggest me Some way ![alt text][1] [1]: /storage/temp/1619-st_collect+-+postgresql.png
spatialgeometry
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
There seems to be no direct, corresponding spatial aggregate in SQL Server 2008 for ST_Collect. There is a solution using a tool kit that can be downloaded from Codeplex at : http://sqlspatialtools.codeplex.com/ - the equivalent funtion here is GeographyCollectionAggregate In SQL2012 onwards, there is also the [CollectionAggregate][1], which althought doesn't exactly give you a MULTILINESTRING, dos give you an equivalent GEOMETRYCOLLECTION : declare @g table (ls geometry) insert into @g values ('LINESTRING(1 2,3 4)') insert into @g values ('LINESTRING(3 4,4 5)') insert into @g values ('LINESTRING(6 7,8 9)') insert into @g values ('LINESTRING(10 17,18 19)') select geometry::CollectionAggregate(ls).ToString() from @g returns GEOMETRYCOLLECTION (LINESTRING (1 2, 3 4), LINESTRING (3 4, 4 5), LINESTRING (6 7, 8 9), LINESTRING (10 17, 18 19)) [1]: http://technet.microsoft.com/en-us/library/ff929285.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.