How to use STUnion()
All, I have data for the water areas for a given state as geography data broken into two seperate tables. In each table I have multiple geography records. I need to combine all these data into one table. Can someone show me some SQL code that would combine do a union of polygons in one table with all polygons in another table? I can do that when there is one record in each table. Need some sample code on how to do that when I have multiple records in each table. thanks
November 11th, 2010 12:13pm

DECLARE @g geography; DECLARE @h geography; SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326); SET @h = geography::STGeomFromText('POLYGON((-122.351 47.656, -122.341 47.656, -122.341 47.661, -122.351 47.661, -122.351 47.656))', 4326); SELECT @g.STUnion(@h).ToString(); This might help you, Gaurav Gupta http://sqlservermsbiblog.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 12:21pm

Thank you. I should have been more clear. I appologize. I know how to use STUnion given two polygons as you suggested above. In my case, I have one table that has multiple polygons in the form of multiple records in that table. I have another table that includes multiple records each representing one or more polygons. I need to combine all these records into one table without carrying the borders of each polygon. Where each polygon touches aonther polygon, I need to get rid of the common points. In essence, I need to come up with the union of the polygons that touch. I also dont know which ones touch. I basically have to write SQL that does a union of all records in one table with all records of the the other table. Leaving the polygons untouched where the do not touch and combine them where they touch. That is what I do not know how to do! THank you
November 11th, 2010 2:25pm

Hi, Try the STSymDifference method, see http://msdn.microsoft.com/en-us/library/bb933903.aspx for the method syntax and example. See http://msdn.microsoft.com/en-us/library/bb933917.aspx for all available methods on Geography Instances. If this is not what you want, please illustrate your requirement so that we understand better. thanks, Jerry
Free Windows Admin Tool Kit Click here and download it now
November 15th, 2010 1:22am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics