Пример #1
0
 public static string ToGeoJson(this Route route)
 {
     return(GeoJsonConverter.ToGeoJson(route.ToFeatureCollection()));
 }
Пример #2
0
        public void RouteToFeatureCollection()
        {
            // build a test route.
            var route = new Route();
            route.Vehicle = Vehicle.Car.UniqueName;
            var route1entry1 = new RouteSegment();
            route1entry1.Distance = 10;
            route1entry1.Latitude = -1;
            route1entry1.Longitude = -1;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = null;
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            var route1entry2 = new RouteSegment();
            route1entry2.Distance = 10;
            route1entry2.Latitude = -1;
            route1entry2.Longitude = -1;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry2.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = null;
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            route.Segments = new RouteSegment[2];
            route.Segments[0] = route1entry1;
            route.Segments[1] = route1entry2;

            // execute the conversion.
            var features = route.ToFeatureCollection();

            // check result, two points, one linestring.
            Assert.IsNotNull(features);
            Assert.AreEqual(3, features.Count);
            var featuresList = new List<Feature>(features);
            Assert.IsInstanceOf<Point>(featuresList[0].Geometry);
            Assert.IsInstanceOf<LineString>(featuresList[1].Geometry);
            Assert.IsInstanceOf<Point>(featuresList[2].Geometry);
        }