public static List <PolygonMap> GetPolygonsOnMap(string ResultKML) { List <PolygonMap> Polygons = new List <PolygonMap>(); XmlDocument xd = new XmlDocument(); xd.LoadXml(ResultKML); XmlNode kml = xd.DocumentElement; XmlNodeList GeoObjectTemp = xd.GetElementsByTagName("Folder"); foreach (XmlNode node in GeoObjectTemp) { foreach (XmlNode item in node.ChildNodes) { if (item.Name == "Placemark") { PolygonMap Polygon = new PolygonMap(); bool IsPolygon = false; foreach (XmlNode PlacemarkItems in item.ChildNodes) { if (PlacemarkItems.Name == "description") { IsPolygon = (PlacemarkItems.InnerXml.Trim() == "Polygon"); } else if (PlacemarkItems.Name == "name") { Polygon.Id = PlacemarkItems.InnerXml; } else if (PlacemarkItems.Name == "LinearRing") { Polygon.Points = PolygonMap.GetPointsFromString(item.LastChild["coordinates"].InnerXml.Replace(',', ' ')); } } if (IsPolygon) { Polygons.Add(Polygon); } } } } return(Polygons); }
/// <summary> /// Возвращаем Id полигона, которому пренадлежит точка /// </summary> /// <param name="polygons">Полигоны, которых нужно искать точку</param> /// <param name="mainPoint">Точка для проверки</param> /// <returns>Возвращает Id полигона</returns> public static string GetIdPolygonOwnerPoint( PolygonMap[] polygons, PointD mainPoint ) { return polygons.Where(x => x.IsInPolygon(mainPoint)).Select(polygonMap => polygonMap.Id).FirstOrDefault(); }