// /// <summary> // /// Implicit conversion between OsmNode and Vector3. // /// </summary> // /// <param name="node">OsmNode instance</param> // public static implicit operator Coordinates (OsmNode node) // { // return new Coordinates(node.X, node.Y, 0); // } /// <summary> /// Constructor. /// </summary> /// <param name="node">Xml node</param> public OsmNode(XmlNode node, OsmNode firstNode) { // Get the attribute values Id = GetAttribute <ulong>("id", node.Attributes); Latitude = GetAttribute <float>("lat", node.Attributes); Longitude = GetAttribute <float>("lon", node.Attributes); // Calculate the position in Unity units X = MercatorProjection.lonToX(Longitude) * 0.1f; Y = MercatorProjection.latToY(Latitude) * 0.1f; if (firstNode == null) { coords = new Coordinates(MapReader.offsetX, 0, MapReader.offsetY); } else { coords = new Coordinates((X - firstNode.X) + MapReader.offsetX, 0, (Y - firstNode.Y) + MapReader.offsetY); } XmlNodeList tags = node.SelectNodes("tag"); foreach (XmlNode t in tags) { string key = GetAttribute <string>("k", t.Attributes); if (key == "highway") { string value = GetAttribute <string>("v", t.Attributes); if (value == "bus_stop") { isBusStop = true; } } else if (key == "naptan:AtcoCode") { string value = GetAttribute <string>("v", t.Attributes); actoCode = value; } } if (isBusStop && actoCode == "") { //throw new System.Exception("Is bus stop but no actoCode: node " + Id); isBusStop = false; } }
void setClosestNodes() { foreach (ulong busStopId in busStops.Values) { double shortestDistance = 9999999; ulong bestNodeId = 0; OsmNode busStopNode = nodes[busStopId]; foreach (ulong roadNodeId in roadNodes) { OsmNode roadNode = nodes[roadNodeId]; double distance = Managed.Coords.Dist(busStopNode.coords, roadNode.coords); if (distance < shortestDistance) { shortestDistance = distance; bestNodeId = roadNodeId; } } nearestRoadNodesToBusStops[busStopId] = bestNodeId; } }
void GetNodes(XmlNodeList xmlNodeList) { OsmNode firstNode = null; foreach (XmlNode n in xmlNodeList) { OsmNode node = new OsmNode(n, firstNode); if (firstNode == null) { firstNode = node; originX = node.X; originY = node.Y; } nodes[node.Id] = node; if (node.isBusStop) { busStops[node.actoCode] = node.Id; } } }