public static void AddWays(this Polygon<OSMNode> polygon, IList<OSMWay> ways, OSMDB db)
        {
            if (ways.Count == 1) {
                // Check if the created polygon is closed
                if (ways[0].Nodes.Count > 0 && ways[0].Nodes.First() != ways[0].Nodes.Last()) {
                    throw new ArgumentException("Ways does not form a closed polygon");
                }

                for (int i = 0; i < ways[0].Nodes.Count - 1; i++) {
                    polygon.AddVertex(db.Nodes[ways[0].Nodes[i]]);
                }
            }
            else {
                int lastVertexID = 0;

                if (ways[0].Nodes.First() == ways.Last().Nodes.First() || ways[0].Nodes.Last() == ways.Last().Nodes.First()) {
                    lastVertexID = ways.Last().Nodes.First();
                }
                else {
                    lastVertexID = ways.Last().Nodes.Last();
                }
                //// Check orientation of the first way
                //if (ways[0].Nodes.First() == ways[1].Nodes.First() || ways[0].Nodes.First() == ways[1].Nodes.First()) {
                //  for (int ii = ways[0].; ii < verticesToAdd.Count - 1; ii++) {
                //    AddVertex(verticesToAdd[ii]);
                //  }
                //}

                for (int i = 0; i < ways.Count; i++) {
                    List<int> verticesToAdd = new List<int>();

                    // Checks the way orienatation and picks nodes in correct order
                    if (lastVertexID == ways[i].Nodes[0]) {
                        verticesToAdd.AddRange(ways[i].Nodes);
                    }
                    else if (lastVertexID == ways[i].Nodes.Last()) {
                        verticesToAdd.AddRange(ways[i].Nodes.Reverse());
                    }
                    else {
                        throw new ArgumentException("Can not create polygon, ways aren't connected");
                    }

                    for (int ii = 0; ii < verticesToAdd.Count - 1; ii++) {
                        polygon.AddVertex(db.Nodes[verticesToAdd[ii]]);
                    }

                    lastVertexID = verticesToAdd.Last();
                }

                // Check if the created polygon is closed
                if (polygon.VerticesCount > 0 && polygon.Vertices.First() != db.Nodes[lastVertexID]) {
                    throw new ArgumentException("Ways does not form a closed polygon");
                }
            }
        }
예제 #2
0
        public void PolygonConstructorAcceptsCollectionOfOSMWaysEvenIfTheyAreRevesed()
        {
            OSMDB db = new OSMDB();

            OSMNode p1 = new OSMNode(1, 10, 15);
            OSMNode p2 = new OSMNode(2, 0, 15);
            OSMNode p3 = new OSMNode(3, 0, 0);
            OSMNode p4 = new OSMNode(4, 10, 0);

            OSMWay way1 = new OSMWay(10);
            OSMWay way2 = new OSMWay(11);

            db.Nodes.Add(p1);
            db.Nodes.Add(p2);
            db.Nodes.Add(p3);
            db.Nodes.Add(p4);

            way1.Nodes.Add(p1.ID);
            way1.Nodes.Add(p2.ID);
            way1.Nodes.Add(p3.ID);

            way2.Nodes.Add(p1.ID);
            way2.Nodes.Add(p4.ID);
            way2.Nodes.Add(p3.ID);

            Polygon<OSMNode> target = new Polygon<OSMNode>();
            target.AddWays(new OSMWay[] { way1, way2 }, db);

            Assert.Equal(4, target.VerticesCount);
            CompareVerticesLists(new IPointGeo[] { p1, p2, p3, p4 }, target.Vertices);
        }
예제 #3
0
        public void ExtensionsPolygonAddWaysAcceptsCollectionOfOSMWays()
        {
            OSMDB db = new OSMDB();

            OSMNode p1 = new OSMNode(1, 10, 15);
            OSMNode p2 = new OSMNode(2, 0, 15);
            OSMNode p3 = new OSMNode(3, 0, 0);

            OSMWay way1 = new OSMWay(10);
            OSMWay way2 = new OSMWay(11);

            db.Nodes.Add(p1);
            db.Nodes.Add(p2);
            db.Nodes.Add(p3);

            way1.Nodes.Add(p1.ID);
            way1.Nodes.Add(p2.ID);
            way1.Nodes.Add(p3.ID);

            way2.Nodes.Add(p3.ID);
            way2.Nodes.Add(p1.ID);

            Polygon<OSMNode> target = new Polygon<OSMNode>();
            target.AddWays(new OSMWay[] {way1, way2}, db);

            Assert.Equal(3, target.VerticesCount);
            CompareVerticesLists(new IPointGeo[] { p3, p2, p1 }, target.Vertices);
        }
예제 #4
0
        public void OSMDatabaseConstructorInitializesInternalFields()
        {
            OSMDB target = new OSMDB();

            Assert.Equal(0, target.Nodes.Count);
            Assert.Equal(0, target.Ways.Count);
            Assert.Equal(0, target.Relations.Count);
        }
예제 #5
0
        public void OSMDatabaseLoadCanLoadDataFromOSMFile()
        {
            OSMDB target = new OSMDB();
            target.Load(new MemoryStream(OSMUtils.Tests.TestData.real_osm_file));

            Assert.Equal(408, target.Nodes.Count);
            Assert.Equal(22, target.Ways.Count);
            Assert.Equal(2, target.Relations.Count);
        }
예제 #6
0
        public void OSMDatabaseNodesAcceptsAndReturnsNodes()
        {
            OSMDB target = new OSMDB();
            OSMNode node = new OSMNode(1254, 1.0, 2.0);

            target.Nodes.Add(node);

            Assert.Same(node, target.Nodes[node.ID]);
        }
예제 #7
0
        public void OSMDatabaseNodesAcceptsAndReturnsRelations()
        {
            OSMDB target = new OSMDB();
            OSMRelation relation = new OSMRelation(1454);

            target.Relations.Add(relation);

            Assert.Same(relation, target.Relations[relation.ID]);
        }
예제 #8
0
        public void AnalyzeFindTravelTimePattersInOneDay_Simulated()
        {
            XmlTravelTimeDB db = new XmlTravelTimeDB();
            db.Load(new MemoryStream(TestData.simulated_traffic_db_day));

            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 1));
            map.Nodes.Add(new OSMNode(2, 1.1, 1.1));

            TTAnalyzer analyzer = new TTAnalyzer(map);
            Model target = analyzer.Analyze(db.TravelTimes, db.TravelTimesSegments.First());
        }
예제 #9
0
        public void FromMatchedTrackFindsStartAndEndTimesForSegmentsThatStartAndEndsOnCrossroads()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_2_segments_without_incolmpete_parts));

            var target = TravelTime.FromMatchedTrack(track).ToList();

            Assert.Equal(2, target.Count());
            Assert.Equal(new DateTime(2010, 5, 21, 16, 48, 10), target[0].TimeStart);
            Assert.Equal(new DateTime(2010, 5, 21, 16, 48, 15), target[0].TimeEnd);

            Assert.Equal(new DateTime(2010, 5, 21, 16, 48, 15), target[1].TimeStart);
            Assert.Equal(new DateTime(2010, 5, 21, 16, 49, 19), target[1].TimeEnd);
        }
예제 #10
0
        public void FromMatchedTrackIgnoresFirstAndLastIncompleteSegments()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_2_complete_segments));

            var target = TravelTime.FromMatchedTrack(track).ToList();

            Assert.Equal(2, target.Count());

            SegmentInfo expectedFirstSegment = new SegmentInfo() { NodeFromID = 411888806, NodeToID = 415814332, WayID = 36881783 };
            SegmentInfo expectedSecondSegment = new SegmentInfo() { NodeFromID = 415814332, NodeToID = 74165639, WayID = 36881783 };

            Assert.Equal(expectedFirstSegment, target[0].Segment);
            Assert.Equal(expectedSecondSegment, target[1].Segment);
        }
예제 #11
0
        public void AnalyzeDetectsStopAtTrafficSignals()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_real_traffic_signals));

            var travelTimeAtSignals = TravelTime.FromMatchedTrack(track).First();

            OSMDB map = new OSMDB();
            map.Load(new MemoryStream(TestData.osm_traffic_signals_map));

            TTAnalyzer analyzer = new TTAnalyzer(map);
            Model target = analyzer.Analyze(new TravelTime[] { travelTimeAtSignals }, travelTimeAtSignals.Segment);

            Assert.Equal(30, target.TrafficSignalsDelay.Length);
            Assert.Equal(1.0, target.TrafficSignalsDelay.Probability);
        }
예제 #12
0
        public void OSMDatabaseSaveCanSaveDataToOSMFile()
        {
            OSMDB target = new OSMDB();

            target.Load(new MemoryStream(OSMUtils.Tests.TestData.real_osm_file));

            MemoryStream writtenDb = new MemoryStream();
            target.Save(writtenDb);

            writtenDb.Seek(0, 0);
            OSMDB readDB = new OSMDB();
            readDB.Load(writtenDb);

            Assert.Equal(408, readDB.Nodes.Count);
            Assert.Equal(22, readDB.Ways.Count);
            Assert.Equal(2, readDB.Relations.Count);
        }
예제 #13
0
        static void AddTrackToDB(ITravelTimesDB db, string path)
        {
            OSMDB track = new OSMDB();

            Console.Write("Loading {0} ...", Path.GetFileName(path));
            track.Load(path);

            try {
                var travelTimes = TravelTime.FromMatchedTrack(track);
                foreach (var travelTime in travelTimes) {
                    db.AddTravelTime(travelTime);
                }

                Console.WriteLine(".");
            }
            catch (Exception e) {
                Console.WriteLine("Error: " + e.Message);
            }
        }
예제 #14
0
        public void AnalyzeEstimatesFreeFlowTimeFromFastestLogs()
        {
            List<TravelTime> travelTimes = new List<TravelTime>();
            travelTimes.Add(new TravelTime(new SegmentInfo(), new DateTime(2010, 7, 7, 10, 00, 00), new DateTime(2010, 7, 7, 10, 00, 34)));
            travelTimes.Add(new TravelTime(new SegmentInfo(), new DateTime(2010, 7, 7, 10, 00, 00), new DateTime(2010, 7, 7, 10, 00, 32)));
            travelTimes.Add(new TravelTime(new SegmentInfo(), new DateTime(2010, 7, 7, 10, 00, 00), new DateTime(2010, 7, 7, 10, 00, 30)));
            travelTimes.Add(new TravelTime(new SegmentInfo(), new DateTime(2010, 7, 7, 10, 00, 00), new DateTime(2010, 7, 7, 10, 00, 44)));
            travelTimes.Add(new TravelTime(new SegmentInfo(), new DateTime(2010, 7, 7, 10, 00, 00), new DateTime(2010, 7, 7, 10, 00, 46)));

            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 1));
            map.Nodes.Add(new OSMNode(2, 2, 2));

            TTAnalyzer analyzer = new TTAnalyzer(map);
            Model target = analyzer.Analyze(travelTimes, new SegmentInfo() { NodeFromID = 1, NodeToID = 2, WayID = 100 });

            // average from 3 or 10% fastest
            Assert.Equal(32, target.FreeFlowTravelTime);
        }
예제 #15
0
        public void FromMatchedTrackProcessesInterpolatesTimeToCrossroads()
        {
            OSMDB track = new OSMDB();
            track.Load(new MemoryStream(TestData.osm_2_complete_segments));

            var target = TravelTime.FromMatchedTrack(track).ToList();

            Assert.Equal(2, target.Count());

            DateTime expectedFirstSegmentStart = new DateTime(2010, 5, 21, 16, 48, 16, 320);
            DateTime expectedFirstSegmentEnd = new DateTime(2010, 5, 21, 16, 48, 19, 220);

            DateTime expectedSecondSegmentStart = expectedFirstSegmentEnd;
            DateTime expectedSecondSegmentEnd = new DateTime(2010, 5, 21, 16, 49, 17, 500);

            Assert.InRange(target[0].TimeStart, expectedFirstSegmentStart.AddMilliseconds(-100), expectedFirstSegmentStart.AddMilliseconds(100));
            Assert.InRange(target[0].TimeEnd, expectedFirstSegmentEnd.AddMilliseconds(-100), expectedFirstSegmentEnd.AddMilliseconds(100));
            Assert.InRange(target[1].TimeStart, expectedSecondSegmentStart.AddMilliseconds(-100), expectedSecondSegmentStart.AddMilliseconds(100));
            Assert.InRange(target[1].TimeEnd, expectedSecondSegmentEnd.AddMilliseconds(-100), expectedSecondSegmentEnd.AddMilliseconds(100));
        }
예제 #16
0
        public void RoadGraphBuildCreatesNodesAccordingToMap()
        {
            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 2));
            map.Nodes.Add(new OSMNode(2, 2, 3));

            OSMWay way = new OSMWay(3, new List<int>(new int[] { 1, 2 }));
            way.Tags.Add(new OSMTag("accessible", "no"));
            way.Tags.Add(new OSMTag("accessible-reverse", "yes"));
            way.Tags.Add(new OSMTag("speed", "50"));
            way.Tags.Add(new OSMTag("way-id", "123"));
            map.Ways.Add(way);

            RoadGraph target = new RoadGraph();
            target.Build(map);

            Assert.Equal(2, target.Nodes.Count());
            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[1]).Count());
            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[2]).Count());
        }
예제 #17
0
        public void RoadGraphBuildCreatesCorrectConnectionGeometry()
        {
            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 2));
            map.Nodes.Add(new OSMNode(2, 2, 3));
            map.Nodes.Add(new OSMNode(3, 3, 4));

            OSMWay way = new OSMWay(4, new int[] { 1, 2, 3 });
            way.Tags.Add(new OSMTag("accessible", "yes"));
            way.Tags.Add(new OSMTag("accessible-reverse", "yes"));
            way.Tags.Add(new OSMTag("speed", "50"));
            way.Tags.Add(new OSMTag("way-id", "123"));
            map.Ways.Add(way);

            RoadGraph target = new RoadGraph();
            target.Build(map);

            Assert.Equal(1, target.ConnectionGeometries.Count());
            Assert.Equal(3, target.ConnectionGeometries.Single().Nodes.Count);
        }
예제 #18
0
        public void RoadGraphBuildCreatesOneWayConnectionForOnewayRoads1()
        {
            OSMDB map = new OSMDB();
            map.Nodes.Add(new OSMNode(1, 1, 1));
            map.Nodes.Add(new OSMNode(2, 2, 2));

            OSMWay way = new OSMWay(3, new List<int>(new int[] { 1, 2 }));
            way.Tags.Add(new OSMTag("accessible", "yes"));
            way.Tags.Add(new OSMTag("accessible-reverse", "no"));
            way.Tags.Add(new OSMTag("speed", "50"));
            way.Tags.Add(new OSMTag("way-id", "123"));
            map.Ways.Add(way);

            RoadGraph target = new RoadGraph();
            target.Build(map);

            Assert.Equal(1, target.Connections.Count());
            Assert.Equal(1, target.Connections.Where(c => c.From.MapPoint == map.Nodes[1] && c.To.MapPoint == map.Nodes[2]).Count());

            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[1]).Single().Connections.Count());
            Assert.Equal(1, target.Nodes.Where(n => n.MapPoint == map.Nodes[2]).Single().Connections.Count());
        }
예제 #19
0
        public static void SaveCandidateIncomingConnections(CandidatePoint candidate, string filename)
        {
            int counter = -1;
            OSMDB result = new OSMDB();

            OSMNode osmCandidate = new OSMNode(counter--, candidate.MapPoint.Latitude, candidate.MapPoint.Longitude);
            osmCandidate.Tags.Add(new OSMTag("observation", candidate.ObservationProbability.ToString()));
            osmCandidate.Tags.Add(new OSMTag("time", candidate.Layer.TrackPoint.Time.ToString()));
            result.Nodes.Add(osmCandidate);
            foreach (var connection in candidate.IncomingConnections) {
                OSMNode from = new OSMNode(counter--, connection.From.MapPoint.Latitude, connection.From.MapPoint.Longitude);
                from.Tags.Add(new OSMTag("observation", connection.From.ObservationProbability.ToString()));
                from.Tags.Add(new OSMTag("time", connection.From.Layer.TrackPoint.Time.ToString()));
                result.Nodes.Add(from);

                OSMWay osmConnection = new OSMWay(counter--, new int[] { from.ID, osmCandidate.ID });
                osmConnection.Tags.Add(new OSMTag("transmission", connection.TransmissionProbability.ToString()));

                result.Ways.Add(osmConnection);
            }

            result.Save(filename);
        }
예제 #20
0
        /// <summary>
        /// Creates a list of travel times from the matched track
        /// </summary>
        /// <param name="track"></param>
        /// <returns></returns>
        public static IEnumerable<TravelTime> FromMatchedTrack(OSMDB track)
        {
            List<TravelTime> result = new List<TravelTime>();
            var orderedWays = track.Ways.OrderBy(way => int.Parse(way.Tags["order"].Value)).ToList();

            //Find start of the first segment
            int index = 0;
            while (index < orderedWays.Count && track.Nodes[orderedWays[index].Nodes[0]].Tags.ContainsTag("crossroad") == false)
                index++;

            while (index < orderedWays.Count) {
                int startNodeId = int.Parse(track.Nodes[orderedWays[index].Nodes[0]].Tags["node-id"].Value);
                DateTime segmentStartTime = DateTime.MinValue;
                if (track.Nodes[orderedWays[index].Nodes[0]].Tags.ContainsTag("time"))
                    segmentStartTime = DateTime.Parse(track.Nodes[orderedWays[index].Nodes[0]].Tags["time"].Value);
                else
                    segmentStartTime = InterpolateStartTime(track, orderedWays, index);

                List<GPXPoint> points = new List<GPXPoint>();
                points.Add(new GPXPoint(track.Nodes[orderedWays[index].Nodes[0]].Latitude, track.Nodes[orderedWays[index].Nodes[0]].Longitude, segmentStartTime));

                while (index < orderedWays.Count && track.Nodes[orderedWays[index].Nodes.Last()].Tags.ContainsTag("crossroad") == false) {
                    if (track.Nodes[orderedWays[index].Nodes.Last()].Tags.ContainsTag("time")) {
                        points.Add(new GPXPoint(track.Nodes[orderedWays[index].Nodes.Last()].Latitude, track.Nodes[orderedWays[index].Nodes.Last()].Longitude,
                            DateTime.Parse(track.Nodes[orderedWays[index].Nodes.Last()].Tags["time"].Value)));
                    }

                    index++;
                }

                if (index < orderedWays.Count) {
                    int endNodeId = int.Parse(track.Nodes[orderedWays[index].Nodes.Last()].Tags["node-id"].Value);

                    DateTime segmentEndTime = DateTime.MinValue;
                    if (track.Nodes[orderedWays[index].Nodes.Last()].Tags.ContainsTag("time"))
                        segmentEndTime = DateTime.Parse(track.Nodes[orderedWays[index].Nodes.Last()].Tags["time"].Value);
                    else
                        segmentEndTime = InterpolateEndTime(track, orderedWays, index);

                    points.Add(new GPXPoint(track.Nodes[orderedWays[index].Nodes.Last()].Latitude, track.Nodes[orderedWays[index].Nodes.Last()].Longitude, segmentEndTime));

                    int wayId = int.Parse(orderedWays[index].Tags["way-id"].Value);
                    SegmentInfo segment = new SegmentInfo() { NodeFromID = startNodeId, NodeToID = endNodeId, WayID = wayId };
                    List<double> avgSpeeds = new List<double>();
                    for (int i = 0; i < points.Count -1; i++) {
                        avgSpeeds.Add(Calculations.GetDistance2D(points[i], points[i + 1]) / (points[i + 1].Time - points[i].Time).TotalSeconds);
                    }

                    TravelTime tt = new TravelTime(segment, segmentStartTime, segmentEndTime);
                    int ii = 0;
                    while (ii < avgSpeeds.Count) {
                        if (avgSpeeds[ii] < 1.0) {
                            Stop stop = new Stop() { From = points[ii].Time };
                            while (ii < avgSpeeds.Count && avgSpeeds[ii] < 1.0)
                                ii++;

                            stop.To = points[ii].Time;
                            tt.Stops.Add(stop);
                        }
                        ii++;
                    }

                    result.Add(tt);

                    index++;
                }
            }

            return result;
        }
예제 #21
0
        /// <summary>
        /// Get length of the OSMWay in meters
        /// </summary>
        /// <param name="way"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        static double GetLength(OSMWay way, OSMDB db)
        {
            double result = 0;
            for (int i = 0; i < way.Nodes.Count - 1; i++) {
                result += LK.GeoUtils.Calculations.GetDistance2D(db.Nodes[way.Nodes[i]], db.Nodes[way.Nodes[i + 1]]);
            }

            return result;
        }
예제 #22
0
        /// <summary>
        /// Estimates Start of the travel time as an inerpolation between neighbour points
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ways"></param>
        /// <param name="segmentIndex"></param>
        /// <returns></returns>
        static DateTime InterpolateStartTime(OSMDB db, IList<OSMWay> ways, int segmentIndex)
        {
            double lenghtBefore = 0;
            int i = segmentIndex;
            while (i >= 0 && db.Nodes[ways[i].Nodes[0]].Tags.ContainsTag("time") == false) {
                i--;
                lenghtBefore += GetLength(ways[i], db);
            }

            DateTime lastTime = DateTime.MinValue;
            if (i >= 0)
                lastTime = DateTime.Parse(db.Nodes[ways[i].Nodes[0]].Tags["time"].Value);
            else
                throw new ArgumentException("Can not find segment start time");

            double lengthAfter = 0;
            i = segmentIndex;
            while (i < ways.Count && db.Nodes[ways[i].Nodes.Last()].Tags.ContainsTag("time") == false) {
                i++;
                lengthAfter += GetLength(ways[i], db);
            }

            DateTime nextTime = DateTime.MinValue;
            if (i < ways.Count)
                nextTime = DateTime.Parse(db.Nodes[ways[i].Nodes.Last()].Tags["time"].Value);
            else
                throw new ArgumentException("Can not find segment end time");

            double miliseconds = (nextTime - lastTime).TotalMilliseconds;
            double totalLength = lenghtBefore + GetLength(ways[segmentIndex], db) + lengthAfter;

            if (totalLength > 0)
                return lastTime.AddMilliseconds(miliseconds * lenghtBefore / totalLength);
            else
                return lastTime.AddMilliseconds(miliseconds);
        }
예제 #23
0
        /// <summary>
        /// Builds road graph from map data
        /// </summary>
        /// <param name="map">OSMDB with preprocessed map data from OSM2Routing utility</param>
        public void Build(OSMDB map)
        {
            Dictionary<int, Node> usedNodes = new Dictionary<int, Node>();

            foreach (var segment in map.Ways) {
                Node start = GetOrCreateNode(segment.Nodes[0], usedNodes);
                try {
                    start.MapPoint = map.Nodes[segment.Nodes[0]];
                }
                catch (ArgumentException) {
                    continue; // If the start node was not found in the database, skip this path completely
                }

                Node end = GetOrCreateNode(segment.Nodes[segment.Nodes.Count - 1], usedNodes);
                try {
                    end.MapPoint = map.Nodes[segment.Nodes[segment.Nodes.Count - 1]];
                }
                catch (ArgumentException) {
                    continue; // If the end node was not found in the database, skip this path completely
                }

                double speed = double.Parse(segment.Tags["speed"].Value, System.Globalization.CultureInfo.InvariantCulture);
                int wayId = int.Parse(segment.Tags["way-id"].Value, System.Globalization.CultureInfo.InvariantCulture);

                ConnectionGeometry geometry = new ConnectionGeometry();
                geometry.WayID = wayId;
                foreach (var n in segment.Nodes) {
                    try {
                        OSMNode mapPoint = map.Nodes[n];
                        geometry.Nodes.Add(mapPoint);
                        //geometry.Nodes.Add(new PointGeo(mapPoint.Latitude, mapPoint.Longitude));
                    }
                    catch (ArgumentException) {
                    continue; // If an intermediate node was not found in the database, skip just that node
                    }
                }
                _connectionGeometries.Add(geometry);

                if (segment.Tags["accessible"].Value == "yes") {
                    Connection sc = new Connection(start, end) { Speed = speed, Geometry = geometry };
                    geometry.Connections.Add(sc);
                    _connections.Add(sc);
                }

                if (segment.Tags["accessible-reverse"].Value == "yes") {
                    Connection sc = new Connection(end, start) { Speed = speed, Geometry = geometry };
                    geometry.Connections.Add(sc);
                    _connections.Add(sc);
                }
            }
        }
예제 #24
0
        static void Main(string[] args)
        {
            string osmPath = "";
            string gpxPath = "";
            string outputPath = ".";
            int samplingPeriod = 0;
            bool showHelp = false;
            bool filter = false;

            OptionSet parameters = new OptionSet() {
                { "osm=", "path to the routable map file",																				v => osmPath = v},
                { "gpx=",	"path to the GPX file to process or to the directory to process",				v => gpxPath = v},
                { "o|output=", "path to the output directory",																		v => outputPath = v},
                { "p|period=", "sampling period of the GPX file",																	v => samplingPeriod = int.Parse(v)},
                { "f|filter", "enables output post processing",																		v => filter = v != null},
                { "h|?|help",																																			v => showHelp = v != null},
            };

            try {
                parameters.Parse(args);
            }
            catch (OptionException e) {
                Console.Write("MatchGPX2OSM: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `matchgpx2osm --help' for more information.");
                return;
            }

            if (showHelp || string.IsNullOrEmpty(osmPath) || string.IsNullOrEmpty(gpxPath) || string.IsNullOrEmpty(outputPath)) {
                ShowHelp(parameters);
                return;
            }

            Console.Write("Loading OSM file ...");
            OSMDB map = new OSMDB();
            map.Load(osmPath);
            Console.WriteLine("\t\t\tDone.");

            Console.Write("Building routable road graph ...");
            RoadGraph graph = new RoadGraph();
            graph.Build(map);
            Console.WriteLine("\tDone.");

            STMatching processor = new STMatching(graph);
            PathReconstructer reconstructor = new PathReconstructer(graph);

            // Process signle file
            if (File.Exists(gpxPath)) {
                ProcessGPXFile(gpxPath, processor, reconstructor, outputPath, samplingPeriod, filter);
            }
            // Process all GPX in directory
            else if (Directory.Exists(gpxPath)) {
                var files = Directory.GetFiles(gpxPath, "*.gpx");
                Console.WriteLine("Found {0} GPX file(s).", files.Length);

                foreach (var file in files) {
                    ProcessGPXFile(file, processor, reconstructor, outputPath, samplingPeriod, filter);
                    Console.WriteLine();
                }
            }
            else {
                Console.WriteLine("No GPX files found");
            }
        }
예제 #25
0
        public void OSMDatabaseWaysAcceptsAndReturnsWays()
        {
            OSMDB target = new OSMDB();
            OSMWay way = new OSMWay(1354);

            target.Ways.Add(way);

            Assert.Same(way, target.Ways[way.ID]);
        }
예제 #26
0
        public void PolygonConstructorThrowsExceptionIfInitializedWithSingleOpenWay()
        {
            OSMDB db = new OSMDB();

            OSMNode p1 = new OSMNode(1, 10, 15);
            OSMNode p2 = new OSMNode(2, 0, 15);
            OSMNode p3 = new OSMNode(3, 0, 0);

            OSMWay way1 = new OSMWay(10);

            db.Nodes.Add(p1);
            db.Nodes.Add(p2);
            db.Nodes.Add(p3);

            way1.Nodes.Add(p1.ID);
            way1.Nodes.Add(p2.ID);
            way1.Nodes.Add(p3.ID);

            Polygon<OSMNode> target = new Polygon<OSMNode>();
            Assert.Throws<ArgumentException>(delegate { target.AddWays(new OSMWay[] { way1 }, db); });
        }
예제 #27
0
 /// <summary>
 /// Creates a new instance of the OSMFIlteredDB
 /// </summary>
 public OSMRoutingDB()
 {
     _storage = new OSMDB();
     _usedNodes = new Dictionary<int, List<int>>();
     _ways = new Dictionary<int, int>();
 }
예제 #28
0
 /// <summary>
 /// Creates a new instance of the analyzer
 /// </summary>
 /// <param name="map"></param>
 public TTAnalyzer(OSMDB map)
 {
     _map = map;
 }
예제 #29
0
        /// <summary>
        /// Splits ways at road crossings, check for oneway roads and save results in OSMDB
        /// </summary>
        /// <returns>OSMDB object with road segments and used nodes</returns>
        public OSMDB BuildRoutableOSM()
        {
            OSMDB result = new OSMDB();
            int counter = -1;

            foreach (OSMRoad route in _storage.Ways) {
                OSMWay segment = new OSMWay(counter--);
                OSMTag wayIDTag = new OSMTag("way-id", route.ID.ToString());
                OSMTag speedTag = new OSMTag("speed", route.Speed.ToString());

                string wayAccessibility = route.IsAccessible() ? "yes" : "no";
                OSMTag wayAccessibilityTag = new OSMTag("accessible", wayAccessibility);

                string wayAccessibilityReverse = route.IsAccessibleReverse() ? "yes" : "no";
                OSMTag wayAccessibilityReverseTag = new OSMTag("accessible-reverse", wayAccessibilityReverse);

                for (int i = 0; i < route.Nodes.Count; i++) {
                    segment.Nodes.Add(route.Nodes[i]);

                    if ((UsedNodes[route.Nodes[i]].Count > 1) && (i > 0) && (i < (route.Nodes.Count - 1))) {
                        segment.Tags.Add(wayIDTag);
                        segment.Tags.Add(speedTag);
                        segment.Tags.Add(wayAccessibilityTag);
                        segment.Tags.Add(wayAccessibilityReverseTag);

                        result.Ways.Add(segment);

                        segment = new OSMWay(counter--);
                        segment.Nodes.Add(route.Nodes[i]);
                    }
                }

                segment.Tags.Add(wayIDTag);
                segment.Tags.Add(speedTag);
                segment.Tags.Add(wayAccessibilityTag);
                segment.Tags.Add(wayAccessibilityReverseTag);
                result.Ways.Add(segment);
            }

            foreach (OSMNode node in _storage.Nodes) {
                OSMNode newNode = new OSMNode(node.ID, node.Latitude, node.Longitude);

                // preserve junction and highway tags on nodes
                if (node.Tags.ContainsTag("junction")) {
                    newNode.Tags.Add(node.Tags["junction"]);
                }
                if (node.Tags.ContainsTag("highway")) {
                    newNode.Tags.Add(node.Tags["highway"]);
                }

                if (_usedNodes[node.ID].Count > 1) {
                    newNode.Tags.Add(new OSMTag("crossroad", "yes"));
                }

                result.Nodes.Add(newNode);
            }

            return result;
        }
예제 #30
0
        public void PolygonConstructorThrowsExceptionIfWaysDontFormClosedPolygon()
        {
            OSMDB db = new OSMDB();

            OSMNode p1 = new OSMNode(1, 10, 15);
            OSMNode p2 = new OSMNode(2, 0, 15);
            OSMNode p3 = new OSMNode(3, 0, 0);
            OSMNode p4 = new OSMNode(4, 10, 0);

            OSMWay way1 = new OSMWay(10);
            OSMWay way2 = new OSMWay(11);

            db.Nodes.Add(p1);
            db.Nodes.Add(p2);
            db.Nodes.Add(p3);
            db.Nodes.Add(p4);

            way1.Nodes.Add(p1.ID);
            way1.Nodes.Add(p2.ID);
            way1.Nodes.Add(p3.ID);

            way2.Nodes.Add(p3.ID);
            way2.Nodes.Add(p4.ID);

            Polygon<OSMNode> target = new Polygon<OSMNode>();
            Assert.Throws<ArgumentException>(delegate { target.AddWays(new OSMWay[] { way1, way2 }, db); });
        }