private static string ReadProp(Feature feature, string key) { object r; if (!feature.Properties.TryGetValue(key, out r)) { return(""); } return(r?.ToString()); }
private static Feature CreateFeature(SqlGeometry sqlGeometry, Dictionary <string, object> properties, string id, int featureCollectionEpsg) { var feature = new Feature(GeoJsonGeometry.FromSqlGeometry(sqlGeometry), properties, id); if (featureCollectionEpsg == -1 && sqlGeometry.STSrid.Value != 0) { feature.CRS = new NamedCRS("EPSG:" + sqlGeometry.STSrid.Value); } else { feature.CRS = null; } return(feature); }
public void Save(string key, VectorQuadTile tile) { var ro = new FeatureCollection(); var crs = new NamedCRS("EPSG:" + Config.Settings.Map.SpatialReferenceSystemIdentifier); ro.CRS = crs; foreach (var omg in tile.Områder) { var område = omg.Område; IGeometryObject geometry = GeoJsonGeometry.FromDotSpatial(omg.Geometry); var props = new Dictionary <string, object> { { "category", område.Category }, { "name", område.Name }, { "number", område.Number }, { "value", område.Value }, { "type", område.Type.ToString() }, { "kind", område.kind } }; var feature = new Feature(geometry, props) { Id = område.AreaId.ToString() }; var fp = new FeatureProperties { nin = område.kind }; if (område.Number == 0) { throw new Exception("Område mangler nummer."); } ro.Features.Add(feature); } var fullPath = GetFullPath(key); var fullPathSingleDir = GetFullPath(key.Replace("/", "_")); var settings = GetJsonSerializerSettings(); File.WriteAllText(fullPath, JsonConvert.SerializeObject(ro, settings)); //File.WriteAllText(fullPathSingleDir, JsonConvert.SerializeObject(ro, settings)); //var serializer = new DataContractJsonSerializer(typeof(VectorQuadTile), CreateDataContractJsonSerializerSettings()); //using (Stream stream = File.Create(fullPath + ".adf")) // serializer.WriteObject(stream, tile); }
public JsonResult GeoFences() { try{ if (redis == null) { string tile38Connection = _configuration.GetConnectionString("Tile38Connection"); redis = ConnectionMultiplexer.Connect(tile38Connection); _logger.LogInformation($"Connected to Tile38 {tile38Connection}"); } db = redis.GetDatabase(); var result = db.Execute("CHANS", "*"); _logger.LogInformation(result.ToString()); GeoJSON.Net.Feature.FeatureCollection geofences = new GeoJSON.Net.Feature.FeatureCollection(); // Top level - collection of features System.Diagnostics.Debug.Assert(result.Type == ResultType.MultiBulk); RedisResult[] topLevelRedisArrayResult = ((RedisResult[])result); foreach (RedisResult redisResult in topLevelRedisArrayResult) { // Child level - the geofence System.Diagnostics.Debug.Assert(redisResult.Type == ResultType.MultiBulk); RedisResult[] childRedisArrayResult = ((RedisResult[])redisResult); // First property should be geofence name System.Diagnostics.Debug.Assert(childRedisArrayResult[0].Type == ResultType.BulkString); // Last property should be contain 'WITHIN', 'enter,exit', etc, and geofence GeoJSON RedisResult lastChildResult = childRedisArrayResult[childRedisArrayResult.Count() - 2]; System.Diagnostics.Debug.Assert(lastChildResult.Type == ResultType.MultiBulk); RedisResult[] lastChildResultArray = (RedisResult[])lastChildResult; RedisResult finalChildResult = lastChildResultArray[lastChildResultArray.Count() - 1]; System.Diagnostics.Debug.Assert(finalChildResult.Type == ResultType.BulkString); if (finalChildResult.ToString().StartsWith("{\"type\":\"Polygon\"")) { // _logger.LogInformation("Found GeoJSON!"); GeoJSON.Net.Feature.Feature feature = new GeoJSON.Net.Feature.Feature(Newtonsoft.Json.JsonConvert.DeserializeObject <GeoJSON.Net.Geometry.Polygon>(finalChildResult.ToString())); feature.Properties["Name"] = childRedisArrayResult[0].ToString(); geofences.Features.Add(feature); } } return(new JsonResult(geofences)); } 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 retrieve GeoFences from Tile38"; _logger.LogError(0, ex, message); HttpContext.Response.StatusCode = 500; return(new JsonResult(new { message = message, exception = ex })); } }
// 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 })); } }
static public DbGeography FeatureToDbGeography(GeoJSON.Net.Feature.Feature p_Feature) { return(GeometryToDbGeography(p_Feature.Geometry)); }
public GeoJSONIterativeContext(GeoJSON.Net.Feature.Feature originalFeature, IGeometryItem feature, double buffer) { this.OriginalFeature = originalFeature; this.Feature = feature; this.Buffer = buffer; }
static internal byte[] Encode(GeoJSON.Net.Feature.Feature p_Feature) { return(Encode(p_Feature.Geometry)); }
public OsmFeature([JetBrains.Annotations.NotNull] Feature feature, [JetBrains.Annotations.NotNull] string guid) { Feature = feature; Guid = guid; }
public static bool GetProjectionFromGeoJson(string fileName, out string projectionName, out string projection) { string geoJson = File.ReadAllText(fileName); ProtoGeoJSON obj = JsonConvert.DeserializeObject <ProtoGeoJSON>(geoJson); projectionName = string.Empty; projection = string.Empty; ICRSObject crs = null; switch (obj.Type) { case "FeatureCollection": GFeatureCollection features = JsonConvert.DeserializeObject <GFeatureCollection>(geoJson); crs = features.CRS; break; case "Feature": GFeature feature = JsonConvert.DeserializeObject <GFeature>(geoJson); crs = feature.CRS; break; case "MultiPolygon": GMultiPolygon multiPoly = JsonConvert.DeserializeObject <GMultiPolygon>(geoJson); crs = multiPoly.CRS; break; case "Polygon": GPolygon poly = JsonConvert.DeserializeObject <GPolygon>(geoJson); crs = poly.CRS; break; default: break; } if (crs is NamedCRS) { NamedCRS nCrs = crs as NamedCRS; object value; if (nCrs.Properties.TryGetValue("name", out value)) { string name = value as string; if (name != null) { name = name.ToLower(); if (name.EndsWith("3857")) { projectionName = "EPSG:3857 Pseudo-Mercator"; projection = CoordinateConverter.WebMercator.WKT; return(true); } else { int index = name.IndexOf("epsg::"); string epsgStr = name.Substring(index); string authNumber = epsgStr.Substring(epsgStr.IndexOf("::") + 2); projection = AutoProjection.GetProjection(authNumber); if (projection != string.Empty) { projectionName = string.Format("EPSG:{0}", authNumber); return(true); } } } } } projectionName = "EPSG:4326 Lat-Long"; projection = CoordinateConverter.WGS84.WKT; return(true); }