Beispiel #1
0
        public MPolygon WriteMPolygon(MultiPolygon multiPolygon)
        {
            var mPolygon   = new MPolygon();
            var geometries = multiPolygon.Geometries;

            for (int i = 0; i < geometries.Length; i++)
            {
                var polygon = (IPolygon)geometries[i];
                var mpolygonLoopCollection = GetMPolygonLoopCollection(polygon);
                try
                {
                    foreach (var mpolygonLoop in mpolygonLoopCollection)
                    {
                        var mPolygonLoop = (MPolygonLoop)mpolygonLoop;
                        mPolygon.AppendMPolygonLoop(mPolygonLoop, false, 0.0);
                    }
                }
                finally
                {
                    foreach (var mpolygonLoop in mpolygonLoopCollection)
                    {
                        if (mpolygonLoop is IDisposable)
                        {
                            (mpolygonLoop as IDisposable).Dispose();
                        }
                    }
                }
            }
            mPolygon.BalanceTree();
            return(mPolygon);
        }
Beispiel #2
0
        public static CALayer RenderMultiPolygonOnLayer(MultiPolygon multiPolygon, IStyle style, IViewport viewport)
        {
            var tile = new CAShapeLayer();

            if (!(style is VectorStyle))
            {
                throw new ArgumentException("Style is not of type VectorStyle");
            }
            var vectorStyle = style as VectorStyle;

            var strokeAlpha = (float)vectorStyle.Outline.Color.A / 255;
            var fillAlpha   = (float)vectorStyle.Fill.Color.A / 255;

            var strokeColor = new CGColor(new CGColor(vectorStyle.Outline.Color.R, vectorStyle.Outline.Color.G,
                                                      vectorStyle.Outline.Color.B), strokeAlpha);
            var fillColor = new CGColor(new CGColor(vectorStyle.Fill.Color.R, vectorStyle.Fill.Color.G,
                                                    vectorStyle.Fill.Color.B), fillAlpha);

            var path = multiPolygon.ToUIKit(viewport);

            tile.StrokeColor = strokeColor;
            tile.FillColor   = fillColor;
            tile.LineWidth   = (float)vectorStyle.Outline.Width;
            tile.Path        = path.CGPath;

            return(tile);
        }
Beispiel #3
0
        public void If_input_a_valid_multipolygon_then_should_get_correct_wkb()
        {
            var multiPolygon = new MultiPolygon(new List <Polygon>
            {
                new Polygon(new List <Point>
                {
                    new Point(30, 20),
                    new Point(45, 40),
                    new Point(10, 40),
                    new Point(30, 20)
                }),
                new Polygon(new List <Point>
                {
                    new Point(15, 5),
                    new Point(40, 10),
                    new Point(10, 20),
                    new Point(5, 10),
                    new Point(15, 5)
                })
            });
            var expectWkbHex = "010600000002000000010300000001000000040000000000000000003E40000000000000344000000000008046400000000000004440000000000000244000000000000044400000000000003E400000000000003440010300000001000000050000000000000000002E4000000000000014400000000000004440000000000000244000000000000024400000000000003440000000000000144000000000000024400000000000002E400000000000001440";

            var hex = multiPolygon.ToWkbHex();

            hex.Should().BeEquivalentTo(expectWkbHex);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the data polygons from a feature.
        /// </summary>
        /// <param name="feature">The feature.</param>
        /// <returns>List with DataPolygons.</returns>
        private List <DataPolygon> GetDataPolygons(Feature feature)
        {
            GeoJSONObjectType  polygonType = feature.Geometry.Type;
            List <DataPolygon> polygons    = new List <DataPolygon>();

            if (!(polygonType == GeoJSONObjectType.MultiPolygon || polygonType == GeoJSONObjectType.Polygon))
            {
                return(polygons);
            }

            DataPolygon dataPolygon;

            if (polygonType == GeoJSONObjectType.MultiPolygon)
            {
                MultiPolygon multiPolygon = (MultiPolygon)feature.Geometry;
                foreach (Polygon polygon in multiPolygon.Coordinates)
                {
                    dataPolygon = DataPolygonConverter.ConvertToDataPolygon(polygon);
                    polygons.Add(dataPolygon);
                }
            }

            if (polygonType == GeoJSONObjectType.Polygon)
            {
                dataPolygon = DataPolygonConverter.ConvertToDataPolygon((Polygon)feature.Geometry);
                polygons.Add(dataPolygon);
            }

            return(polygons);
        }
Beispiel #5
0
        public static void Run()
        {
            //ExStart: GetAreaOfGeometry
            var triangleRing = new LinearRing();

            triangleRing.AddPoint(4, 6);
            triangleRing.AddPoint(1, 3);
            triangleRing.AddPoint(8, 7);
            triangleRing.AddPoint(4, 6);
            var triangle = new Polygon(triangleRing);

            var squareRing = new LinearRing();

            squareRing.AddPoint(0, 9);
            squareRing.AddPoint(0, 7);
            squareRing.AddPoint(2, 7);
            squareRing.AddPoint(2, 9);
            squareRing.AddPoint(0, 9);
            var square = new Polygon(squareRing);

            var multiPolygon = new MultiPolygon {
                triangle, square
            };

            Console.WriteLine("{0:F}", triangle.GetArea());     // 4.50
            Console.WriteLine("{0:F}", square.GetArea());       // 4.00
            Console.WriteLine("{0:F}", multiPolygon.GetArea()); // 8.50
            //ExEnd: GetAreaOfGeometry
        }
Beispiel #6
0
 private void DrawMultiPolygon(MultiPolygon mPolygon, DrawingStyle style, ViewInfo viewInfo, Graphics g)
 {
     foreach (var polygon in mPolygon.Geometries)
     {
         DrawPolygon(polygon, style, viewInfo, g);
     }
 }
            protected override Geometry Transform(MultiPolygon geom,
                                                  Geometry parent)
            {
                Geometry roughGeom = base.Transform(geom, parent);

                return(CreateValidArea(roughGeom));
            }
        private static List <List <PointF> > ConvertToPointF(Geometry geom)
        {
            List <List <PointF> > list = new List <List <PointF> >();

            if (geom is Polygon)
            {
                Polygon polygon = geom as Polygon;
                list.Add((from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList());
            }
            else if (geom is MultiPolygon)
            {
                MultiPolygon polygons = geom as MultiPolygon;
                foreach (Polygon polygon in polygons.Polygons)
                {
                    list.Add((from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList());
                }
            }
            else if (geom is EasyMap.Geometries.Point)
            {
                EasyMap.Geometries.Point p = (EasyMap.Geometries.Point)geom;
                PointF        p1           = new PointF(float.Parse(p.X.ToString()), (float)p.Y);
                List <PointF> lp           = new List <PointF>();
                lp.Add(p1);
                list.Add(lp);
            }
            return(list);
        }
Beispiel #9
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.");
            }
        }
Beispiel #10
0
 public static void AreEqual(XmlNodeList polygonNodes, MultiPolygon multiPolygon)
 {
     for (int i = 0; i < polygonNodes.Count; i++)
     {
         AreEqual(polygonNodes[i], multiPolygon.Polygons[i]);
     }
 }
Beispiel #11
0
        private void TestParseMultiPolygon(byte[] wkb, string expectedAsWkt)
        {
            MultiPolygon expected = (MultiPolygon)this.ParseWKT(expectedAsWkt);
            MultiPolygon parsed   = WkbReader.Parse <MultiPolygon>(wkb);

            this.CompareMultiPolygons(parsed, expected);
        }
Beispiel #12
0
 public static void DrawMultiPolygon(Graphics g, MultiPolygon pols, Brush brush, Pen pen, bool clip, Map map)
 {
     for (int i = 0; i < pols.Polygons.Count; i++)
     {
         DrawPolygon(g, pols.Polygons[i], brush, pen, clip, map);
     }
 }
 public static GeoRss10Where ToGeoRss10Where(this MultiPolygon mpolygon)
 {
     return(new GeoRss10Where()
     {
         Item = mpolygon.ToGmlMultiSurface()
     });
 }
        private List <MultiPolygon> GetShiftedMultipolygonsAroundTheAxis(MultiPolygon multiPolygon, double factor)
        {
            var shftingTable = new List <ShiftingFactorForCoordinates>
            {
                new ShiftingFactorForCoordinates
                {
                    ShiftingFactorForX = factor,
                    ShiftingFactorForY = 0
                },
                new ShiftingFactorForCoordinates
                {
                    ShiftingFactorForX = 0,
                    ShiftingFactorForY = factor
                },
                new ShiftingFactorForCoordinates
                {
                    ShiftingFactorForX = -factor,
                    ShiftingFactorForY = 0
                },
                new ShiftingFactorForCoordinates
                {
                    ShiftingFactorForX = 0,
                    ShiftingFactorForY = -factor
                }
            };

            return(shftingTable.Select(shiftingOption => GetShiftedMultpolygon(multiPolygon, shiftingOption)).ToList());
        }
        private MultiPolygon GetShiftedMultpolygon(MultiPolygon multipolygon, ShiftingFactorForCoordinates shiftingOption)
        {
            List <LineString> lineStrings = multipolygon.Coordinates.SelectMany(polygon => polygon.Coordinates).ToList();

            List <LineString> transformedLineStrings = new List <LineString>();

            foreach (LineString line in lineStrings)
            {
                var updatedCoords = new List <IPosition>();
                foreach (IPosition coords in line.Coordinates)
                {
                    GeographicPosition geographicPosition = (GeographicPosition)coords;
                    var latitudeFactor  = (shiftingOption.ShiftingFactorForY / _earthsRadiusInMeters) * 180 / Math.PI;
                    var longitudeFactor = (shiftingOption.ShiftingFactorForX / _earthsRadiusInMeters) * (180 / Math.PI) /
                                          Math.Cos(geographicPosition.Latitude * Math.PI / 180);

                    updatedCoords.Add(
                        new GeographicPosition(
                            geographicPosition.Latitude + latitudeFactor,
                            geographicPosition.Longitude + longitudeFactor));
                }

                transformedLineStrings.Add(new LineString(updatedCoords));
            }

            var result = new MultiPolygon(new List <Polygon> {
                new Polygon(transformedLineStrings)
            });

            return(result);
        }
Beispiel #16
0
        public static void PositionMultiPolygon(CALayer shape, MultiPolygon multiPolygon, IStyle style, IViewport viewport)
        {
            var shapeLayer = shape as CAShapeLayer;
            var path       = multiPolygon.ToUIKit(viewport);

            //var frame = ConvertBoundingBox (multiPolygon.GetBoundingBox(), viewport);
            shapeLayer.Path = path.CGPath;
            //shape.Frame = frame;

            /*
             * if (viewport.Resolution > MinResolution || viewport.Resolution < MaxResolution) {
             *  //recalculate
             *  var newImage = RenderMultiPolygonOnLayer (multiPolygon, style, viewport);
             *
             *  shape.Contents = newImage.Contents;
             *  shape.Frame = newImage.Frame;
             *
             *  var resolution = ZoomHelper.ClipToExtremes (Resolutions, viewport.Resolution);
             *
             *  MinResolution = ZoomHelper.ZoomOut (Resolutions, resolution);
             *  MaxResolution = ZoomHelper.ZoomIn (Resolutions, resolution);
             *
             * } else {
             *  //reposition Geometry
             *  var frame = ConvertBoundingBox (multiPolygon.GetBoundingBox(), viewport);
             *  var newFrame = new RectangleF (frame.X, (frame.Y), frame.Width, frame.Height);
             *
             *  shape.Frame = newFrame;
             *  //shape.Frame = frame;
             * }
             */
        }
Beispiel #17
0
        protected override void _draw()
        {
            foreach (Feature feature in features.Features)
            {
                IDictionary <string, object> properties = feature.Properties;
                string gisId = feature.Id;


                // Get the geometry
                MultiPolygon mPols = null;
                if (feature.Geometry.Type == GeoJSONObjectType.Polygon)
                {
                    mPols = new MultiPolygon(new List <Polygon>()
                    {
                        feature.Geometry as Polygon
                    });
                }
                else if (feature.Geometry.Type == GeoJSONObjectType.MultiPolygon)
                {
                    mPols = feature.Geometry as MultiPolygon;
                }

                foreach (Polygon mPol in mPols.Coordinates)
                {
                    ReadOnlyCollection <LineString> LinearRings = mPol.Coordinates;
                    _drawFeature(LinearRings, gisId, properties as Dictionary <string, object>);
                }
            }
        }
        public void If_input_valid_multipolygon_with_lower_endian_then_should_return_correct_multipolygon()
        {
            const string hex       = "010600000002000000010300000001000000040000000000000000003e40000000000000344000000000008046400000000000004440000000000000244000000000000044400000000000003e400000000000003440010300000001000000050000000000000000002e4000000000000014400000000000004440000000000000244000000000000024400000000000003440000000000000144000000000000024400000000000002e400000000000001440";
            var          expectGeo = new MultiPolygon(new List <Polygon>
            {
                new Polygon(new List <Point>
                {
                    new Point(30, 20),
                    new Point(45, 40),
                    new Point(10, 40),
                    new Point(30, 20)
                }),
                new Polygon(new List <Point>
                {
                    new Point(15, 5),
                    new Point(40, 10),
                    new Point(10, 20),
                    new Point(5, 10),
                    new Point(15, 5)
                })
            });

            var geoResult = WkbReader.Read(hex);

            geoResult.Equals(expectGeo).ShouldBeTrue();
        }
        private static List <GpcPolygon> ConvertGpcPolygon(Geometry geom)
        {
            List <GpcPolygon> list = new List <GpcPolygon>();

            if (geom is Polygon)
            {
                Polygon       polygon = geom as Polygon;
                List <PointF> ps      = (from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList();
                GraphicsPath  gp1     = new GraphicsPath();
                gp1.AddPolygon(ps.ToArray());
                GpcPolygon pp = new GpcPolygon(gp1);
                list.Add(pp);
            }
            else if (geom is MultiPolygon)
            {
                MultiPolygon polygons = geom as MultiPolygon;
                foreach (Polygon polygon in polygons.Polygons)
                {
                    List <PointF> ps  = (from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList();
                    GraphicsPath  gp1 = new GraphicsPath();
                    gp1.AddPolygon(ps.ToArray());
                    GpcPolygon pp = new GpcPolygon(gp1);
                    list.Add(pp);
                }
            }
            return(list);
        }
        public void If_json_is_valid_multipolygon_with_hole_then_should_return_correct_multipolygon()
        {
            const string geojson   = @"{
                ""type"": ""MultiPolygon"", 
                ""coordinates"": [
                    [
                        [[40, 40], [20, 45], [45, 30], [40, 40]]
                    ], 
                    [
                        [[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], 
                        [[30, 20], [20, 15], [20, 25], [30, 20]]
                    ]
                ]
            }";
            var          expectGeo = new MultiPolygon(new List <Polygon>
            {
                new Polygon(new List <Point> {
                    new Point(40, 40), new Point(20, 45), new Point(45, 30), new Point(40, 40)
                }),
                new Polygon(new List <LineString>
                {
                    new LineString(new List <Point> {
                        new Point(20, 35), new Point(10, 30), new Point(10, 10), new Point(30, 5), new Point(45, 20), new Point(20, 35)
                    }),
                    new LineString(new List <Point> {
                        new Point(30, 20), new Point(20, 15), new Point(20, 25), new Point(30, 20)
                    })
                })
            });

            var resultGeo = GeoJsonReader.Read(geojson);

            resultGeo.ShouldBe(expectGeo);
        }
        public static Geometry Intersection(Geometry source, Geometry dest)
        {
            List <List <PointF> > source_polygons = ConvertToPointF(source);
            List <List <PointF> > dest_polygons   = ConvertToPointF(dest);
            GpcPolygon            polygon         = Intersection(source_polygons, dest_polygons);

            if (polygon.Contour.Length == 0)
            {
                return(null);
            }
            if (polygon.Contour.Length > 2)
            {
                MultiPolygon ret = new MultiPolygon();
                polygon.Contour.ToList().ForEach(
                    a =>
                {
                    Polygon subret = new Polygon();
                    IList <EasyMap.Geometries.Point> vertices = subret.ExteriorRing.Vertices;
                    a.Vertex.ToList().ForEach(p => { vertices.Add(new EasyMap.Geometries.Point(p.X, p.Y)); });
                    ret.Polygons.Add(subret);
                });
                return(ret);
            }
            else
            {
                Polygon ret = new Polygon();
                IList <EasyMap.Geometries.Point> vertices = ret.ExteriorRing.Vertices;
                polygon.Contour[0].Vertex.ToList().ForEach(p => { vertices.Add(new EasyMap.Geometries.Point(p.X, p.Y)); });
                return(ret);
            }
        }
Beispiel #22
0
        private async Task <MultiPolygon> ReadMultiPolygon(BinaryReader reader, ByteOrder wkbByteOrder, WKBShapeType type, bool includeAltitude, bool includeM)
        {
            // Get the number of Polygons.
            int numPolygons = (int)NumberReader.ReadUInt32(reader, wkbByteOrder);

            // Create a new array for the Polygons.
            MultiPolygon polygons = new MultiPolygon(numPolygons);

            Polygon p;

            // Loop on the number of polygons.
            for (int i = 0; i < numPolygons; i++)
            {
                // read polygon header
                reader.ReadByte();
                NumberReader.ReadUInt32(reader, wkbByteOrder);

                p = await ReadPolygon(reader, wkbByteOrder, type, includeAltitude, includeM);

                // Create the next polygon and add it to the array.
                polygons.Geometries.Add(p);
            }

            //Create and return the MultiPolygon.
            return(polygons);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="multiPolygon"></param>
        /// <param name="writer"></param>
        /// <param name="addSRID"></param>
        private void WriteMultiPolygon(MultiPolygon multiPolygon,
                                       XmlWriter writer, bool addSRID)
        {
            // 1. Start the multi-polygon...
            bool usePrefix = WriteStartElement(writer, GeometryGml2.GmlMultiPolygon,
                                               multiPolygon, addSRID);

            // 2. Write the individual polygons
            int nPolygons = multiPolygon.NumGeometries;

            for (int i = 0; i < nPolygons; i++)
            {
                if (usePrefix)
                {
                    writer.WriteStartElement(m_strPrefix,
                                             GeometryGml2.GmlPolygonMember, null);
                }
                else
                {
                    writer.WriteStartElement(GeometryGml2.GmlPolygonMember);
                }
                WritePolygon(multiPolygon[i], writer, false);
                writer.WriteEndElement();
            }

            // 3. End the multi-polygon
            WriteEndElement(writer);
        }
Beispiel #24
0
        private static void WriteMultiPolygon(MultiPolygon polygons, BinaryWriter writer)
        {
            //write the byte order
            writer.Write((byte)ByteOrder.Ndr);

            if (polygons.Geometries.Count > 0 && polygons.Geometries[0].ExteriorRing.Count > 0)
            {
                if (polygons.Geometries[0].ExteriorRing[0].Altitude.HasValue)
                {
                    writer.Write((uint)WKBShapeType.WkbMultiPolygonZ);
                }
                else
                {
                    writer.Write((uint)WKBShapeType.WkbMultiPolygon);
                }
            }
            else
            {
                writer.Write((uint)WKBShapeType.WkbMultiPolygon);
            }

            writer.Write((int)polygons.Geometries.Count);    //write the number of polygons

            for (int i = 0; i < polygons.Geometries.Count; i++)
            {
                WritePolygon(polygons.Geometries[i], writer);
            }
        }
Beispiel #25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="cancelProgressHandler"></param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return(false);
            }

            // We add all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            // We add the area field
            bool   addField   = true;
            string fieldCount = string.Empty;
            int    i          = 0;

            while (addField)
            {
                if (output.DataTable.Columns.Contains(TextStrings.Area + fieldCount) == false)
                {
                    output.DataTable.Columns.Add(new DataColumn(TextStrings.Area + fieldCount, typeof(double)));
                    addField = false;
                }
                else
                {
                    fieldCount = i.ToString();
                    i++;
                }
            }

            // we add all the old features to output
            for (int j = 0; j < input.Features.Count; j++)
            {
                Feature newFeature = new Feature(input.Features[j].BasicGeometry, output);
                foreach (DataColumn colSource in input.DataTable.Columns)
                {
                    newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                }

                newFeature.DataRow[TextStrings.Area + fieldCount] =
                    MultiPolygon.FromBasicGeometry(output.Features[j].BasicGeometry).Area;

                // Status updates is done here
                cancelProgressHandler.Progress(
                    string.Empty,
                    Convert.ToInt32((Convert.ToDouble(j) / Convert.ToDouble(input.Features.Count)) * 100),
                    input.Features[j].DataRow[0].ToString());
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }
            }

            output.AttributesPopulated = true;
            output.Save();
            return(true);
        }
        public void A_multipolygon_should_not_equal_to_a_none_point()
        {
            var multiPolygon = new MultiPolygon();
            var other        = 100;

            multiPolygon.Equals(other).ShouldBeFalse();
        }
Beispiel #27
0
 public static void DrawMultiPolygon(Graphics graphics, MultiPolygon pols, Brush brush, Pen pen, IViewport viewport)
 {
     foreach (Polygon t in pols.Polygons)
     {
         DrawPolygon(graphics, t, brush, pen, viewport);
     }
 }
        public void A_valid_multipolygon_should_not_equal_an_invalid_point()
        {
            var multiPolygon = new MultiPolygon(new[] { new Polygon(new[] { new LineString(new[] { new Point(30, 20), new Point(45, 40), new Point(10, 40), new Point(30, 20) }) }) });
            var other        = new MultiPolygon();

            multiPolygon.Equals(other).ShouldBeFalse();
        }
        private static MultiPolygon ReadMultiPolygonText(WktStreamTokenizer tokenizer)
        {
            //GeoJSONObject geometry = null;
            //var polygons = new List<List<Coordinate>>();
            string nextToken = GetNextEmptyOrOpener(tokenizer);
            var    pol       = new List <Polygon>();

            if (nextToken == "EMPTY")
            {
                var polygons = new MultiPolygon(
                    new List <Polygon>(pol)

                    );
                return(polygons);
            }

            var polygon = ReadPolygonText(tokenizer);

            pol.Add(polygon);
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                polygon = ReadPolygonText(tokenizer);
                pol.Add(polygon);
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            var pols = new MultiPolygon(
                new List <Polygon>(pol)

                );

            //pols = GeoJSONFromWKT.Parse(Convert.ToString(dr["wkt"]));
            return(pols);
        }
Beispiel #30
0
        public void RenderGeometry(MultiPolygon multiPolygon, IStyle style, IFeature feature, IViewport viewport)
        {
            if (_bgWorker == null)
            {
                _bgWorker = new BackgroundWorker();
            }

            /*
             * while (_bgWorker.IsBusy) {
             *  Thread.Sleep (00001);
             * }
             */
            _bgWorker.RunWorkerCompleted += (sender, e) =>
            {
                var layer = e.Result as CALayer;

                if (layer != null)
                {
                    var styleKey = style.GetHashCode().ToString();
                    feature[styleKey] = layer;
                }
            };

            _bgWorker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                var layer = RenderImage(multiPolygon, style, viewport);
                e.Result = layer;
            };

            _bgWorker.RunWorkerAsync();
        }
        public void ComputeArea_IMultiPolygon_ReturnsSumOfPolygonAreas()
        {
            Random generator = new Random();

            Polygon polygon = new Polygon(new CoordinateList());
            double polygonArea = generator.Next(100);
            MultiPolygon multipolygon = new MultiPolygon(new Polygon[] { polygon, polygon });

            Mock<IDimensionsCalculator> calculatorM = new Mock<IDimensionsCalculator>();
            calculatorM.Setup(calc => calc.CalculateArea(polygon.ExteriorRing)).Returns(() => polygonArea);

            Measurements target = new Measurements(calculatorM.Object);

            double area = target.ComputeArea(multipolygon);

            Assert.Equal(2 * polygonArea, area);
        }
Beispiel #32
0
        protected Geometry CreateGeometry(GeometryType geometryType, Dimension dimension)
        {
            Geometry geometry = null;

            switch (geometryType)
            {
                case GeometryType.Point: geometry = new Point(); break;
                case GeometryType.LineString: geometry = new LineString(); break;
                case GeometryType.Polygon: geometry = new Polygon(); break;
                case GeometryType.MultiPoint: geometry = new MultiPoint(); break;
                case GeometryType.MultiLineString: geometry = new MultiLineString(); break;
                case GeometryType.MultiPolygon: geometry = new MultiPolygon(); break;
                case GeometryType.GeometryCollection: geometry = new GeometryCollection(); break;
            }

            geometry.Dimension = dimension;

            return geometry;
        }
Beispiel #33
0
        private void WriteMultiPolygon(MultiPolygon multiPolygon)
        {
            wktBuilder.Append("(");

            foreach (Polygon polygon in multiPolygon.Polygons)
            {
                WritePolygon(polygon);
                wktBuilder.Append(",");
            }

            wktBuilder.Remove(wktBuilder.Length - 1, 1);
            wktBuilder.Append(")");
        }
 public void Write_WritesMultiPolygonsOfAllDimensions(MultiPolygon toWrite, string expectedWkt)
 {
     this.TestWriteGeometry(toWrite, expectedWkt);
 }
Beispiel #35
0
        public static void Write(MultiPolygon areas, TextWriter writer)
        {
            if (areas == null)
                return;
            if (writer == null)
                throw new ArgumentNullException("writer", "A valid text writer object is required");

            Write(areas, CreateWriter(writer));
        }
 public IMultiPolygon CreateMultiPolygon()
 {
     MultiPolygon mp = new MultiPolygon();
     mp.Factory = this;
     return mp;
 }
        public IMultiPolygon CreateMultiPolygon(IEnumerable<IPolygon> polygons)
        {
            MultiPolygon mp = new MultiPolygon();
            mp.Factory = this;

            foreach (Polygon polygon in polygons)
            {
                mp.Add(polygon);
            }

            return mp;
        }
        private void CompareMultiPolygons(MultiPolygon multipolygon, MultiPolygon expected)
        {
            Assert.Equal(expected.Geometries.Count, multipolygon.Geometries.Count);

            for (int i = 0; i < expected.Geometries.Count; i++) {
                this.ComparePolygons(multipolygon.Geometries[i], expected.Geometries[i]);
            }
        }
Beispiel #39
0
        /// <summary>
        ///     Creates a <see cref="MultiPolygon" /> using the next token in the stream.
        /// </summary>
        /// <param name="tokenizer">
        ///     tokenizer over a stream of text in Well-known Text
        ///     format. The next tokens must form a MultiPolygon.
        /// </param>
        /// <returns>
        ///     a <code>MultiPolygon</code> specified by the next token in the
        ///     stream, or if if the coordinates used to create the <see cref="Polygon" />
        ///     shells and holes do not form closed linestrings.
        /// </returns>
        private static MultiPolygon ReadMultiPolygonText(WktStreamTokenizer tokenizer)
        {
            var polygons = new MultiPolygon();
            var nextToken = GetNextEmptyOrOpener(tokenizer);
            if (nextToken == "EMPTY")
                return polygons;

            var polygon = ReadPolygonText(tokenizer);
            polygons.Polygons.Add(polygon);
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                polygon = ReadPolygonText(tokenizer);
                polygons.Polygons.Add(polygon);
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return polygons;
        }
Beispiel #40
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process</param>
 /// <param name="level"></param>
 /// <param name="writer">The output stream writer to Append to.</param>
 protected void AppendMultiPolygonTaggedText(MultiPolygon multiPolygon, int level, StringWriter writer)
 {
     writer.Write("MULTIPOLYGON ");
     AppendMultiPolygonText(multiPolygon, level, writer);
 }
Beispiel #41
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="multiPolygon"></param>
 /// <returns></returns>
 protected virtual int SetByteStreamLength(MultiPolygon multiPolygon)
 {
     int count = INIT_VALUE;
     foreach (Polygon p in multiPolygon.Geometries)
         count += SetByteStreamLength(p);
     return count;
 }
Beispiel #42
0
        protected MultiPolygon ReadMultiPolygon(Dimension dimension)
        {
            MultiPolygon multiPolygon = new MultiPolygon();
            multiPolygon.Dimension = dimension;

            ExpectGroupStart();

            do
            {
                multiPolygon.Polygons.Add(ReadPolygon(dimension));
            } while (IsMatch(","));

            ExpectGroupEnd();

            return multiPolygon;
        }
Beispiel #43
0
        private void WriteMultiPolygon(MultiPolygon multiPolygon)
        {
            wkbWriter.Write(multiPolygon.Polygons.Count);

            foreach (Polygon polygon in multiPolygon.Polygons)
                WriteInternal(polygon, multiPolygon);
        }
Beispiel #44
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 protected void AppendMultiPolygonTaggedText(MultiPolygon multiPolygon,  TextWriter writer)
 {
     AppendPath(writer);
     AppendMultiPolygonText(multiPolygon,  writer);
     AppendEndPath(writer);
 }
Beispiel #45
0
        private void WriteMultiPolygon(MultiPolygon mp, WKBByteOrder byteOrder)
        {
            // Write byte order
            _writer.Write((byte)byteOrder);

            // Write type
            this.WriteType(mp, byteOrder);

            // Get the number of polygons in this multipolygon.
            int numpolygons = mp.getNumGeometries();

            // Write the number of polygons.
            this.Write((uint)numpolygons, byteOrder);

            for (int i = 0; i < numpolygons; i++)
            {
                // Write each polygon.
                this.WritePolygon((Polygon)mp.getGeometryN(i), byteOrder);
            }
        }
Beispiel #46
0
 /// <summary>
 ///     Converts a MultiPolygon to &lt;MultiPolygon Text&gt; format, then Appends to it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process.</param>
 /// <param name="writer">The output stream to Append to.</param>
 private static void AppendMultiPolygonText(MultiPolygon multiPolygon, StringWriter writer)
 {
     if ((multiPolygon == null) || multiPolygon.IsEmpty())
         writer.Write("EMPTY");
     else
     {
         writer.Write("(");
         for (var i = 0; i < multiPolygon.Polygons.Count; i++)
         {
             if (i > 0)
                 writer.Write(", ");
             AppendPolygonText(multiPolygon[i], writer);
         }
         writer.Write(")");
     }
 }
Beispiel #47
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Text&gt; format, then Appends to it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process.</param>
 /// <param name="level"></param>
 /// <param name="writer">The output stream to Append to.</param>
 protected void AppendMultiPolygonText(MultiPolygon multiPolygon, int level, StringWriter writer)
 {
     if ( multiPolygon.isEmpty() )
     {
         writer.Write("EMPTY");
     }
     else
     {
         int level2 = level;
         bool doIndent = false;
         writer.Write("(");
         for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
         {
             if (i > 0)
             {
                 writer.Write(", ");
                 level2 = level + 1;
                 doIndent = true;
             }
             //AppendPolygonText((Polygon) multiPolygon.GetGeometryN(i), level2, doIndent, writer);
             AppendPolygonText((Polygon) multiPolygon.getGeometryN(i), level2, doIndent, writer);
         }
         writer.Write(")");
     }
 }
Beispiel #48
0
 /// <summary>
 ///     Converts a MultiPolygon to &lt;MultiPolygon Tagged
 ///     Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendMultiPolygonTaggedText(MultiPolygon multiPolygon, StringWriter writer)
 {
     writer.Write("MULTIPOLYGON ");
     AppendMultiPolygonText(multiPolygon, writer);
 }
Beispiel #49
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="multiPolygon"></param>
 /// <param name="writer"></param>
 protected virtual void Write(MultiPolygon multiPolygon, XmlTextWriter writer)
 {
     writer.WriteStartElement("MultiPolygon");
     for (int i = 0; i < multiPolygon.NumGeometries; i++)
     {
         writer.WriteStartElement("polygonMember");
         Write(multiPolygon.Geometries[i] as Polygon, writer);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
        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.");
            }

        }
Beispiel #51
0
        /// <summary>
        ///     Writes a multipolygon.
        /// </summary>
        /// <param name="mp">The mulitpolygon to be written.</param>
        /// <param name="bWriter">Stream to write to.</param>
        /// <param name="byteorder">Byte order</param>
        private static void WriteMultiPolygon(MultiPolygon mp, BinaryWriter bWriter, WkbByteOrder byteorder)
        {
            //Write the number of polygons.
            WriteUInt32((uint) mp.Polygons.Count, bWriter, byteorder);

            //Loop on the number of polygons.
            foreach (var poly in mp.Polygons)
            {
                //Write polygon header
                bWriter.Write((byte) byteorder);
                WriteUInt32((uint) WKBGeometryType.WKBPolygon, bWriter, byteorder);
                //Write each polygon.
                WritePolygon(poly, bWriter, byteorder);
            }
        }
Beispiel #52
0
        public void Multipg()
        {
            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);
                var 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);
            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);
            }
        }
Beispiel #53
0
        public static void Write(MultiPolygon areas, JsonTextWriter writer)
        {
            if (areas == null)
                return;
            if (writer == null)
                throw new ArgumentNullException("writer", "A valid JSON writer object is required");

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            writer.WriteValue("MultiPolygon");
            writer.WritePropertyName("coordinates");
            writer.WriteStartArray();
            foreach (Polygon area in areas)
            {
                writer.WriteStartArray();
                WriteCoord(area.ExteriorRing.Vertices, writer);
                foreach (LinearRing hole in area.InteriorRings)
                    WriteCoord(hole.Vertices, writer);
                writer.WriteEndArray();
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
        }
Beispiel #54
0
 /// <summary>
 /// Converts a MultiPolygon to &lt;MultiPolygon Text&gt; format, then Appends to it to the writer.
 /// </summary>
 /// <param name="multiPolygon">The MultiPolygon to process.</param>
 /// <param name="writer">The output stream to Append to.</param>
 public void AppendMultiPolygonText(MultiPolygon multiPolygon, TextWriter writer)
 {
     if (multiPolygon.isEmpty())
     {
         writer.Write("EMPTY");
     }
     else
     {
         //writer.Write("M");
         for (int i = 0; i < multiPolygon.getNumGeometries(); i++)
         {
             /*if (i > 0 && (i<multiPolygon.GetNumGeometries()-1) )
             {
                 writer.Write(", ");
             }*/
             AppendPolygonText((Polygon) multiPolygon.getGeometryN(i), writer);
         }
         //writer.Write("Z");
     }
 }
Beispiel #55
0
        private static MultiPolygon CreateWKBMultiPolygon(BinaryReader reader, WkbByteOrder byteOrder)
        {
            // Get the number of Polygons.
            var numPolygons = (int) ReadUInt32(reader, byteOrder);

            // Create a new array for the Polygons.
            var polygons = new MultiPolygon();

            // Loop on the number of polygons.
            for (var i = 0; i < numPolygons; i++)
            {
                // read polygon header
                reader.ReadByte();
                ReadUInt32(reader, byteOrder);

                // TODO: Validate type

                // Create the next polygon and add it to the array.
                polygons.Polygons.Add(CreateWKBPolygon(reader, byteOrder));
            }

            //Create and return the MultiPolygon.
            return polygons;
        }