private void WriteLineString(LineString linestring, XmlWriter xmlWriter) { if (linestring.Vertices != null && linestring.Vertices.Count >= 2) { if (!linestring.Vertices[0].Altitude.HasValue) { //<georss:line>46.28548 -122.25302 46.28489 -122.25492</georss:line> xmlWriter.WriteStartElement("line", GeoRssNamespace); WriteCoordinateCollection(linestring.Vertices, xmlWriter); xmlWriter.WriteEndElement(); } else { //<georss:where> // <gml:LineString> // <gml:posList dimension="2"> // 14.35954 100.57967 // 14.35871 100.57337 // </gml:posList> // </gml:LineString> //</georss:where> xmlWriter.WriteStartElement("where", GeoRssNamespace); Gml.CreateLineString(linestring, xmlWriter); xmlWriter.WriteEndElement(); } } }
private void WritePolygon(Polygon polygon, XmlWriter xmlWriter) { if (polygon.ExteriorRing != null && polygon.ExteriorRing.Count >= 2) { bool hasAltitude = polygon.ExteriorRing[0].Altitude.HasValue; if (!hasAltitude && (polygon.InteriorRings == null || polygon.InteriorRings.Count == 0)) { //<georss:polygon>46.31409 -122.22616 46.31113 -122.22968 46.31083 -122.23320</georss:polygon> xmlWriter.WriteStartElement("polygon", GeoRssNamespace); WriteCoordinateCollection(polygon.ExteriorRing, xmlWriter); xmlWriter.WriteEndElement(); } else { //<georss:where> // <gml:Polygon> // <gml:exterior> // <gml:LinearRing> // <gml:posList> // -71.106216 42.366661 // -71.105576 42.367104 // -76.104378 42.367134 // -71.106216 42.366661 // </gml:posList> // </gml:LinearRing> // </gml:exterior> // </gml:Polygon> //</georss:where> xmlWriter.WriteStartElement("where", GeoRssNamespace); Gml.CreatePolygon(polygon, xmlWriter); xmlWriter.WriteEndElement(); } } }
private async Task <Geometry> ParseGeoRSSItem(XElement node, string baseUri, Dictionary <string, ShapeStyle> styles) { Geometry geom = null; var metadata = new ShapeMetadata(); string nodeName, styleKey = null, id = string.Empty; double tLat = double.NaN, tLon = double.NaN; var mapPointNS = XNamespace.Get(MapPointNamespace); var gmlNS = XNamespace.Get(GmlNamespace); var geoNS = XNamespace.Get(GeoNamespace); foreach (var n in node.Elements()) { nodeName = n.Name.LocalName; if (n.Name.Namespace == geoRssNS) { switch (nodeName) { case "point": case "line": case "polygon": case "circle": var polyCoords = ParseCoordinates(n); geom = await ParseGeometry(n); break; case "where": var g = await Gml.Parse(n, optimize, tolerance); if (g != null) { geom = g; } break; default: break; } } else if (n.Name.Namespace == gmlNS) { var gm = await Gml.Parse(node, optimize, tolerance); if (gm != null) { geom = gm; } } else if (n.Name.Namespace == mapPointNS && string.Compare(nodeName, "icon", StringComparison.OrdinalIgnoreCase) == 0) { var s = XmlUtilities.GetString(n, stripHtml); if (!string.IsNullOrWhiteSpace(s)) { var uri = CleanUri(s, baseUri); if (uri != null) { //Extract embedded Style styleKey = "embeddedStyle_" + embeddedStyleCnt; embeddedStyleCnt++; if (!styles.ContainsKey(styleKey)) { styles.Add(styleKey, new ShapeStyle() { IconUrl = uri }); } } } } else if (n.Name.Namespace == geoNS) { switch (nodeName) { case "lat": tLat = XmlUtilities.GetDouble(n, double.NaN); if (!double.IsNaN(tLat)) { if (!double.IsNaN(tLon)) { geom = new Point(tLat, tLon); } } break; case "lon": case "long": tLon = XmlUtilities.GetDouble(n, double.NaN); if (!double.IsNaN(tLon)) { if (!double.IsNaN(tLat)) { geom = new Point(tLat, tLon); } } break; case "point": tLat = XmlUtilities.GetDouble(n, "lat", double.NaN); tLon = XmlUtilities.GetDouble(n, "long", double.NaN); if (!double.IsNaN(tLat) && !double.IsNaN(tLon)) { geom = new Point(tLat, tLon); } break; default: break; } } else { switch (nodeName) { case "title": metadata.Title = XmlUtilities.GetString(n, stripHtml); break; case "description": metadata.Description = XmlUtilities.GetString(n, stripHtml); break; case "content": case "summary": SetMetadataString(metadata, nodeName, n, stripHtml); break; case "id": metadata.ID = XmlUtilities.GetString(n, stripHtml); break; case "icon": var s = XmlUtilities.GetString(n, stripHtml); if (!string.IsNullOrWhiteSpace(s)) { var uri = CleanUri(s, baseUri); if (uri != null) { //Extract embedded Style styleKey = "embeddedStyle_" + embeddedStyleCnt; embeddedStyleCnt++; if (!styles.ContainsKey(styleKey)) { styles.Add(styleKey, new ShapeStyle() { IconUrl = uri }); } } } break; case "link": var href = XmlUtilities.GetStringAttribute(n, "href"); if (!string.IsNullOrWhiteSpace(href) && !metadata.Properties.ContainsKey(nodeName)) { metadata.Properties.Add(nodeName, href); } break; case "updated": var time = XmlUtilities.GetDateTime(n); if (time.HasValue && !metadata.Properties.ContainsKey(nodeName)) { metadata.Properties.Add(nodeName, time); } break; default: break; } } } if (geom != null) { if (metadata.HasMetadata()) { geom.Metadata = metadata; } geom.StyleKey = styleKey; } return(geom); }