private void ProcessMuiltipleGeometry(MultipleGeometry f) { f.Geometry.ToList().ForEach(g => { if (g is Polygon) { ProcessPolygonGeometry((Polygon)g); } if (g is LineString) { ProcessLineStringGeometry((LineString)g); } if (g is Point) { ProcessPointGeometry((Point)g); } if (g is LinearRing) { ProcessLinearRingGeometry((LinearRing) g); } if (g is MultipleGeometry) { ProcessMuiltipleGeometry((MultipleGeometry)g); } }); }
/// <summary> /// Converts JSON geometry to KML geometry. /// </summary> /// <param name="geometry">ArcGIS JSON geometry</param> /// <returns><see cref="Geometry"/></returns> public static Geometry JsonToKmlGeometry(Dictionary<string, object> geometry) { Geometry placemarkGeometry; if (geometry.Keys.Contains("x")) { // Create point geometry // x and y are decimals; var x = Convert.ToDouble(geometry["x"]); var y = Convert.ToDouble(geometry["y"]); placemarkGeometry = new Point { Coordinate = new Vector(y, x) }; } else if (geometry.Keys.Contains("rings")) { // Create polygon geometry var rings = (ArrayList)geometry["rings"]; var linearRings = from ArrayList ring in rings select new LinearRing { Coordinates = new CoordinateCollection(from ArrayList point in ring select new Vector( Convert.ToDouble(point[1]), Convert.ToDouble(point[0]) )) }; if (linearRings.Count() > 1) { var polygon = new Polygon(); polygon.OuterBoundary = new OuterBoundary { LinearRing = linearRings.ElementAt(0) }; var innerBoundaries = from lr in linearRings.Skip(1) select new InnerBoundary { LinearRing = lr }; foreach (var ib in innerBoundaries) { polygon.AddInnerBoundary(ib); } placemarkGeometry = polygon; } else { placemarkGeometry = linearRings.First(); } } else if (geometry.Keys.Contains("paths")) { // Create line geometry var paths = (ArrayList)geometry["paths"]; var lineStrings = from ArrayList path in paths select new LineString { Coordinates = new CoordinateCollection(from ArrayList point in path select new Vector( Convert.ToDouble(point[1]), Convert.ToDouble(point[0]) )) }; if (lineStrings.Count() > 1) { var multiGeo = new MultipleGeometry(); foreach (var ls in lineStrings) { multiGeo.AddGeometry(ls); } placemarkGeometry = multiGeo; } else { placemarkGeometry = lineStrings.First(); } } else { placemarkGeometry = null; } return placemarkGeometry; }
protected virtual Feature CreateKmlFeature(FeatureDataRow feature, StyleSelector style) { var geometry = feature.Geometry; geometry = ToTarget(geometry); switch (geometry.OgcGeometryType) { case OgcGeometryType.Point: { var location = geometry.Coordinate; var p = new Point { Coordinate = new Vector(location.Y, location.X) }; return WrapPlacemark(p, style, feature); } case OgcGeometryType.MultiPoint: { var multiGeometry = new MultipleGeometry(); foreach (var coordinate in geometry.Coordinates) { var p = new Point { Coordinate = new Vector(coordinate.Y, coordinate.X) }; multiGeometry.AddGeometry(p); } return WrapPlacemark(multiGeometry, style, feature); } case OgcGeometryType.LineString: { var lineString = CreateLineString(geometry); return WrapPlacemark(lineString, style, feature); } case OgcGeometryType.Polygon: { var polygon = (IPolygon)geometry; var kmlPolygon = CreateKmlPolygon(polygon); return WrapPlacemark(kmlPolygon, style, feature); } case OgcGeometryType.MultiLineString: { var multiGeometry = new MultipleGeometry(); var multiLineString = (IMultiLineString)geometry; foreach (var innerGeometry in multiLineString.Geometries) { var lineString = CreateLineString(innerGeometry); multiGeometry.AddGeometry(lineString); } return WrapPlacemark(multiGeometry, style, feature); } case OgcGeometryType.MultiPolygon: { var multiGeometry = new MultipleGeometry(); var multiPoly = (IMultiPolygon)geometry; foreach (var innerGeometry in multiPoly.Geometries.Cast<IPolygon>()) { var polygon = CreateKmlPolygon(innerGeometry); multiGeometry.AddGeometry(polygon); } return WrapPlacemark(multiGeometry, style, feature); } default: throw new InvalidOperationException("Geometry not supported"); } }