title: Calculating the outer boundary of several Geometry objects in SQL Server 2008
body: <p>I have lots of <code>Polygons</code> of datatype <code>Geometry</code> in SQL Server 2008. The image below shows how a select of all these Geometrys looks visualized.</p>
  
  <p><img src="https://i.stack.imgur.com/720hk.png" alt="Lots of Geometrys"></p>
  
  <p>What I need to do is create a Polygon which represents the outer boundary of all these polygons. So I used the <a href="https://stackoverflow.com/questions/8154672/how-to-combine-multiple-linestring-rows-into-a-single-row-collection">response given to a previous spatial question</a> I asked to create the following code:</p>
  
  <pre><code>DECLARE @test TABLE(geom GEOMETRY);
  
  INSERT INTO @test SELECT geom FROM ForceBoundary
  
  DECLARE @geom GEOMETRY
  SELECT @geom = (SELECT TOP 1 geom FROM @test)
  SELECT @geom = @geom.STUnion(geom) FROM @test
  
  SELECT @geom
  </code></pre>
  
  <p>This produced the following result, which has <em>cracks</em> in it due to holes between the polygons:</p>
  
  <p><img src="https://i.stack.imgur.com/vzlEu.png" alt="Combined polygons with cracks"></p>
  
  <p>So I updated my query with the following change:</p>
  
  <pre><code>INSERT INTO @test SELECT geom.Reduce(0.001).STBuffer(100) FROM ForceBoundary
  </code></pre>
  
  <p>Which improved the result, however it's not solving the issue completely and it also damages the outer boundary accuracy.</p>
  
  <p><img src="https://i.stack.imgur.com/Wukle.png" alt="Combined polygons with less cracks"></p>
  
  <p><strong>What is the correct way to achieve this?</strong> From looking through a list of the STxxxx functions I couldn't see one that seemed to provide the results I need?</p>