Ejemplo n.º 1
0
        public void MultipolygonToByteArray()
        {
            var rnd = new Random();
            var pg  = new Polygon[50];

            for (var i = 0; i < 50; i++)
            {
                var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                var coord  = new 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);
                }
                coord[35] = new Coordinate(coord[0].X, coord[0].Y);
                pg[i]     = new Polygon(coord);
            }
            var mpg      = new MultiPolygon(pg);
            var vals     = mpg.ToBinary();
            var wkr      = new WkbReader();
            var g        = wkr.Read(vals);
            var mpgcheck = g as MultiPolygon;

            if (mpgcheck != null)
            {
                for (var 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);
                }
            }
            else
            {
                Assert.Fail("The test failed bc the check mpgcheck was null.");
            }
        }
        public void MultipolygonToByteArray()
        {
            Random rnd = new Random();
            Polygon[] pg = new Polygon[50];
            for (int i = 0; i < 50; i++)
            {
                Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
                Coordinate[] coord = new Coordinate[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);
                }
                coord[35] = new Coordinate(coord[0].X, coord[0].Y);
                pg[i] = new Polygon(coord);
            }
            MultiPolygon mpg = new MultiPolygon(pg);
            Byte[] vals = mpg.ToBinary();
            WkbReader wkr = new WkbReader();
            IGeometry g = wkr.Read(vals);
            MultiPolygon mpgcheck = g as MultiPolygon;
            if (mpgcheck != null)
            {
                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);
                }
            }
            else
            {
                Assert.Fail("The test failed bc the check mpgcheck was null.");
            }

        }