question

AndrewIngall-7152 avatar image
0 Votes"
AndrewIngall-7152 asked EchoLiu-msft commented

Disolve Geometry

I have the following to buffer some lines by 10 metres, can anyone tell me how i can then dissolve these polygons where they overlap

 SELECT SHAPE.STBuffer(10) AS Expr1
 FROM     dbo.OS_MMT_TOPO_LINE
 WHERE  (style_code = 19)

Thanks

sql-server-transact-sql
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you have anyupdate?
Please also remember to accept the answers if they helped. Your action would be helpful to other users who encounter the same issue and read this thread.

0 Votes 0 ·

1 Answer

EchoLiu-msft avatar image
0 Votes"
EchoLiu-msft answered EchoLiu-msft edited

Hi @AndrewIngall-7152,

Welcome to the microsoft TSQL Q&A forum!

I spent some time researching your problem, but since I am not very familiar with this type of problem, I am not sure how to solve it. Here are the methods I searched for:

 using GeoAPI.Geometries;
 using NetTopologySuite.Geometries;
 using NetTopologySuite.Operation.Polygonize;
  public class GeometryRepair
     {
         /// <summary>
         /// Verify that the graph intersects itself
         /// </summary>
         /// <param name="geom"></param>
         /// <returns></returns>
         public static IGeometry validateGeometry(IGeometry geom)
         {
             if (geom is Polygon)
             {
                 if (geom.IsValid)
                 {
                     geom.Normalize();
                     return geom;
                 }
                 Polygonizer polygonizer = new Polygonizer();
                 addPolygon((Polygon)geom, polygonizer);
                 return toPolygonGeometry(polygonizer.GetPolygons(), geom.Factory as IGeometryFactory);
             }
             else if (geom is MultiPolygon)
             {
                 if (geom.IsValid)
                 {
                     geom.Normalize();
                     return geom;
                 }
                 Polygonizer polygonizer = new Polygonizer();
                 for (int n = geom.NumGeometries; n-- > 0;)
                 {
                     addPolygon((Polygon)geom.GetGeometryN(n), polygonizer);
                 }
                 return toPolygonGeometry(polygonizer.GetPolygons(), geom.Factory as IGeometryFactory);
             }
             else
             {
                 return geom;
             }
         }
    
         /// <summary>
         ///Add polygon
         /// </summary>
         /// <param name="polygon"></param>
         /// <param name="polygonizer"></param>
         static void addPolygon(Polygon polygon, Polygonizer polygonizer)
         {
             addLineString(polygon.ExteriorRing as LineString, polygonizer);
             for (int n = polygon.NumInteriorRings; n-- > 0;)
             {
                 var line = polygon.GetInteriorRingN(n) as LineString;
                 addLineString(line, polygonizer);
             }
         }
    
         /// <summary>
         /// Add line
         /// </summary>
         /// <param name="lineString"></param>
         /// <param name="polygonizer"></param>
         static void addLineString(LineString lineString, Polygonizer polygonizer)
         {
             if (lineString is LinearRing)
             {
                 lineString = lineString.Factory.CreateLineString(lineString.CoordinateSequence) as LineString;
             }
             Point point = lineString.Factory.CreatePoint(lineString.GetCoordinateN(0)) as Point;
             IGeometry toAdd = lineString.Union(point);
             polygonizer.Add(toAdd);
         }
    
         /// <summary>
         /// Convert a face object into a multi face
         /// </summary>
         /// <param name="polygons"></param>
         /// <param name="factory"></param>
         /// <returns></returns>
         static IGeometry toPolygonGeometry(ICollection<IGeometry> polygons, IGeometryFactory factory)
         {
             switch (polygons.Count)
             {
                 case 0:
                     return null;
                 case 1:
                     return polygons.First();
                 default:
                     List<IPolygon> mPolygons = new List<IPolygon>();
                     foreach (IGeometry g in polygons)
                     {
                         mPolygons.Add(g as IPolygon);
                     }
                     return factory.CreateMultiPolygon(mPolygons.ToArray()) as MultiPolygon;
             }
         }
     }


Regards
Echo


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.