private string GetGeoJsonString(List <PropertyList> properties) { string serializedData = null; var modelF = new List <GeoJSON.Net.Feature.Feature>(); foreach (var prop in properties) { var point = new GeoJSON.Net.Geometry.Point(new GeoJSON.Net.Geometry.GeographicPosition(Convert.ToDouble(prop.LAT.ToString()), Convert.ToDouble(prop.LONG.ToString()))); var featureProperties = new Dictionary <string, object> { }; object val = null; foreach (PropertyInfo propInfo in prop.GetType().GetProperties()) { val = prop.GetType().GetProperty(propInfo.Name).GetValue(prop, null); featureProperties.Add(propInfo.Name, val == null ? "" : val.ToString()); } modelF.Add(new GeoJSON.Net.Feature.Feature(point, featureProperties)); } var fcol = new FeatureCollection(modelF); serializedData = JsonConvert.SerializeObject(fcol, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore }); return(serializedData); }
private GeoJSON.Net.Geometry.MultiPoint GetGeoJsonNetMultiPoint() { if (routes != null && routes.Length > 0) { var route = routes[0]; if (route.geometry != null) { if (route.geometry.coordinates != null && route.geometry.coordinates.Length > 0) { List <GeoJSON.Net.Geometry.Point> points = new List <GeoJSON.Net.Geometry.Point>(); foreach (float[] coordinate in route.geometry.coordinates) { float longitude = coordinate[0]; float latitude = coordinate[1]; GeoJSON.Net.Geometry.Position position = new GeoJSON.Net.Geometry.Position(latitude, longitude); GeoJSON.Net.Geometry.Point point = new GeoJSON.Net.Geometry.Point(position); points.Add(point); } return(new GeoJSON.Net.Geometry.MultiPoint(points)); } } } throw new ArgumentException(); }
static public Point ToPoint(this GeoJSON.Net.Geometry.Point geoJsonPoint) { if (geoJsonPoint?.Coordinates != null) { return(new Point(geoJsonPoint.Coordinates.Longitude, geoJsonPoint.Coordinates.Latitude)); } return(null); }
public void ShouldMapCollision() { //Given var now = DateTime.Now; var point = new GeoJSON.Net.Geometry.Point(new GeoJSON.Net.Geometry.Position(-45.12638971, 122.54672893563)); var Collision = new CollisionDTO { Date = now, Location = point }; //When var dbCollision = Mapper.Map <Collision>(Collision); //Then Assert.NotNull(dbCollision); Assert.Equal(now.TimeOfDay, dbCollision.Time); }
public void ShouldMapDeployment() { //Given var now = DateTime.Now; var point = new GeoJSON.Net.Geometry.Point(new GeoJSON.Net.Geometry.Position(-45.12638971, 122.54672893563)); var deployment = new DeploymentDTO { StartTime = now, EndTime = now, Location = point }; //When var dbDeployment = Mapper.Map <Deployment>(deployment); //Then Assert.NotNull(dbDeployment); Assert.Equal(now.TimeOfDay, dbDeployment.StartTime); Assert.Equal(now.TimeOfDay, dbDeployment.EndTime); }
// public JsonResult WITHIN(string key, double xMin, double yMin, double xMax, double yMax){ public JsonResult WITHIN(string key, string xMin, string yMin, string xMax, string yMax, string resubscribeToEvents) { try{ if (redis == null) { string tile38Connection = _configuration.GetConnectionString("Tile38Connection"); redis = ConnectionMultiplexer.Connect(tile38Connection); _logger.LogInformation($"Connected to Tile38 {tile38Connection}"); } db = redis.GetDatabase(); _logger.LogInformation($"WITHIN {key} BOUNDS {xMin} {yMin} {xMax} {yMax}"); var result = db.Execute("WITHIN", key, "BOUNDS", xMin, yMin, xMax, yMax); _logger.LogInformation(result.ToString()); GeoJSON.Net.Feature.FeatureCollection featureCollection = new GeoJSON.Net.Feature.FeatureCollection(); // Top level - collection of features System.Diagnostics.Debug.Assert(result.Type == ResultType.MultiBulk); RedisResult[] withinResult = ((RedisResult[])result); System.Diagnostics.Debug.Assert(withinResult[0].Type == ResultType.Integer); _logger.LogInformation($"WITHIN returned {withinResult[0]} features"); System.Diagnostics.Debug.Assert(withinResult[1].Type == ResultType.MultiBulk); RedisResult[] withinFeatures = ((RedisResult[])withinResult[1]); foreach (RedisResult featureResult in withinFeatures) { System.Diagnostics.Debug.Assert(featureResult.Type == ResultType.MultiBulk); RedisResult[] featureDetails = ((RedisResult[])featureResult); System.Diagnostics.Debug.Assert(featureDetails.Length == 2); System.Diagnostics.Debug.Assert(featureDetails[0].Type == ResultType.BulkString); // ID System.Diagnostics.Debug.Assert(featureDetails[1].Type == ResultType.BulkString); // GeoJSON if (featureDetails[1].ToString().StartsWith("{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\"")) { // _logger.LogInformation("Found GeoJSON!"); GeoJSON.Net.Feature.Feature feature = Newtonsoft.Json.JsonConvert.DeserializeObject <GeoJSON.Net.Feature.Feature>(featureDetails[1].ToString()); featureCollection.Features.Add(feature); if (!feature.Properties.ContainsKey("id")) { feature.Properties["id"] = featureDetails[0].ToString(); } } else { if (featureDetails[1].ToString().StartsWith("{\"type\":\"Point\"")) { // _logger.LogInformation("Found GeoJSON!"); GeoJSON.Net.Geometry.Point point = Newtonsoft.Json.JsonConvert.DeserializeObject <GeoJSON.Net.Geometry.Point>(featureDetails[1].ToString()); GeoJSON.Net.Feature.Feature feature = new GeoJSON.Net.Feature.Feature(point); featureCollection.Features.Add(feature); if (!feature.Properties.ContainsKey("id")) { feature.Properties["id"] = featureDetails[0].ToString(); } } } } return(new JsonResult(featureCollection)); } catch (StackExchange.Redis.RedisConnectionException ex) { string message = "Unable to connect to Tile38"; _logger.LogError(0, ex, message); HttpContext.Response.StatusCode = 500; return(new JsonResult(new { message = message, exception = ex })); } catch (Exception ex) { string message = "Unable to execute WITHIN against Tile38"; _logger.LogError(0, ex, message); HttpContext.Response.StatusCode = 500; return(new JsonResult(new { message = message, exception = ex })); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { var Features = new List <Feature>(); foreach (var CurrentPoint in points) { var Geometry = new GeoJSON.Net.Geometry.Point(InvertPosition(CurrentPoint)); Features.Add(new Feature(Geometry)); } foreach (var CurrentLine in lines) { var Geometry = new GeoJSON.Net.Geometry.LineString(new List <GeoJSON.Net.Geometry.IPosition> { InvertPosition(CurrentLine.Item1), InvertPosition(CurrentLine.Item2) }); Features.Add(new Feature(Geometry)); } foreach (var CurrentPoly in polygons) { var Poly = new List <List <List <double> > > { new List <List <double> > { new List <double> { InvertPosition(CurrentPoly.Item1).Latitude, InvertPosition(CurrentPoly.Item1).Longitude }, new List <double> { InvertPosition(CurrentPoly.Item1).Latitude, InvertPosition(CurrentPoly.Item2).Longitude }, new List <double> { InvertPosition(CurrentPoly.Item2).Latitude, InvertPosition(CurrentPoly.Item2).Longitude }, new List <double> { InvertPosition(CurrentPoly.Item2).Latitude, InvertPosition(CurrentPoly.Item1).Longitude }, new List <double> { InvertPosition(CurrentPoly.Item1).Latitude, InvertPosition(CurrentPoly.Item1).Longitude }, } }; var Geometry = new GeoJSON.Net.Geometry.Polygon(Poly); Features.Add(new Feature(Geometry)); } var FeatureCol = new FeatureCollection(Features); var SaveDialog = new SaveFileDialog(); SaveDialog.Filter = "GeoJSON Files (*.json)|*.json"; var Result = SaveDialog.ShowDialog(); if (Result == DialogResult.OK) { Stream Stream; if ((Stream = SaveDialog.OpenFile()) != null) { string Json = JsonConvert.SerializeObject(FeatureCol); using (var Writer = new StreamWriter(Stream)) { Writer.Write(Json); Writer.Flush(); } Stream.Close(); } } }