static void Main(string[] args) { Console.WriteLine("Hello World!"); var osmpbf = "./data/utrecht-latest.osm.pbf"; // https://tiles.sharedstreets.io/12-2106-1351.intersection.pbf var intersectionStream = File.OpenRead("./data/12-2106-1351.intersection.pbf"); var intersections = SharedStreetsTileParser.Parse <SharedStreetsIntersection>(intersectionStream); // 5099 Console.WriteLine("Number of intersections:" + intersections.Count); var tile = new Tile(2106, 1351, 12); var bounds = tile.Bounds(); // read osm pbf var source = new PBFOsmStreamSource(new FileInfo(osmpbf).OpenRead()); var filtered = source.FilterBox((float)bounds[0], (float)bounds[3], (float)bounds[2], (float)bounds[1]); // left, top, right, bottom var i = 0; //grab all way segments for road name A //grab all way segments for road named B //compare both list of nodes //return equal nodes // filter intersections, geometries // todo: improve perf foreach (var element in filtered) { if (element.Type == OsmGeoType.Way) { var way = (Way)element; var nodes = way.Nodes; foreach (var node in nodes) { var otherway = GetOtherWay(source, way, node); if (otherway != null) { Console.WriteLine(node); i++; } } } } // 533926 Console.WriteLine("Number of nodes: " + i); Console.ReadKey(); }
public static Graph.RoutingGraph ReadOsmData(string path, string testPointsPath, string name) { RoutingGraph graph = new RoutingGraph(name, testPointsPath); { using (var fileStreamSource = File.OpenRead(path)) { var source = new PBFOsmStreamSource(fileStreamSource); var filtered = name.Equals("VA")? source.FilterBox(-77.8f, 39.4f, -77f, 38.67f) : source; var nodesAndWays = from osmGeo in filtered where osmGeo.Type == OsmSharp.OsmGeoType.Node || (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.ContainsKey("highway")) select osmGeo; var completed = nodesAndWays.ToComplete(); foreach (var obj in completed) { if (obj.Type == OsmSharp.OsmGeoType.Way) { OsmSharp.Complete.CompleteWay way = (OsmSharp.Complete.CompleteWay)obj; var vList = new List <Vertex>(); Vertex fromVertex = null; foreach (OsmSharp.Node node in way.Nodes) { var location = new Coordinates(node.Latitude, node.Longitude); var toVertex = graph.AddVertex(location); if (fromVertex != null) { var edge = new Edge(fromVertex, toVertex); graph.AddEdge(edge); } fromVertex = toVertex; } } } } } graph.CleanGraph(); return(graph); }