/// <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)); } }
/// <summary> /// Converts the given route to a feature collection. /// </summary> public abstract FeatureCollection GetFeatures(Route route, RouteAggregationType aggregationType);
/// <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); } }
/// <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; } }
public override FeatureCollection GetFeatures(Route route, RouteAggregationType aggregationType) { throw new NotImplementedException(); }
/// <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); } }