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; }
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); }
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; }
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; }
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; }
/// <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) }; }
public string Write(Feature feature) { return(SimpleJson.SerializeObject(WriteFeature(feature))); }
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; }