void LoadPlaces() { StreamReader reader = new StreamReader(File.OpenRead("MO.txt")); WikiMapiaPlace place = new WikiMapiaPlace(); int counter = 0; while (!reader.EndOfStream) { var str = reader.ReadLine(); if (str == "") { RamCache.Add(place.Id, place); } else if (str[0] == 'М') { place = new WikiMapiaPlace(); place.Title = str; place.Id = counter++; place.Polygon = new List <Vector2>(); } else { var strs = str.Split(' '); place.Polygon.Add(new Vector2(float.Parse(strs[1]), float.Parse(strs[0]))); } } }
WikiMapiaPlace ParseWikiPlace(XmlNode place) { string id = place.SelectSingleNode("id").InnerText; XmlNode loc = place.SelectSingleNode("location"); WikiMapiaLocation location = new WikiMapiaLocation { Lon = float.Parse(loc.SelectSingleNode("lon").InnerText), Lat = float.Parse(loc.SelectSingleNode("lat").InnerText), North = float.Parse(loc.SelectSingleNode("north").InnerText), South = float.Parse(loc.SelectSingleNode("south").InnerText), East = float.Parse(loc.SelectSingleNode("east").InnerText), West = float.Parse(loc.SelectSingleNode("west").InnerText), Country = loc.SelectSingleNode("country").InnerText, State = loc.SelectSingleNode("state").InnerText, Place = loc.SelectSingleNode("place").InnerText, CountryAdmId = int.Parse(loc.SelectSingleNode("country_adm_id").InnerText) }; var title = place.SelectSingleNode("title"); WikiMapiaPlace p = new WikiMapiaPlace { Id = int.Parse(id), Title = title != null ? title.InnerText : "No Title", Location = location, Polygon = new List <Vector2>() }; XmlNode poly = place.SelectSingleNode("polygon"); foreach (XmlNode child in poly.ChildNodes) { float x = float.Parse(child.SelectSingleNode("x").InnerText); float y = float.Parse(child.SelectSingleNode("y").InnerText); p.Polygon.Add(new Vector2(x, y)); } p.Tags = new Dictionary <string, string>(); var tags = place.SelectSingleNode("tags"); foreach (XmlNode child in tags.ChildNodes) { p.Tags.Add(child.SelectSingleNode("id").InnerText, child.SelectSingleNode("title").InnerText); } return(p); }
WikiMapiaPlace ParseWikiPlace(XmlNode place) { string id = place.SelectSingleNode("id").InnerText; XmlNode loc = place.SelectSingleNode("location"); WikiMapiaLocation location = new WikiMapiaLocation { Lon = float.Parse(loc.SelectSingleNode("lon").InnerText), Lat = float.Parse(loc.SelectSingleNode("lat").InnerText), North = float.Parse(loc.SelectSingleNode("north").InnerText), South = float.Parse(loc.SelectSingleNode("south").InnerText), East = float.Parse(loc.SelectSingleNode("east").InnerText), West = float.Parse(loc.SelectSingleNode("west").InnerText), Country = loc.SelectSingleNode("country").InnerText, State = loc.SelectSingleNode("state").InnerText, Place = loc.SelectSingleNode("place").InnerText, CountryAdmId = int.Parse(loc.SelectSingleNode("country_adm_id").InnerText) }; var title = place.SelectSingleNode("title"); WikiMapiaPlace p = new WikiMapiaPlace { Id = int.Parse(id), Title = title!=null ? title.InnerText : "No Title", Location = location, Polygon = new List<Vector2>() }; XmlNode poly = place.SelectSingleNode("polygon"); foreach (XmlNode child in poly.ChildNodes) { float x = float.Parse(child.SelectSingleNode("x").InnerText); float y = float.Parse(child.SelectSingleNode("y").InnerText); p.Polygon.Add(new Vector2(x, y)); } p.Tags = new Dictionary<string, string>(); var tags = place.SelectSingleNode("tags"); foreach (XmlNode child in tags.ChildNodes) { p.Tags.Add(child.SelectSingleNode("id").InnerText, child.SelectSingleNode("title").InnerText); } return p; }
void LoadPlaces() { StreamReader reader = new StreamReader(File.OpenRead("MO.txt")); WikiMapiaPlace place = new WikiMapiaPlace(); int counter = 0; while (!reader.EndOfStream) { var str = reader.ReadLine(); if(str == "") { RamCache.Add(place.Id, place); } else if (str[0] == 'М') { place = new WikiMapiaPlace(); place.Title = str; place.Id = counter++; place.Polygon = new List<Vector2>(); } else { var strs = str.Split(' '); place.Polygon.Add(new Vector2(float.Parse(strs[1]), float.Parse(strs[0]))); } } }