Ejemplo n.º 1
0
        private static List <OsmGeoObject> ParseStreets(XElement root)
        {
            var nodes = (from node in root.Descendants("node")
                         select new OsmGeoNode()
            {
                Id = (string)node.Attribute("id"),
                Latitude = (double)node.Attribute("lat"),
                Longitude = (double)node.Attribute("lon")
            }).ToDictionary(x => x.Id, x => x);


            var objects = from way in root.Descendants("way")
                          let fullName = GetTagValue(way, "name")
                                         where fullName != null
                                         let wayNodes = (from nodeRef in way.Elements("nd") select(string) nodeRef.Attribute("ref")).ToList()
                                                        select new OsmWay
            {
                Name           = GetOsmName(way),
                Nodes          = GetGeoNodes(fullName, nodes, wayNodes),
                Ua             = GetOsmName(way, "uk"),
                Ru             = GetOsmName(way, "ru"),
                ParentDistrict = GetTagValue(way, "addr:suburb")
            };

            var wayGroups = objects.GroupBy(x => new { x.Name.FullName, x.ParentDistrict });

            var distinctGeoObjects = new List <OsmGeoObject>();

            foreach (var wayGroup in wayGroups)
            {
                string SelectMostFrequent(Func <OsmWay, string> selector)
                {
                    return(wayGroup.Select(selector)
                           .GroupBy(x => x)
                           .OrderByDescending(x => x.Count())
                           .First()
                           .Key);
                }

                var osmGeoObject = new OsmGeoObject
                {
                    Nodes = wayGroup.SelectMany(x => x.Nodes).ToList(),
                    Ua    = new OsmName()
                    {
                        FullOldName = SelectMostFrequent(x => x.Ua.FullOldName),
                        FullName    = SelectMostFrequent(x => x.Ua.FullName)
                    },
                    Ru = new OsmName()
                    {
                        FullOldName = SelectMostFrequent(x => x.Ru.FullOldName),
                        FullName    = SelectMostFrequent(x => x.Ru.FullName)
                    },
                    ParentDistrict = wayGroup.Key.ParentDistrict
                };

                distinctGeoObjects.Add(osmGeoObject);
            }

            return(distinctGeoObjects);
        }
Ejemplo n.º 2
0
 private static IEnumerable <GeoNode> ConvertGeoNodes(OsmGeoObject osmGeoObject)
 {
     return(osmGeoObject.Nodes.Select(x => new GeoNode(x.Latitude, x.Longitude)));
 }