예제 #1
0
        public static JGeometry.MultiPolygon MultiPolygon2JG(Polygon polygon)
        {
            var polygons = (from simplePolygon in polygon.childPolygons select Polygon2JG(simplePolygon)).ToList();

            JGeometry.MultiPolygon multiPolygon = new JGeometry.MultiPolygon(polygons);
            return(multiPolygon);
        }
예제 #2
0
        private static IGeometryObject FromDotSpatial(DotSpatial.Topology.MultiPolygon polygon)
        {
            List <Polygon> pl = new List <Polygon>();

            for (int i = 0; i < polygon.Geometries.Length; i++)
            {
                IGeometry geometry = polygon.Geometries[i];
                var       g        = FromDotSpatial((DotSpatial.Topology.Polygon)geometry);
                pl.Add(g);
            }
            MultiPolygon r = new MultiPolygon(pl);

            return(r);
        }
예제 #3
0
        public void Can_Deserialize()
        {
            var json = GetExpectedJson();

            var expectMultiPolygon = new MultiPolygon(new List<Polygon>
            {
                new Polygon(new List<LineString>
                {
                    new LineString(new List<IPosition>
                    {
                        new GeographicPosition(52.959676831105995, -2.6797102391514338), 
                        new GeographicPosition(52.9608756693609, -2.6769029474483279), 
                        new GeographicPosition(52.908449372833715, -2.6079763270327119), 
                        new GeographicPosition(52.891287242948195, -2.5815104708998668), 
                        new GeographicPosition(52.875476700983896, -2.5851645010668989), 
                        new GeographicPosition(52.882954723868622, -2.6050779098387191), 
                        new GeographicPosition(52.875255907042678, -2.6373482332006359), 
                        new GeographicPosition(52.878791122091066, -2.6932445076063951), 
                        new GeographicPosition(52.89564268523565, -2.6931334629377890), 
                        new GeographicPosition(52.930592009390175, -2.6548779332193022), 
                        new GeographicPosition(52.959676831105995, -2.6797102391514338)
                    })
                }), 
                new Polygon(new List<LineString>
                {
                    new LineString(new List<IPosition>
                    {
                        new GeographicPosition(52.89610842810761, -2.69628632041613), 
                        new GeographicPosition(52.8894641454077, -2.75901233808515), 
                        new GeographicPosition(52.89938894657412, -2.7663172788742449), 
                        new GeographicPosition(52.90253773227807, -2.804554822840895), 
                        new GeographicPosition(52.929801009654575, -2.83848602260174), 
                        new GeographicPosition(52.94013913205788, -2.838979264607087), 
                        new GeographicPosition(52.937353122653533, -2.7978187468478741), 
                        new GeographicPosition(52.920394929466184, -2.772273870352612), 
                        new GeographicPosition(52.926572918779222, -2.6996509024137052), 
                        new GeographicPosition(52.89610842810761, -2.69628632041613)
                    })
                })
            });

            var actualMultiPolygon = JsonConvert.DeserializeObject<MultiPolygon>(json);

            Assert.AreEqual(expectMultiPolygon, actualMultiPolygon);
        }
예제 #4
0
 private MultiPolygon GetMultiPolygon(double offset = 0.0)
 {
     var multiPolygon = new MultiPolygon(new List<Polygon>
     {
         new Polygon(new List<LineString>
         {
             new LineString(new List<IPosition>
             {
                 new GeographicPosition(52.959676831105995 + offset, -2.6797102391514338 + offset),
                 new GeographicPosition(52.9608756693609 + offset, -2.6769029474483279 + offset),
                 new GeographicPosition(52.908449372833715 + offset, -2.6079763270327119 + offset),
                 new GeographicPosition(52.891287242948195 + offset, -2.5815104708998668 + offset),
                 new GeographicPosition(52.875476700983896 + offset, -2.5851645010668989 + offset),
                 new GeographicPosition(52.882954723868622 + offset, -2.6050779098387191 + offset),
                 new GeographicPosition(52.875255907042678 + offset, -2.6373482332006359 + offset),
                 new GeographicPosition(52.878791122091066 + offset, -2.6932445076063951 + offset),
                 new GeographicPosition(52.89564268523565 + offset, -2.6931334629377890 + offset),
                 new GeographicPosition(52.930592009390175 + offset, -2.6548779332193022 + offset),
                 new GeographicPosition(52.959676831105995 + offset, -2.6797102391514338 + offset)
             })
         }),
         new Polygon(new List<LineString>
         {
             new LineString(new List<IPosition>
             {
                 new GeographicPosition(52.89610842810761 + offset,-2.69628632041613 + offset),
                 new GeographicPosition(52.8894641454077 + offset,-2.75901233808515 + offset),
                 new GeographicPosition(52.89938894657412 + offset,-2.7663172788742449 + offset),
                 new GeographicPosition(52.90253773227807 + offset,-2.804554822840895 + offset),
                 new GeographicPosition(52.929801009654575 + offset,-2.83848602260174 + offset),
                 new GeographicPosition(52.94013913205788 + offset,-2.838979264607087 + offset),
                 new GeographicPosition(52.937353122653533 + offset,-2.7978187468478741 + offset),
                 new GeographicPosition(52.920394929466184 + offset,-2.772273870352612 + offset),
                 new GeographicPosition(52.926572918779222 + offset,-2.6996509024137052 + offset),
                 new GeographicPosition(52.89610842810761 + offset, -2.69628632041613 + offset)
             })
         })
     });
     return multiPolygon;
 }
		private IGeometryObject GeometryFromSinkGeometryCollection(SinkGeometryCollection<OpenGisGeographyType> sinkCollection)
		{

			IGeometryObject _geometry = null;

			switch (sinkCollection.GeometryType)
			{
				case OpenGisGeographyType.Point:
					_geometry = ConstructGeometryPart(sinkCollection[0]);
					((Point)_geometry).BoundingBoxes = this.BoundingBox;
					break;
				case OpenGisGeographyType.MultiPoint:
					_geometry = new MultiPoint(sinkCollection.Skip(1)
																										.Select(g => (Point)ConstructGeometryPart(g))
																										.ToList());
					((MultiPoint)_geometry).BoundingBoxes = this.BoundingBox;
					break;
				case OpenGisGeographyType.LineString:
					_geometry = ConstructGeometryPart(sinkCollection[0]);
					((LineString)_geometry).BoundingBoxes = this.BoundingBox;
					break;
				case OpenGisGeographyType.MultiLineString:
					_geometry = new MultiLineString(sinkCollection.Skip(1)
																												.Select(g => (LineString)ConstructGeometryPart(g))
																												.ToList());
					((MultiLineString)_geometry).BoundingBoxes = this.BoundingBox;
					break;
				case OpenGisGeographyType.Polygon:
					_geometry = ConstructGeometryPart(sinkCollection.First());
					((Polygon)_geometry).BoundingBoxes = this.BoundingBox;
					break;
				case OpenGisGeographyType.MultiPolygon:
					_geometry = new MultiPolygon(sinkCollection.Skip(1)
																												.Select(g => (Polygon)ConstructGeometryPart(g))
																												.ToList());
					((MultiPolygon)_geometry).BoundingBoxes = this.BoundingBox;
					break;
				default:
					throw new NotSupportedException("Geometry type " + sinkCollection.GeometryType.ToString() + " is not possible in GetConstructedGeometry.");
			}

			return _geometry;

		}
예제 #6
0
        public void Can_Serialize_MultiPolygon_Feature()
        {
            var multiPolygon = new MultiPolygon(new List<Polygon>
            {
                new Polygon(new List<LineString>
                {
                    new LineString(new List<GeographicPosition>
                    {
                        new GeographicPosition(0, 0),
                        new GeographicPosition(0, 1),
                        new GeographicPosition(1, 1),
                        new GeographicPosition(1, 0),
                        new GeographicPosition(0, 0)
                    })
                }),
                new Polygon(new List<LineString>
                {
                    new LineString(new List<GeographicPosition>
                    {
                        new GeographicPosition(100, 100),
                        new GeographicPosition(100, 101),
                        new GeographicPosition(101, 101),
                        new GeographicPosition(101, 100),
                        new GeographicPosition(100, 100)
                    }),
                    new LineString(new List<GeographicPosition>
                    {
                        new GeographicPosition(200, 200),
                        new GeographicPosition(200, 201),
                        new GeographicPosition(201, 201),
                        new GeographicPosition(201, 200),
                        new GeographicPosition(200, 200)
                    })
                })
            });

            var feature = new Net.Feature.Feature(multiPolygon);

            var expectedJson = GetExpectedJson();
            var actualJson = JsonConvert.SerializeObject(feature);

            JsonAssert.AreEqual(expectedJson, actualJson);
        }
예제 #7
0
        public void MultiPolygonSerialization()
        {
            var expectedJson = "{\"geometry\":{\"coordinates\":[[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]],[[[100.0,100.0],[101.0,100.0],[101.0,101.0],[100.0,101.0],[100.0,100.0]],[[200.0,200.0],[201.0,200.0],[201.0,201.0],[200.0,201.0],[200.0,200.0]]]],\"type\":\"MultiPolygon\"},\"properties\":{},\"type\":\"Feature\"}";
            var polygon1 = new Polygon(new List<LineString>
            {
                new LineString((new List<GeographicPosition>
                {
                    new GeographicPosition(0, 0),
                    new GeographicPosition(0, 1),
                    new GeographicPosition(1, 1),
                    new GeographicPosition(1, 0),
                    new GeographicPosition(0, 0)
                }).ToList<IPosition>())

            });

            var polygon2 = new Polygon(new List<LineString>
            {
                new LineString((new List<GeographicPosition>
                {
                    new GeographicPosition(100, 100),
                    new GeographicPosition(100, 101),
                    new GeographicPosition(101, 101),
                    new GeographicPosition(101, 100),
                    new GeographicPosition(100, 100)
                }).ToList<IPosition>()),
                new LineString((new List<GeographicPosition>
                {
                    new GeographicPosition(200, 200),
                    new GeographicPosition(200, 201),
                    new GeographicPosition(201, 201),
                    new GeographicPosition(201, 200),
                    new GeographicPosition(200, 200)
                }).ToList<IPosition>())

            });

            var multipolygon = new MultiPolygon(new List<Polygon> { polygon1, polygon2 });
            var newFeature = new Feature.Feature(multipolygon);
            var serializedData = JsonConvert.SerializeObject(newFeature, Formatting.Indented, DefaultJsonSerializerSettings);
            var serializedDataWithouWhiteSpace = Regex.Replace(serializedData, @"(\s|$)+", "");
            Assert.IsTrue(serializedDataWithouWhiteSpace == expectedJson);
        }
		public ToSqlGeometryTests()
		{
			point = new Point(new GeographicPosition(53.2455662, 90.65464646));

			multiPoint = new MultiPoint(new List<Point>
                {
                    new Point(new GeographicPosition(52.379790828551016, 5.3173828125)),
                    new Point(new GeographicPosition(52.36721467920585, 5.456085205078125)),
                    new Point(new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23))
                });
			lineString = new LineString(new List<IPosition>
                {
                    new GeographicPosition(52.379790828551016, 5.3173828125),
                    new GeographicPosition(52.36721467920585, 5.456085205078125),
                    new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23)
                });
			multiLineString = new MultiLineString(new List<LineString>
                {
                    new LineString(new List<IPosition>
                    {
                        new GeographicPosition(52.379790828551016, 5.3173828125),
                        new GeographicPosition(52.36721467920585, 5.456085205078125),
                        new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23)
                    }),
                    new LineString(new List<IPosition>
                    {
                        new GeographicPosition(52.379790828551016, 5.3273828125),
                        new GeographicPosition(52.36721467920585, 5.486085205078125),
                        new GeographicPosition(52.303440474272755, 5.426047363281249, 4.23)
                    })
                });

			polygonWithHole = new Polygon(new List<LineString>
                {
                    new LineString(new List<GeographicPosition>
                    {
											new GeographicPosition(0.516357421875, 47.6415668949958),
											new GeographicPosition(0.516357421875, 47.34463879017405),
											new GeographicPosition(0.977783203125, 47.22539733216678),
											new GeographicPosition(1.175537109375, 47.463611506072866),
											new GeographicPosition(0.516357421875, 47.6415668949958)
                    }),
										 new LineString(new List<GeographicPosition>
											{
												new GeographicPosition(0.630340576171875, 47.54944962456812),
												new GeographicPosition(0.630340576171875, 47.49380564962583),
												new GeographicPosition(0.729217529296875, 47.482669772098674),
												new GeographicPosition(0.731964111328125, 47.53276262898896),
												new GeographicPosition(0.630340576171875, 47.54944962456812)
											})
								});
			polygon = new Polygon(new List<LineString>
                {
                    new LineString(new List<GeographicPosition>
                    {
                        new GeographicPosition(52.379790828551016, 5.3173828125),
                        new GeographicPosition(52.36721467920585, 5.456085205078125),
                        new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23),
                        new GeographicPosition(52.379790828551016, 5.3173828125)
                    })
                });

			multiPolygon = new MultiPolygon(new List<Polygon>
                {
                    new Polygon(new List<LineString>
                    {
                        new LineString(new List<IPosition>
                        {
                            new GeographicPosition(52.959676831105995, -2.6797102391514338),
                            new GeographicPosition(52.9608756693609, -2.6769029474483279),
                            new GeographicPosition(52.908449372833715, -2.6079763270327119),
                            new GeographicPosition(52.891287242948195, -2.5815104708998668),
                            new GeographicPosition(52.875476700983896, -2.5851645010668989),
                            new GeographicPosition(52.882954723868622, -2.6050779098387191),
                            new GeographicPosition(52.875255907042678, -2.6373482332006359),
                            new GeographicPosition(52.878791122091066, -2.6932445076063951),
                            new GeographicPosition(52.89564268523565, -2.6931334629377890),
                            new GeographicPosition(52.930592009390175, -2.6548779332193022),
                            new GeographicPosition(52.959676831105995, -2.6797102391514338)
                        })
                    }),
                    new Polygon(new List<LineString>
                    {
                        new LineString(new List<IPosition>
                        {
                            new GeographicPosition(52.89610842810761, -2.69628632041613),
                            new GeographicPosition(52.8894641454077, -2.75901233808515),
                            new GeographicPosition(52.89938894657412, -2.7663172788742449),
                            new GeographicPosition(52.90253773227807, -2.804554822840895),
                            new GeographicPosition(52.929801009654575, -2.83848602260174),
                            new GeographicPosition(52.94013913205788, -2.838979264607087),
                            new GeographicPosition(52.937353122653533, -2.7978187468478741),
                            new GeographicPosition(52.920394929466184, -2.772273870352612),
                            new GeographicPosition(52.926572918779222, -2.6996509024137052),
                            new GeographicPosition(52.89610842810761, -2.69628632041613)
                        })
                    })
                });

			geomCollection = new GeometryCollection(new List<IGeometryObject>
                {
                    point,
                    multiPoint,
                    lineString,
                    multiLineString,
                    polygon,
                    multiPolygon
                });

			feature = new Feature.Feature(polygon, new Dictionary<string, object>() { { "Key", "Value" } }, "Id");

			featureCollection = new FeatureCollection(new List<Feature.Feature> {
					feature, new Feature.Feature(multiPolygon, null)
			});

		}
예제 #9
0
 protected bool Equals(MultiPolygon other)
 {
     return base.Equals(other) && Coordinates.SequenceEqual(other.Coordinates);
 }
예제 #10
0
        public void Can_Serialize()
        {
            // Arrang
            var polygon1 = new Polygon(new List<LineString>
            {
                new LineString(new List<GeographicPosition>
                {
                    new GeographicPosition(0, 0), 
                    new GeographicPosition(0, 1), 
                    new GeographicPosition(1, 1), 
                    new GeographicPosition(1, 0), 
                    new GeographicPosition(0, 0)
                })
            });

            var polygon2 = new Polygon(new List<LineString>
            {
                new LineString(new List<GeographicPosition>
                {
                    new GeographicPosition(100, 100), 
                    new GeographicPosition(100, 101), 
                    new GeographicPosition(101, 101), 
                    new GeographicPosition(101, 100), 
                    new GeographicPosition(100, 100)
                }), 
                new LineString(new List<GeographicPosition>
                {
                    new GeographicPosition(200, 200), 
                    new GeographicPosition(200, 201), 
                    new GeographicPosition(201, 201), 
                    new GeographicPosition(201, 200), 
                    new GeographicPosition(200, 200)
                })
            });

            var multiPolygon = new MultiPolygon(new List<Polygon> { polygon1, polygon2 });
            var expectedJson = GetExpectedJson();

            // Act
            var actualJson = JsonConvert.SerializeObject(multiPolygon);

            // Assert
            JsonAssert.AreEqual(expectedJson, actualJson);
        }
		private static void Internal_FillGeometryBuilder(SqlGeometryBuilder gb, MultiPolygon multiPolygon)
		{
			gb.BeginGeometry(OpenGisGeometryType.MultiPolygon);
			foreach (var polygon in multiPolygon.Coordinates)
			{
				Internal_FillGeometryBuilder(gb, polygon);
			}
			gb.EndGeometry();
		}
		private IGeometryObject ConstructGeometryPart(SinkGeometry<OpenGisGeometryType> geomPart)
		{

			IGeometryObject geometry = null;

			switch (geomPart.GeometryType)
			{
				case OpenGisGeometryType.Point:
					geometry = new Point(geomPart[0][0]);
					break;
				case OpenGisGeometryType.MultiPoint:
					MultiPoint mp = new MultiPoint(geomPart.Select(g => new Point(g[0])).ToList());
					geometry = mp;
					break;
				case OpenGisGeometryType.LineString:
					geometry = new LineString(geomPart[0]);
					break;
				case OpenGisGeometryType.MultiLineString:
					geometry = new MultiLineString(geomPart.Select(line => new LineString(line))
																																		.ToList()
																															);
					break;
				case OpenGisGeometryType.Polygon:
					geometry = new Polygon(geomPart.Select(line => new LineString(line))
																																		.ToList()
																															);
					break;
				case OpenGisGeometryType.MultiPolygon:
					//geometry = new MultiPolygon(geomPart.Skip(1)
					//																							.Select(g => (Polygon)ConstructGeometryPart(g))
					//																							.ToList());
					geometry = new MultiPolygon();
					break;

				default:
					throw new NotSupportedException("Geometry type " + geomPart.GeometryType.ToString() + " is not supported yet.");
			}

			return geometry;
		}
        private static IGeometryObject GetPolygonGeometry(List<List<List<GeographicPosition>>> polygons)
        {
            {
                IGeometryObject geom=null;

                if (polygons.Count == 1)
                {
                    geom = GetPolygon(polygons[0]);
                }
                else if(polygons.Count>0)
                {
                    var multipolys = new List<Polygon>();
                    foreach(var poly in polygons)
                    {
                        var pl = GetPolygon(poly);
                        multipolys.Add(pl);
                    }

                    geom = new MultiPolygon(multipolys);
                }
                return geom;
            }
        }
 protected bool Equals(MultiPolygon other)
 {
     return(base.Equals(other) && Coordinates.SequenceEqual(other.Coordinates));
 }