locked
GeometryCollection help RRS feed

  • Question

  • Hi All,

     

    I have a sp that takes in a geometry type as a parameter.  Often times though not always, it gets a GeometryCollection.  Is there a way to union all items in it?  Maybe iterate through it somehow?  Thanks.

     

    jogi

    Monday, August 18, 2008 5:35 PM

Answers

  • Think I got it.

     

    this:

     

    DECLARE @GEO geometry

     

    SET @GEO = geometry::Parse('GEOMETRYCOLLECTION(POLYGON((-179 71, -20 71, -20 -5, -179 -5, -179 71)), POLYGON((-179 71, -20 71, -20 -5, -179 -5, -179 71)), POLYGON((-96 74, 63 74, 63 4, -96 4, -96 74)), POLYGON((-163 76, -3 76, -3 14, -163 14, -163 76)), POLYGON((-98 73, 61 73, 61 2, -98 2, -98 73)), POLYGON((-8 62, 151 62, 151 -27, -8 -27, -8 62)), POLYGON((21 66, 180 66, 180 -17, 21 -17, 21 66)), POLYGON((21 82, 180 82, 180 39, 21 39, 21 82)), POLYGON((-137 83, 180 83, 180 -50, -137 -50, -137 83)), POLYGON((-180 85, 180 85, 180 -85, -180 -85, -180 85)), POLYGON((-180 85, 180 85, 180 -85, -180 -85, -180 85)), POLYGON((-137 83, 180 83, 180 -50, -137 -50, -137 83)), POLYGON((-180 78, 137 78, 137 -64, -180 -64, -180 78)), POLYGON((-137 78, 180 78, 180 -65, -137 -65, -137 78)), POLYGON((-180 85, 180 85, 180 -85, -180 -85, -180 85)), POLYGON((-180 85, 180 85, 180 -85, -180 -85, -180 85)), POLYGON((-180 85, 180 85, 180 -85, -180 -85, -180 85)), POLYGON((-159 72, 159 72, 159 -72, -159 -72, -159 72)), POLYGON((-159 72, 159 72, 159 -72, -159 -72, -159 72)), POLYGON((-100 50, 59 50, 59 -44, -100 -44, -100 50)), POLYGON((-127 28, 32 28, 32 -61, -127 -61, -127 28)), POLYGON((-127 28, 32 28, 32 -61, -127 -61, -127 28)))')

     

    SET @GEO = @GEO.STUnion(@GEO);

    SELECT @GEO.ToString()

     

    seems to work.

     

    Monday, August 18, 2008 5:41 PM