polygon from line string

Topics: SharpMap v0.9 / v1.x
Apr 20, 2012 at 1:50 PM

hi , i search the better way to make a polygon from a closed collection of line string in a layer but not created in order.

i am not sur how to explain that in english but for each end point or of line string there a another line string with one of this end point.

i cannot just iterate in the collection and take all point to form the polygon a have to take all point in order to make a closed polygon.

 

any idea

thanks

Coordinator
Apr 20, 2012 at 3:23 PM
Edited Apr 20, 2012 at 6:48 PM

That is a functionality you cannot solve with sharpmap geometries. You need to use NTS to do that:

  • Reference SharpMap.Extensions
  • Convert your set of SharpMap.LineStrings to a set of IGeometry.LineStrings.
  • var nodedContours = new System.Collections.Generic.Collection<IGeometry>();
    var geomNoder = new NetTopologySuite.Noding.SnapRound.GeometryNoder(new PrecisionModel(0.1d));
    
    foreach (var c in geomNoder.Node(Contours))
        nodedContours.Add(c);
    
    var polygonizer = new NetTopologySuite.Operation.Polygonize.Polygonizer();
    polygonizer.Add(nodedContours);
    
    foreach (var p in polygonizer.GetPolygons())
    {
        // do something
    }
    
    

Please note: The code has not seen a compiler, there may be typos.

Hth FObermaier

Apr 20, 2012 at 4:06 PM
Edited Apr 20, 2012 at 5:08 PM

NetTopologySuite.Noding.GeometryNoder seem do not exist

 

may be its just in v2

there a alternative for sharmap v0.9

Apr 20, 2012 at 5:51 PM

i have just skip that part of code

   SharpMap.Geometries.Polygon polySharp = new SharpMap.Geometries.Polygon();
   IList<SharpMap.Geometries.Geometry> geomColl = dragLineLayer.DataSource.GetGeometriesInView(dragLineLayer.Envelope);

   GisSharpBlog.NetTopologySuite.Geometries.Polygon poly = null;
   GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory _geometryFactory = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
   GisSharpBlog.NetTopologySuite.Geometries.LineString ntsLine1 = null;
   IList<GisSharpBlog.NetTopologySuite.Geometries.LineString> Contours = null;

   var polygonizer = new GisSharpBlog.NetTopologySuite.Operation.Polygonize.Polygonizer();

   if (geomColl.Count > 0)
   {
        try
        {
            foreach (SharpMap.Geometries.Geometry geo in geomColl)
            {

               SharpMap.Geometries.LineString line = geo as SharpMap.Geometries.LineString;
               if (line.Vertices[0].X != line.Vertices[1].X)
               {
                   ntsLine1 = GeometryConverter.ToNTSGeometry(line, _geometryFactory) as GisSharpBlog.NetTopologySuite.Geometries.LineString;
                   //Contours.Add(ntsLine1);
                   polygonizer.Add(ntsLine1);
                }
            }
         }
         catch (Exception)
         {
                            
            throw;
         }
                       

         /*  foreach (var c in geomNoder.Node(Contours))
                            nodedContours.Add(c);*/

                       
                        

       foreach ( GisSharpBlog.NetTopologySuite.Geometries.Polygon p in polygonizer.Polygons)
       {
           poly = p;
       }


       polySharp = GeometryConverter.ToSharpMapGeometry(poly as GisSharpBlog.NetTopologySuite.Geometries.Geometry) as SharpMap.Geometries.Polygon;
Apr 20, 2012 at 5:52 PM

by the way this can be done for plotted point,

if have have a lot of point in map and i want to make the contour  ??

thinks a lot you have make my weekend

Apr 20, 2012 at 6:06 PM

shit that dont alwas work

a have 94 Dangle but 0 polygone

the fist test a made that was good for 5 Dangle that give a polygon

its missing somethings

Coordinator
Apr 20, 2012 at 6:48 PM

That is what you need the noder for (it is in NetTopologySuite.Noding.Snapround).

If it is not, I urge you to update to the latest version.

If you only have dangles, you need to add a frame around your area of interest. Be sure to make it a little smaller so that it actually intersects your linework.

Hth FObermaier

Apr 21, 2012 at 2:20 AM

when you talk of the last version you talk about sharmap....

Coordinator
Apr 21, 2012 at 5:57 PM

No, you can replace your NTS version with the one provided via nuget.

You need to update your NTSGeometryConverter/-Provider (remove GisSharpBlog namespace)

There may be more to it, but it is definately managable.

Hth FObermaier

Apr 22, 2012 at 3:20 PM

ok and ther is a reason why its not done in shapmap v0.9

Apr 23, 2012 at 12:26 PM

how i do to get version from nuget

Developer
Apr 23, 2012 at 2:42 PM

install nuget package manager from vs2010 extension manager, or from here: http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c . Here (http://nuget.codeplex.com/) you can see how to use the manager, but, simply, you must search for 'nettopologysuite' package.

Apr 23, 2012 at 2:57 PM
Edited Apr 23, 2012 at 6:40 PM

ok , only one trouble i dont have visual studio 2010 ....

i will make a try from source

Developer
Apr 24, 2012 at 6:27 AM

you can take the latest release from here: http://goo.gl/A6XCa

Apr 27, 2012 at 5:33 PM

i have make a try with nts v. 1.12 but ther was no geometry.envellope, and that make some bug, but with the v. 1.11 that seem to work

Apr 27, 2012 at 6:15 PM
Edited Apr 28, 2012 at 2:06 AM

that really not done that i need, or i not done the right things there is a way i can send you a image