how to do that

Topics: Italiano
Sep 27, 2012 at 6:01 PM

i have that code

 IList<Point> PointColl = new List<Point>();

foreach (DataRow drPoint in dsCoordinnate.Tables[0].Rows)
            {
                string X = drPoint["X"].ToString().Replace(".", ",");
                string Y = drPoint["Y"].ToString().Replace(".", ",");

                if (!string.IsNullOrEmpty(X) && !string.IsNullOrEmpty(Y))
                {
                    pointCoordinate[0] = double.Parse(X);
                    pointCoordinate[1] = double.Parse(Y);
                }

                if (pointCoordinate[0] != pointCoordinate[1] && pointCoordinate[0] != 0)
                {
                    newPoint = new Point(pointCoordinate[0], pointCoordinate[1]);
                    PointColl.Add(newPoint);
                }
            }

            LinearRing extRing = new LinearRing(PointColl);
            

            Polygon newPolygon = new Polygon(extRing);


how i can do that now with geoapi/nts geometry ?? 
thanks 
Developer
Sep 28, 2012 at 6:44 AM

be sure to replace any reference to SharpMap Geometries (Point, LinearRing, Polygon) with GeoAPI/NTS one, and you've done.

Coordinator
Sep 28, 2012 at 6:44 AM

Hello longuard,

  1. build an array of GeoAPI.Coordinates from your datatable (var coords = new GeoAPI.Geometries.Coordinate[...]).
  2. Create a GeometryFactory (var gf = new NetTopologySuite.Geometries.GeometryFactory();)
  3. Create a GeoAPI.Geometries.ILinearRing using that factory (var shell = gf.CreateLinearRing(coords);)
  4. Create a GeoAPI.Geometries.IPolygon using the factory (var polygon = gf.CreatePolygon(shell, null);)

Hth FObermaier

Sep 28, 2012 at 10:44 AM
Edited Sep 28, 2012 at 10:56 AM

There is what i have done, you'll not change any that, i still have for 2 day to make change like that and a week to make test

but its a good idea to dont have to transform between nts and sharmap geo

when a merge between geoapi and nts ...

 Collection vertices = new Collection();


            foreach (DataRow drPoint in dsCoordinnate.Tables[0].Rows)
            {
                string X = drPoint["X"].ToString().Replace(".", ",");
                string Y = drPoint["Y"].ToString().Replace(".", ",");

                if (!string.IsNullOrEmpty(X) && !string.IsNullOrEmpty(Y))
                {
                    pointCoordinate[0] = double.Parse(X);
                    pointCoordinate[1] = double.Parse(Y);
                }

                if (pointCoordinate[0] != pointCoordinate[1] && pointCoordinate[0] != 0)
                {
                    newPoint = new Point(pointCoordinate[0], pointCoordinate[1]);
                    vertices.Add(newPoint);
                }
            }

            // pour être sur d'avoir un polygon valide je remet le premier point a la fin
            string XLast = dsCoordinnate.Tables[0].Rows[0]["X"].ToString().Replace(".", ",");
            string YLast = dsCoordinnate.Tables[0].Rows[0]["Y"].ToString().Replace(".", ",");

            if (!string.IsNullOrEmpty(XLast) && !string.IsNullOrEmpty(YLast))
            {
                pointCoordinate[0] = double.Parse(XLast);
                pointCoordinate[1] = double.Parse(YLast);
            }

            if (pointCoordinate[0] != pointCoordinate[1] && pointCoordinate[0] != 0)
            {
                newPoint = new Point(pointCoordinate[0], pointCoordinate[1]);
                vertices.Add(newPoint);
            }

            var gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            GisSharpBlog.NetTopologySuite.Geometries.LinearRing extRing = gf.CreateLinearRing(vertices.ToArray()) as GisSharpBlog.NetTopologySuite.Geometries.LinearRing;
            
            Polygon newPolygon = new Polygon(extRing);
Coordinator
Sep 28, 2012 at 7:47 PM

??? Do you want any more advice on this topic or do you want to puzzle yourself ???

Sep 28, 2012 at 8:30 PM

just if  you have a better way to do the same