Reputation: 419
I have polygon table "PARCELA" with geometry column "GEOMETRY". How I can create multipolygon from these polygons?
Thanks!
Upvotes: 1
Views: 2003
Reputation: 11
Not sure if this is what you are looking for but: If you have polygon A and polygon B and you want to combine them as one polygon here is what I have used. What I needed was to get nordic countries together so I could print them on a map as one.
I have table countries with geometry column "geom" and column "ISO3" where country codes are located. So I am using ISO3 column as my primary key.
DECLARE @gtbl TABLE(g geometry, id INT)
INSERT INTO @gtbl
SELECT null,1
DECLARE @t TABLE(PK INT Identity(1,1), ISO3 VARCHAR(3))
INSERT INTO @t
Select ISO3 From countries WHERE ISO3 in ('FIN','SWE','NOR','DNK')
Declare @maxPK int; Select @maxPK = MAX(PK) From @t
Declare @pk int; Set @pk = 1
While @pk <= @maxPK
Begin
IF ((SELECT g FROM @gtbl) IS NULL)
BEGIN
UPDATE gtbl SET g = c.Geom.MakeValid()
FROM @gtbl gtbl, countries c WHERE c.ISO3 in (Select ISO3 From @T Where PK = @pk)
END
ELSE
BEGIN
UPDATE gtbl SET g = g.STUnion(c.Geom.MakeValid())
FROM @gtbl gtbl, countries c
WHERE c.ISO3 in (Select ISO3 From @T Where PK = @pk)
END
Select @pk = @pk + 1
End
SELECT * FROM @gtbl
Upvotes: 1