예제 #1
0
        private Dictionary<string, object> WriteFeature(Feature feature)
        {
            var result = new Dictionary<string, object>
            {
                { "type", "Feature" },
                { "geometry", WriteGeometry(feature.Geometry) }
            };

            if (feature.Properties != null && feature.Properties.Count > 0)
                result.Add("properties", feature.Properties);
            else
                result.Add("properties", null);

            if (feature.Id != null)
                result.Add("id", feature.Id);

            return result;
        }
예제 #2
0
파일: GeoJsonTests.cs 프로젝트: spadger/Geo
        public void Feature()
        {
            var reader = new GeoJsonReader();
            Assert.AreEqual(@"{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[0,0]},""properties"":null,""id"":""test-id""}",
                new Feature(new Point(0, 0)) { Id = "test-id" }.ToGeoJson()
                );

            Assert.AreEqual(@"{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[0,0]},""properties"":null,""id"":""test-id""}",
                new Feature(new Point(0, 0), new Dictionary<string, object>()) { Id = "test-id" }.ToGeoJson()
                );

            var feature = new Feature(new Point(0, 0), new Dictionary<string, object>()
                                                           {
                                                               {"name", "test"}
                                                           }) {Id = "test-id"};
            Assert.AreEqual(@"{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[0,0]},""properties"":{""name"":""test""},""id"":""test-id""}",
                feature.ToGeoJson()
                );

            var feature2 = (Feature) reader.Read(feature.ToGeoJson());
            Assert.AreEqual(feature.Id, feature2.Id);
            Assert.AreEqual(feature.Geometry, feature2.Geometry);
        }
예제 #3
0
        private bool TryParseFeature(JsonObject obj, out object result)
        {
            string typeString;
            if(TryParseTypeString(obj, out typeString) && typeString.ToLowerInvariant()== "feature")
            {
                object geometry;
                object geo;
                if (obj.TryGetValue("geometry", out geometry) && TryParseGeometry((JsonObject)geometry, out geo))
                {
                    object prop;
                    Dictionary<string, object> pr = null;
                    if (obj.TryGetValue("properties", out prop) && prop is JsonObject)
                    {
                        var props = (JsonObject) prop;
                        if (props.Count > 0)
                        {
                            pr = props.ToDictionary(x => x.Key, x=> SantizeJsonObjects(x.Value));
                        }
                    }

                    result = new Feature((IGeoJsonGeometry)geo, pr);

                    object id;
                    if (obj.TryGetValue("id", out id))
                    {
                        ((Feature) result).Id = SantizeJsonObjects(id);
                    }

                    return true;
                }
            }
            result = null;
            return false;
        }
예제 #4
0
        private Feature GetFeatureFromCarPark(CarPark carPark)
        {
            // Reversed on purpose; result from API is wrong
            var coordinates = new Coordinate(carPark.Latitude, carPark.Longitude);

            var lineString = new Point(coordinates);

            var feature = new Feature(
                lineString,
                new Dictionary<string, object>
                    {
                        { "name", carPark.Name },
                        { "Spaces", carPark.SpacesNow },
                        { "Last Updated", carPark.LastUpdated.ToString("dd/MM/yy HH:mm") },
                        { "Predicted Spaces in 30 mins", carPark.PredictedSpaces30Mins },
                        { "Predicted Spaces in 60 mins", carPark.PredictedSpaces60Mins },
                    });

            feature.Id = carPark.Id.ToString();

            return feature;
        }
예제 #5
0
        private Feature GetFeatureFromMetroShuttle(MetroShuttle metroShuttle)
        {
            // Reversed on purpose; original API is wrong
            var coordinates = new Coordinate(metroShuttle.Latitude, metroShuttle.Longitude);

            var lineString = new Point(coordinates);

            var feature = new Feature(
                lineString,
                new Dictionary<string, object>
                    {
                        { "name", "Metro Shuttle " + metroShuttle.Id },
                        { "Route", metroShuttle.Route },
                        { "Registration", metroShuttle.Registration },
                        { "Last Updated", metroShuttle.LastUpdated.ToString("dd/MM/yy HH:mm") },
                        { "IsParked", metroShuttle.IsParked },
                    });

            feature.Id = metroShuttle.Id.ToString();

            return feature;
        }
예제 #6
0
        /// <summary>
        /// Calculates the route.
        /// </summary>
        /// <param name="transportMode">The transport mode.</param>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <returns>
        /// A new <see cref="RouteModel" /> with the route details.
        /// </returns>
        public RouteModel CalculatePointToPoint(VehicleEnum transportMode, GeoCoordinate start, GeoCoordinate end)
        {
            // calculate route.
            var startPoint = router.Resolve(transportMode, start);
            var endPoint = router.Resolve(transportMode, end);
            var route = router.Calculate(transportMode, startPoint, endPoint);

            if (route == null)
            {
                throw new RoutingException("No matching route found.");
            }

            var coordinates = route.Entries
                .Select(x => new Coordinate(x.Latitude, x.Longitude))
                .ToList();

            var lineString = new LineString(coordinates);

            var feature = new Feature(
                lineString,
                new Dictionary<string, object>
                    {
                        { "name", "Test route result." },
                        { "distance", route.TotalDistance },
                        { "journeytime", route.TotalTime },
                    });

            var generator = new InstructionGenerator();
            var instructions = generator.Generate(route, interpreter, new SimpleEnglishLanguageGenerator());

            return new RouteModel
                       {
                           Results = new ResultSet(feature)
                       };
        }
예제 #7
0
 public string Write(Feature feature)
 {
     return(SimpleJson.SerializeObject(WriteFeature(feature)));
 }
예제 #8
0
 public string Write(Feature feature)
 {
     return SimpleJson.SerializeObject(WriteFeature(feature));
 }
		public object ToFeature(object geometry, object id, Dictionary<string, object> properties)
		{
			var feature = new Feature((IGeometry)geometry, properties);
			if (id != null)
				feature.Id = id;
			return feature;
		}