Esempio n. 1
0
        public static kmlDocumentPlacemark GLOSATestRoutePlacemark(string id)
        {
            var list = LoadPlacemarksFromFile("GreenLight.Core.Test.GLOSA-MAP-CHACHE.kml") as List <kmlDocumentPlacemark>;
            kmlDocumentPlacemark placemark = list.Find(obj => obj.name.Contains(id));

            return(placemark);
        }
Esempio n. 2
0
        public static double DistanceFromCurrentIntersection(kmlDocumentPlacemark kml, double currentLatitude, double currentLongitude)
        {
            var coordinatesString = kml.Point.coordinates;

            string[] parts     = coordinatesString.Split(',');
            double   longitude = double.Parse(parts[0]);
            double   latitude  = double.Parse(parts[1]);

            var distanceMeters = Distance.CalculateDistanceBetween2PointsKMs(currentLatitude, currentLongitude, latitude, longitude) * 1000.0;

            return(distanceMeters);
        }
Esempio n. 3
0
        public static string IntersectionIdOfPlacemark(kmlDocumentPlacemark placemark)
        {
            string id    = null;
            var    name  = placemark.name;
            var    array = name.Split('-');

            if (array != null && array.Count() > 0)
            {
                id = array[0];
            }

            return(id);
        }
        public kmlDocumentPlacemark LocateWaypointOnRoute(WaypointDetectionMethod method, List <kmlDocumentPlacemark> route, List <GPSLocation> history, double heading, int waypointIndex = 0)
        {
            kmlDocumentPlacemark nearestMAPPlacemark = null;

            var location = history.Last();

            var sortedMAPPoints = GLOSAHelper.SortMAPKMLDataByDistanceFromCurrentLocation(route, location.Latitude, location.Longitude).ToList();

            if (sortedMAPPoints != null && sortedMAPPoints.Count > 0)
            {
                if (method == WaypointDetectionMethod.ShortestDistance)
                {
                    nearestMAPPlacemark = sortedMAPPoints.First();
                }
                else if (method == WaypointDetectionMethod.DeviceHeading)
                {
                    // No valid method chosen
                    throw new Exception("Waypoint Detection Method not implemented.");
                }
                else if (method == WaypointDetectionMethod.GPSHistoryDirection)
                {
                    List <TrafficNode> listOfWaypoints = new List <TrafficNode>();

                    GPSLocation from = history[history.Count - 2];
                    GPSLocation to   = history[history.Count - 1];

                    double?vehicleBearing = LocationHelper.HeadingBetweenTwoGPSLocations(from, to);

                    foreach (var mapPoint in sortedMAPPoints)
                    {
                        listOfWaypoints.Add(new TrafficNode()
                        {
                            GPSLocation = KMLHelper.XMLCoordinateStringToGPSLocation(mapPoint.Point.coordinates),
                            ID          = mapPoint.name,
                            angleDiff   = 0,
                        });
                    }

                    foreach (var waypoint in listOfWaypoints)
                    {
                        double?bearingLocationToWaypoint = LocationHelper.HeadingBetweenTwoGPSLocations(to, waypoint.GPSLocation);
                        double delta = LocationHelper.DeltaOfVehicleToLaneDirection(vehicleBearing, bearingLocationToWaypoint);
                        waypoint.angleDiff = Math.Abs(delta);//Make positive
                        waypoint.distance  = Distance.CalculateDistanceBetween2PointsKMs(to.Latitude, to.Longitude, waypoint.GPSLocation.Latitude, waypoint.GPSLocation.Longitude);
                    }

                    var sortedByBearingAndDistance = listOfWaypoints.OrderBy(wp => wp.distance)
                                                     .ThenBy(wp => wp.angleDiff)
                                                     .Where(wp => wp.angleDiff >= -50 && wp.angleDiff <= 50 && wp.distance <= 1.0);

                    if (sortedByBearingAndDistance != null && sortedByBearingAndDistance.Count() > waypointIndex)
                    {
                        var tn = sortedByBearingAndDistance.ToList()[waypointIndex];
                        var pm = sortedMAPPoints.Find(mp => mp.name == tn.ID);
                        nearestMAPPlacemark = pm;
                    }
                }
                else
                {
                    // No valid method chosen
                    throw new Exception("Waypoint Detection Method not properly set.");
                }
            }
            return(nearestMAPPlacemark);
        }