Exemple #1
0
 public Building(string name, string houseNumber, string street, Amenity amenity, Material material, RoofInfo roofInfo, Node[] nodes)
 {
     Name        = name;
     HouseNumber = houseNumber;
     Street      = street;
     Amenity     = amenity;
     Nodes       = nodes;
     Material    = material;
     Roof        = roofInfo;
 }
Exemple #2
0
 public Building(string name, string houseNumber, string street, Amenity amenity, Material material, double lat, double longitude, RoofInfo roofInfo, Node[] nodes)
 {
     Name        = name;
     HouseNumber = houseNumber;
     Street      = street;
     Amenity     = amenity;
     Material    = material;
     PrimaryLat  = lat;
     PrimaryLong = longitude;
     Roof        = roofInfo;
     Nodes       = nodes;
 }
Exemple #3
0
        public void ReadData()
        {
            var allNodes = new Dictionary <long, Node>();
            RankedDictionary <double, RankedDictionary <double, SeattleNode> > orderedNodes = new RankedDictionary <double, RankedDictionary <double, SeattleNode> >();

            var reader = XmlReader.Create(new FileStream(_sourceXml, FileMode.Open));
            HashSet <string> nodeNames = new HashSet <string>()
            {
                { "node" },
                { "way" },
            };

            foreach (var data in ElementsNamed(reader, nodeNames))
            {
                TagInfo tags = new TagInfo();
                switch (data.Name.LocalName)
                {
                case "node":
                    var id        = Convert.ToInt64(data.Attribute("id").Value);
                    var lat       = Convert.ToDouble(data.Attribute("lat").Value);
                    var longitude = Convert.ToDouble(data.Attribute("lon").Value);
                    foreach (var node in data.Descendants())
                    {
                        switch (node.Name.LocalName)
                        {
                        case "tag":
                            ReadTag(ref tags, node);
                            break;
                        }
                    }
                    Node newNode;
                    if (tags.houseNumber != null && tags.street != null)
                    {
                        RankedDictionary <double, SeattleNode> longNodes;
                        if (!orderedNodes.TryGetValue(lat, out longNodes))
                        {
                            longNodes = orderedNodes[lat] = new RankedDictionary <double, SeattleNode>();
                        }
                        allNodes[id] = newNode = longNodes[longitude] = new SeattleNode(lat, longitude, id, tags.name, tags.houseNumber, tags.street, tags.stories);
                    }
                    else
                    {
                        newNode = allNodes[id] = new Node(lat, longitude);
                    }

                    if (tags.crossing == CrossingType.Zebra)
                    {
                        var zebra = Ways[id] = new Way(
                            tags.name,
                            new[] { newNode },
                            tags.lanes,
                            tags.roadType,
                            tags.sidewalk,
                            tags.layer,
                            tags.crossing,
                            tags.surface,
                            tags.oneWay
                            );
                    }
                    else if (tags.roadType == RoadType.BusStop)
                    {
                        if (tags.name != null && (tags.shelter ?? false))
                        {
                            var streetNames = tags.name.Split('&');
                            if (streetNames.Length != 2)
                            {
                                Console.WriteLine("BS: {0}", tags.name);
                            }
                            var         normalized = NormalizeName(streetNames[0]);
                            List <Node> busNodes;
                            if (!BusStops.TryGetValue(normalized, out busNodes))
                            {
                                BusStops[normalized] = busNodes = new List <Node>();
                            }
                            busNodes.Add(newNode);
                        }
                    }
                    else if (tags.signType != SignType.None)
                    {
                        Signs[newNode] = tags.signType;
                    }
                    break;

                case "way":
                    List <Node> nodes = new List <Node>();
                    foreach (var node in data.Descendants())
                    {
                        switch (node.Name.LocalName)
                        {
                        case "nd":
                            nodes.Add(allNodes[Convert.ToInt64(node.Attribute("ref").Value)]);
                            break;

                        case "tag":
                            ReadTag(ref tags, node);
                            break;
                        }
                    }

                    RoofInfo roof = null;
                    if (tags.roofType != RoofType.None ||
                        tags.roofColor != null)
                    {
                        roof = new RoofInfo(tags.roofType, tags.roofColor, tags.roofDirection, tags.roofHeight, tags.roofMaterial, tags.roofOrientationAcross);
                    }
                    if (tags.building != BuildingType.None)
                    {
                        var buildingObj = Buildings[Convert.ToInt64(data.Attribute("id").Value)] = new Building(
                            tags.name,
                            tags.houseNumber,
                            tags.street,
                            tags.amenity,
                            tags.material,
                            roof,
                            nodes.ToArray()
                            );
                        buildingObj.Stories = tags.stories;
                        if (tags.houseNumber != null && tags.street != null)
                        {
                            BuildingsByAddress[tags.houseNumber + " " + tags.street] = buildingObj;
                        }

                        double maxLat = double.MinValue, minLat = double.MaxValue, maxLong = double.MinValue, minLong = double.MaxValue;
                        foreach (var point in nodes)
                        {
                            maxLat  = Math.Max(point.Lat, maxLat);
                            minLat  = Math.Min(point.Lat, minLat);
                            maxLong = Math.Max(point.Long, maxLong);
                            minLong = Math.Min(point.Long, minLong);
                        }

                        int itemsCount = 0;
                        foreach (var group in orderedNodes.ElementsBetween(minLat, maxLat))
                        {
                            foreach (var longAndNode in group.Value.ElementsBetween(minLong, maxLong))
                            {
                                var node = longAndNode.Value;
                                if (node.Lat >= minLat && node.Lat <= maxLat &&
                                    node.Long >= minLong && node.Long <= maxLong)
                                {
                                    var buildingFromPoint = Buildings[node.NodeNumber] = new Building(
                                        node.Name ?? tags.name,
                                        node.HouseNumber,
                                        node.Street,
                                        tags.amenity,
                                        tags.material,
                                        node.Lat,
                                        node.Long,
                                        roof,
                                        nodes.ToArray());
                                    buildingFromPoint.Stories = tags.stories;
                                    itemsCount++;
                                    Console.WriteLine("ByAddressNode: " + node.HouseNumber + " " + node.Street + " (" + itemsCount + ")");
                                    BuildingsByAddress[node.HouseNumber + " " + node.Street] = buildingFromPoint;
                                }
                            }
                        }
                    }
                    else if (tags.roadType != RoadType.None)
                    {
                        var road = Ways[Convert.ToInt64(data.Attribute("id").Value)] = new Way(
                            tags.name,
                            nodes.ToArray(),
                            tags.lanes,
                            tags.roadType,
                            tags.sidewalk,
                            tags.layer,
                            tags.crossing,
                            tags.surface,
                            tags.oneWay
                            );
                        foreach (var point in nodes)
                        {
                            List <Way> ways;
                            if (!RoadsByNode.TryGetValue(point, out ways))
                            {
                                RoadsByNode[point] = ways = new List <Way>(1);
                            }
                            ways.Add(road);
                        }
                        if (tags.name != null)
                        {
                            List <Way> roads;
                            if (!RoadsByName.TryGetValue(tags.name, out roads))
                            {
                                roads = RoadsByName[tags.name] = new List <Way>();
                            }
                            roads.Add(road);
                        }
                    }
                    else if (tags.barrier != BarrierKind.None)
                    {
                        Barriers.Add(new Barrier(nodes.ToArray(), tags.barrier, tags.wall));
                    }
                    break;
                }
            }
        }