Esempio n. 1
0
        /// <summary>
        /// Convert an OSMSharp CompleteWay into an array of coordinates. Used by the FeatureInterpreter.
        /// </summary>
        /// <param name="w">The CompleteWay to convert</param>
        /// <returns>An array of coordinate pairs</returns>
        public static Coordinate[] CompleteWayToCoordArray(OsmSharp.Complete.CompleteWay w)
        {
            if (w == null)
            {
                return(null);
            }

            List <Coordinate> results = new List <Coordinate>(w.Nodes.Count());

            foreach (var node in w.Nodes)
            {
                results.Add(new Coordinate(node.Longitude.Value, node.Latitude.Value));
            }

            return(results.ToArray());
        }
Esempio n. 2
0
        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);
        }