示例#1
0
        public void PolygonEnvelopeArea()
        {
            var coords      = new Coordinate[20];
            var rnd         = new Random();
            var center      = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];

            for (var i = 0; i < 19; i++)
            {
                coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
                var x = coords[i].X;
                var y = coords[i].Y;
                var c = new GeoAPI.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);
            var gf = new NetTopologySuite.Geometries.GeometryFactory();

            GeoAPI.Geometries.ILinearRing ring    = gf.CreateLinearRing(coordscheck);
            GeoAPI.Geometries.IPolygon    pgcheck = gf.CreatePolygon(ring, null);
            var pg   = new Polygon(coords);
            var area = pg.Envelope.Area();

            AssertExt.AreEqual15(area, pgcheck.Envelope.Area);
        }
示例#2
0
        public void Multipg()
        {
            Random rnd = new Random();

            Polygon[] pg = new Polygon[50];
            GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50];
            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            for (int i = 0; i < 50; i++)
            {
                Coordinate   center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                Coordinate[] coord  = new Coordinate[36];
                GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36];
                for (int ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    double x = coord[ii].X;
                    double y = coord[ii].Y;
                    GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35]       = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i]      = new Polygon(coord);
            }
            MultiPolygon mpg = new MultiPolygon(pg);

            GeoAPI.Geometries.IMultiPolygon mpgcheck = gf.CreateMultiPolygon(pgcheck);
            for (int ii = 0; ii < mpg.Coordinates.Count; ii++)
            {
                Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X);
                Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y);
            }
        }
示例#3
0
        public void Overlaps()
        {
            var rnd     = new Random();
            var pg      = new Polygon[50];
            var pgcheck = new GeoAPI.Geometries.IPolygon[50];
            var gf      = new NetTopologySuite.Geometries.GeometryFactory();
            var center  = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            for (var i = 0; i < 50; i++)
            {
                var coord       = new Coordinate[36];
                var coordscheck = new GeoAPI.Geometries.Coordinate[36];
                for (var ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    var x = coord[ii].X;
                    var y = coord[ii].Y;
                    var c = new GeoAPI.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35]       = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i]      = new Polygon(coord);
            }
            for (var t = 0; t < 49; t++)
            {
                var g      = pg[t].Overlaps(pg[t + 1]);
                var gcheck = pgcheck[t].Overlaps(pgcheck[t + 1]);
                Assert.AreEqual(g, gcheck);
            }
        }
        public void PolygonArea()
        {
            Coordinate[] coords = new Coordinate[20];
            Random       rnd    = new Random();
            Coordinate   center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[20];
            for (int i = 0; i < 19; i++)
            {
                coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
                double x = coords[i].X;
                double y = coords[i].Y;
                GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
                coordscheck[i] = c;
            }
            coordscheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);
            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            GeoAPI.Geometries.ILinearRing ring         = gf.CreateLinearRing(coordscheck);
            GeoAPI.Geometries.IPolygon    polygonCheck = gf.CreatePolygon(ring, null);
            Polygon pg        = new Polygon(coords);
            double  areaCheck = polygonCheck.Area;
            double  area      = pg.Area;

            Assert.AreEqual(area, areaCheck);
        }
示例#5
0
        public void EnvelopeHeight()
        {
            var rnd     = new Random();
            var pg      = new Polygon[50];
            var pgcheck = new GeoAPI.Geometries.IPolygon[50];
            var gf      = new NetTopologySuite.Geometries.GeometryFactory();

            for (var i = 0; i < 50; i++)
            {
                var center      = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var coord       = new Coordinate[36];
                var coordscheck = new GeoAPI.Geometries.Coordinate[36];
                for (var ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    var x = coord[ii].X;
                    var y = coord[ii].Y;
                    var c = new GeoAPI.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35]       = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i]      = new Polygon(coord);
            }
            var mpg      = new MultiPolygon(pg);
            var mpgcheck = gf.CreateMultiPolygon(pgcheck);

            Assert.AreEqual(mpg.Envelope.Height, mpgcheck.EnvelopeInternal.Height);
        }
示例#6
0
        public void Overlaps()
        {
            Random rnd = new Random();

            Polygon[] pg = new Polygon[50];
            GeoAPI.Geometries.IPolygon[] pgcheck = new GeoAPI.Geometries.IPolygon[50];
            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            for (int i = 0; i < 50; i++)
            {
                Coordinate[] coord = new Coordinate[36];
                GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[36];
                for (int ii = 0; ii < 36; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                    double x = coord[ii].X;
                    double y = coord[ii].Y;
                    GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
                    coordscheck[ii] = c;
                }
                coord[35]       = new Coordinate(coord[0].X, coord[0].Y);
                coordscheck[35] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y);
                GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
                pgcheck[i] = gf.CreatePolygon(ring, null);
                pg[i]      = new Polygon(coord);
            }
            for (int t = 0; t < 49; t++)
            {
                bool g      = pg[t].Overlaps(pg[t + 1]);
                bool gcheck = pgcheck[t].Overlaps(pgcheck[t + 1]);
                Assert.AreEqual(g, gcheck);
            }
        }
 public void PolygonEnvelopeMaxMin()
 {
     Coordinate[] coords = new Coordinate[20];
     Random rnd = new Random();
     Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
     GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[20];
     for (int i = 0; i < 19; i++)
     {
         coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
         double x = coords[i].X;
         double y = coords[i].Y;
         GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
         coordscheck[i] = c;
     }
     coordscheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coords[0].X, coords[0].Y);
     coords[19] = new Coordinate(coords[0].X, coords[0].Y);
     GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
     GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck);
     GeoAPI.Geometries.IPolygon pgcheck = gf.CreatePolygon(ring, null);
     Polygon pg = new Polygon(coords);
     AssertExt.AreEqual15(pg.Envelope.Maximum.X, pgcheck.EnvelopeInternal.MaxX);
     AssertExt.AreEqual15(pg.Envelope.Maximum.Y, pgcheck.EnvelopeInternal.MaxY);
     AssertExt.AreEqual15(pg.Envelope.Minimum.X, pgcheck.EnvelopeInternal.MinX);
     AssertExt.AreEqual15(pg.Envelope.Minimum.Y, pgcheck.EnvelopeInternal.MinY);
 }
        public void PolygonHoles()
        {
            Coordinate[] coords = new Coordinate[20];
            Random       rnd    = new Random();
            Coordinate   center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            // Shell Coordinates
            GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[20];
            for (int i = 0; i < 19; i++)
            {
                double x = center.X + Math.Cos((i * 10) * Math.PI / 10);
                double y = center.Y + (i * 10) * Math.PI / 10;
                coords[i]      = new Coordinate(x, y);
                coordscheck[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
            }
            coordscheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);


            // Shell Rings
            LinearRing ring = new LinearRing(coords);

            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            GeoAPI.Geometries.ILinearRing ringCheck = gf.CreateLinearRing(coordscheck);


            // Hole Coordinates
            GeoAPI.Geometries.ICoordinate[] coordsholecheck = new GeoAPI.Geometries.ICoordinate[20];
            Coordinate[] coordshole = new Coordinate[20];
            for (int i = 0; i < 20; i++)
            {
                double x = center.X + Math.Cos((i * 10) * Math.PI / 20);
                double y = center.Y + (i * 10) * Math.PI / 20;
                coordshole[i]      = new Coordinate(x, y);
                coordsholecheck[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
            }
            coordshole[19]      = new Coordinate(coordshole[0].X, coordshole[0].Y);
            coordsholecheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y);

            // Hole LinearRing Arrays
            LinearRing hole = new LinearRing(coordshole);

            ILinearRing[] holes = new ILinearRing[1];
            GeoAPI.Geometries.ILinearRing   holeCheck  = gf.CreateLinearRing(coordsholecheck);
            GeoAPI.Geometries.ILinearRing[] holescheck = new GeoAPI.Geometries.ILinearRing[1];
            holes[0]      = hole;
            holescheck[0] = holeCheck;


            Polygon pg = new Polygon(ring, holes);

            GeoAPI.Geometries.IPolygon polygonCheck = gf.CreatePolygon(ringCheck, holescheck);
            double areaCheck = polygonCheck.Area;
            double area      = pg.Area;

            Assert.AreEqual(area, areaCheck);
        }
示例#9
0
        public void PolygonHoles()
        {
            var coords = new Coordinate[20];
            var rnd    = new Random();
            var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            // Shell Coordinates
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];

            for (var i = 0; i < 19; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 10);
                var y = center.Y + (i * 10) * Math.PI / 10;
                coords[i]      = new Coordinate(x, y);
                coordscheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19]      = new Coordinate(coords[0].X, coords[0].Y);


            // Shell Rings
            var ring      = new LinearRing(coords);
            var gf        = new NetTopologySuite.Geometries.GeometryFactory();
            var ringCheck = gf.CreateLinearRing(coordscheck);


            // Hole Coordinates
            var coordsholecheck = new GeoAPI.Geometries.Coordinate[20];
            var coordshole      = new Coordinate[20];

            for (var i = 0; i < 20; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 20);
                var y = center.Y + (i * 10) * Math.PI / 20;
                coordshole[i]      = new Coordinate(x, y);
                coordsholecheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordshole[19]      = new Coordinate(coordshole[0].X, coordshole[0].Y);
            coordsholecheck[19] = new GeoAPI.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y);

            // Hole LinearRing Arrays
            var hole       = new LinearRing(coordshole);
            var holes      = new ILinearRing[1];
            var holeCheck  = gf.CreateLinearRing(coordsholecheck);
            var holescheck = new GeoAPI.Geometries.ILinearRing[1];

            holes[0]      = hole;
            holescheck[0] = holeCheck;


            var pg           = new Polygon(ring, holes);
            var polygonCheck = gf.CreatePolygon(ringCheck, holescheck);
            var areaCheck    = polygonCheck.Area;
            var area         = pg.Area;

            Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6);
        }
示例#10
0
        public void PolygonHoles()
        {
            var coords = new Coordinate[20];
            var rnd = new Random();
            var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            // Shell Coordinates
            var coordscheck = new GeoAPI.Geometries.Coordinate[20];
            for (var i = 0; i < 19; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 10);
                var y = center.Y + (i * 10) * Math.PI / 10;
                coords[i] = new Coordinate(x, y);
                coordscheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19] = new Coordinate(coords[0].X, coords[0].Y);


            // Shell Rings
            var ring = new LinearRing(coords);
            var gf = new NetTopologySuite.Geometries.GeometryFactory();
            var ringCheck = gf.CreateLinearRing(coordscheck);


            // Hole Coordinates
            var coordsholecheck = new GeoAPI.Geometries.Coordinate[20];
            var coordshole = new Coordinate[20];
            for (var i = 0; i < 20; i++)
            {
                var x = center.X + Math.Cos((i * 10) * Math.PI / 20);
                var y = center.Y + (i * 10) * Math.PI / 20;
                coordshole[i] = new Coordinate(x, y);
                coordsholecheck[i] = new GeoAPI.Geometries.Coordinate(x, y);
            }
            coordshole[19] = new Coordinate(coordshole[0].X, coordshole[0].Y);
            coordsholecheck[19] = new GeoAPI.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y);

            // Hole LinearRing Arrays
            var hole = new LinearRing(coordshole);
            var holes = new ILinearRing[1];
            var holeCheck = gf.CreateLinearRing(coordsholecheck);
            var holescheck = new GeoAPI.Geometries.ILinearRing[1];
            holes[0] = hole;
            holescheck[0] = holeCheck;


            var pg = new Polygon(ring, holes);
            var polygonCheck = gf.CreatePolygon(ringCheck, holescheck);
            var areaCheck = polygonCheck.Area;
            var area = pg.Area;
            Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6);
        }
示例#11
0
        public static GeoAPI.Geometries.IMultiPolygon ConvertTo(ESRI.ArcGIS.Geometry.IPolygon4 polygon)
        {
            GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon output = null;
            List <GeoAPI.Geometries.IPolygon> list = new List <GeoAPI.Geometries.IPolygon>();

            //IPolygon4.ExteriorRingBag should be used instead of IPolygon.QueryExteriorRings,
            //which does not work in .NET because of C-Style Arrays
            IGeometryBag exteriorRings = polygon.ExteriorRingBag;

            //For each exterior rings find the number of interior rings associated with it and print it
            IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry;

            exteriorRingsEnum.Reset();
            IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing;

            while (currentExteriorRing != null)
            {
                GeoAPI.Geometries.ILinearRing        shell = ConvertTo(currentExteriorRing);
                List <GeoAPI.Geometries.ILinearRing> holes = null;

                //IPolygon4.get_InteriorRingBag should be used instead of IPolygon.QueryInteriorRings,
                //which does not work in .NET because of C-Style Arrays
                IGeometryBag        interiorRings          = polygon.get_InteriorRingBag(currentExteriorRing);
                IGeometryCollection interiorRingCollection = interiorRings as IGeometryCollection;
                if (interiorRingCollection != null && interiorRingCollection.GeometryCount > 0)
                {
                    holes = new List <GeoAPI.Geometries.ILinearRing>();
                    int interiorRingsTotal = interiorRingCollection.GeometryCount;
                    for (int interiorRingIndex = 0; interiorRingIndex < interiorRingsTotal; interiorRingIndex++)
                    {
                        IRing currentInteriorRing = interiorRingCollection.get_Geometry(interiorRingIndex) as IRing;
                        if (currentInteriorRing != null)
                        {
                            holes.Add(ConvertTo(currentInteriorRing));
                        }
                    }

                    ////Note we do nothing with the interiorRings, but you can use them the same way as the IGeometryBag exteriorRings
                    //IRing currentInteriorRing = exteriorRingsEnum.Next() as IRing;
                    //while (currentInteriorRing != null)
                    //{
                    //    holes.Add(ConvertTo(currentInteriorRing));
                    //    currentInteriorRing = exteriorRingsEnum.Next() as IRing;
                    //}
                }

                GeoAPI.Geometries.IPolygon entry;
                if (holes != null && holes.Count > 0)
                {
                    entry = new GisSharpBlog.NetTopologySuite.Geometries.Polygon(shell, holes.ToArray());
                }
                else
                {
                    entry = new GisSharpBlog.NetTopologySuite.Geometries.Polygon(shell, null);
                }

                list.Add(entry);
                currentExteriorRing = exteriorRingsEnum.Next() as IRing;
            }

            if (list != null && list.Count > 0)
            {
                output = new GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon(list.ToArray());
            }

            return(output);
        }
示例#12
0
        private void LoadParcels(List <PointD> pt, Color color, string labelname)
        {
            SharpMap.Map map = new SharpMap.Map();
            List <GeoAPI.Geometries.Coordinate> vertices = new List <GeoAPI.Geometries.Coordinate>();


            foreach (PointD i in pt)
            {
                GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate();
                p.X = i.X;
                p.Y = i.Y;
                vertices.Add(p);
            }
            GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate();
            l.X = pt[0].X;
            l.Y = pt[0].Y;
            vertices.Add(l);

            //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>();



            GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory();

            GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray());

            GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null);


            SharpMap.Data.Providers.GeometryProvider geomProvider = new SharpMap.Data.Providers.GeometryProvider(polygon);

            SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels");

            SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();



            style.Fill    = new SolidBrush(Color.FromArgb(200, color));
            style.Outline = new Pen(new SolidBrush(color));

            layerParcels.Style = style;
            layerParcels.Style.EnableOutline = true;


            layerParcels.DataSource    = geomProvider;
            layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;

            var fdt = new SharpMap.Data.FeatureDataTable();

            fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint)));
            fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string)));
            var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow();

            fdr.ItemArray = new object[] { 1, labelname };
            fdr.Geometry  = polygon;
            fdt.AddRow(fdr);

            var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);

            var ll = new SharpMap.Layers.LabelLayer("llayer");

            ll.DataSource  = dataprovider;
            ll.LabelColumn = "label";
            ll.Style.Font  = new Font("Eurostile Extended", 16, FontStyle.Bold);



            mapBox1.Map.Layers.Add(layerParcels);
            mapBox1.Map.Layers.Add(ll);



            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
        }
示例#13
0
        public void PolygonHoles()
        {
            Coordinate[] coords = new Coordinate[20];
            Random rnd = new Random();
            Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            // Shell Coordinates
            GeoAPI.Geometries.ICoordinate[] coordscheck = new GeoAPI.Geometries.ICoordinate[20];
            for (int i = 0; i < 19; i++)
            {
                double x = center.X + Math.Cos((i * 10) * Math.PI / 10);
                double y = center.Y + (i * 10) * Math.PI / 10;
                coords[i] = new Coordinate(x, y);
                coordscheck[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
            }
            coordscheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coords[0].X, coords[0].Y);
            coords[19] = new Coordinate(coords[0].X, coords[0].Y);


            // Shell Rings
            LinearRing ring = new LinearRing(coords);
            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            GeoAPI.Geometries.ILinearRing ringCheck = gf.CreateLinearRing(coordscheck);


            // Hole Coordinates
            GeoAPI.Geometries.ICoordinate[] coordsholecheck = new GeoAPI.Geometries.ICoordinate[20];
            Coordinate[] coordshole = new Coordinate[20];
            for (int i = 0; i < 20; i++)
            {
                double x = center.X + Math.Cos((i * 10) * Math.PI / 20);
                double y = center.Y + (i * 10) * Math.PI / 20;
                coordshole[i] = new Coordinate(x, y);
                coordsholecheck[i] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
            }
            coordshole[19] = new Coordinate(coordshole[0].X, coordshole[0].Y);
            coordsholecheck[19] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y);

            // Hole LinearRing Arrays
            LinearRing hole = new LinearRing(coordshole);
            ILinearRing[] holes = new ILinearRing[1];
            GeoAPI.Geometries.ILinearRing holeCheck = gf.CreateLinearRing(coordsholecheck);
            GeoAPI.Geometries.ILinearRing[] holescheck = new GeoAPI.Geometries.ILinearRing[1];
            holes[0] = hole;
            holescheck[0] = holeCheck;


            Polygon pg = new Polygon(ring, holes);
            GeoAPI.Geometries.IPolygon polygonCheck = gf.CreatePolygon(ringCheck, holescheck);
            double areaCheck = polygonCheck.Area;
            double area = pg.Area;
            Assert.AreEqual(area, areaCheck);
        }