Пример #1
0
        public static bool ProjectOn(this Route route, GeoCoordinate coordinates, out GeoCoordinate projectedCoordinates, out int entryIndex, out Meter distanceFromStart, out Second timeFromStart)
        {
            double num1 = double.MaxValue;

            distanceFromStart = (Meter)0.0;
            timeFromStart     = (Second)0.0;
            double num2 = 0.0;

            projectedCoordinates = (GeoCoordinate)null;
            entryIndex           = -1;
            List <GeoCoordinate> points = route.GetPoints();

            for (int index = 0; index < points.Count - 1; ++index)
            {
                PointF2D pointF2D = new GeoCoordinateLine(points[index], points[index + 1], true, true).ProjectOn((PointF2D)coordinates);
                if (pointF2D != (PointF2D)null)
                {
                    GeoCoordinate point = new GeoCoordinate(pointF2D[1], pointF2D[0]);
                    double        num3  = coordinates.Distance(point);
                    if (num3 < num1)
                    {
                        projectedCoordinates = point;
                        entryIndex           = index;
                        num1 = num3;
                        double num4 = point.DistanceReal(points[index]).Value;
                        distanceFromStart = (Meter)(num2 + num4);
                    }
                }
                GeoCoordinate point1 = points[index];
                double        num5   = coordinates.Distance(point1);
                if (num5 < num1)
                {
                    projectedCoordinates = point1;
                    entryIndex           = index;
                    num1 = num5;
                    distanceFromStart = (Meter)num2;
                }
                num2 += points[index].DistanceReal(points[index + 1]).Value;
            }
            GeoCoordinate point2 = points[points.Count - 1];

            if (coordinates.Distance(point2) < num1)
            {
                projectedCoordinates = point2;
                entryIndex           = points.Count - 1;
                distanceFromStart    = (Meter)num2;
            }
            return(true);
        }
Пример #2
0
        public static GeoCoordinate PositionAfter(this Route route, Meter m)
        {
            double num1 = 0.0;
            List <GeoCoordinate> points = route.GetPoints();

            for (int index = 0; index < points.Count - 1; ++index)
            {
                double num2 = points[index].DistanceReal(points[index + 1]).Value;
                if (num1 + num2 >= m.Value)
                {
                    double    num3      = m.Value - num1;
                    VectorF2D vectorF2D = ((PointF2D)points[index + 1] - (PointF2D)points[index]) * (num3 / num2);
                    PointF2D  pointF2D  = (PointF2D)points[index] + vectorF2D;
                    return(new GeoCoordinate(pointF2D[1], pointF2D[0]));
                }
                num1 += num2;
            }
            return((GeoCoordinate)null);
        }
Пример #3
0
        /// <summary>
        /// Converts the given route to a line string.
        /// </summary>
        /// <returns></returns>
        public override FeatureCollection GetFeatures(Route route, RouteAggregationType aggregationType)
        {
            if (aggregationType == RouteAggregationType.All ||
                aggregationType == RouteAggregationType.Modal)
            { // one mode, one LineString.
                var featureCollection = new FeatureCollection();
                var coordinates = route.GetPoints();
                if (coordinates.Count > 1)
                {
                    var lineString = new LineString(coordinates.ToArray());

                    var attributes = new SimpleGeometryAttributeCollection();
                    attributes.Add("osmsharp:total_time", route.TotalTime.ToInvariantString());
                    attributes.Add("osmsharp:total_distance", route.TotalDistance.ToInvariantString());

                    var feature = new Feature(lineString, attributes);

                    featureCollection.Add(feature);
                }
                return featureCollection;
            }
            else
            { // one LineString per instruction.
                var instructions = this.GetInstructions(route);
                var featureCollection = new FeatureCollection();
                for (int i = 0; i < instructions.Count; i++)
                {
                    var instruction = instructions[i];
                    var coordinates = new List<GeoCoordinate>();
                    for (int segmentIdx = instruction.FirstSegmentIdx; segmentIdx <= instruction.LastSegmentIdx; segmentIdx++)
                    {
                        coordinates.Add(new GeoCoordinate(route.Segments[segmentIdx].Latitude, route.Segments[segmentIdx].Longitude));
                    }

                    // build attributes.
                    var currentArcTags = instruction.MetaData;
                    var attributesTable = new SimpleGeometryAttributeCollection();
                    if (currentArcTags != null)
                    { // there are tags.
                        foreach (var tag in currentArcTags)
                        {
                            if (tag.Value != null)
                            {
                                var t = tag.Value.GetType();
                                if (t.IsPrimitive || t == typeof(Decimal) || t == typeof(String))
                                {
                                    attributesTable.Add(tag.Key, tag.Value);
                                }
                            }
                        }
                    }

                    // build feature.
                    var lineString = new LineString(coordinates);
                    featureCollection.Add(new Feature(lineString, attributesTable));

                    // build poi-features if any.
                    if (instruction.Pois != null)
                    {
                        foreach (var poi in instruction.Pois)
                        {
                            // build attributes.
                            var poiTags = poi.Tags;
                            var poiAttributesTable = new SimpleGeometryAttributeCollection();
                            if (poiTags != null)
                            { // there are tags.
                                foreach (var tag in poiTags)
                                {
                                    poiAttributesTable.Add(tag.Key, tag.Value);
                                }
                            }

                            // build feature.
                            var point = new Point(poi.Location);
                            featureCollection.Add(new Feature(point, poiAttributesTable));
                        }
                    }
                }
                return featureCollection;
            }
        }
Пример #4
0
 public static GeoCoordinateBox GetBox(this Route route)
 {
     return(new GeoCoordinateBox(route.GetPoints().ToArray()));
 }
        /// <summary>
        /// Gets a feature collection representing the given route based on the given aggregation type.
        /// </summary>
        /// <param name="route"></param>
        /// <param name="aggregationType"></param>
        /// <returns></returns>
        public override FeatureCollection GetFeatures(Route route, RouteAggregationType aggregationType)
        {
            if (route == null) { throw new ArgumentNullException("route"); }
            if (aggregationType == RouteAggregationType.All)
            {  // one LineString.
                var featureCollection = new FeatureCollection();
                var coordinates = route.GetPoints();
                if (coordinates.Count > 1)
                {
                    var lineString = new LineString(coordinates.ToArray());

                    var attributes = new SimpleGeometryAttributeCollection();
                    attributes.Add("osmsharp:total_time", route.TotalTime.ToInvariantString());
                    attributes.Add("osmsharp:total_distance", route.TotalDistance.ToInvariantString());

                    var feature = new Feature(lineString, attributes);

                    featureCollection.Add(feature);
                }
                return featureCollection;
            }
            else if(aggregationType == RouteAggregationType.Modal)
            { // modal.
                // aggregate.
                var aggregator = new ModalAggregator(new OsmRoutingInterpreter());
                var microPlanner = new ModalMicroPlanner(new ModalLanguageGenerator(), new OsmRoutingInterpreter());
                var aggregated = aggregator.Aggregate(route);
                var instructions = InstructionGenerator.Generate(microPlanner, route, aggregated);

                return this.GetFeatures(route, instructions);
            }
            else // modal and instructions.
            { // instructions.
                var instructions = this.GetInstructions(route);

                return this.GetFeatures(route, instructions);
            }
        }