public string GenerateGeoJsonStringFromEntity(InspektionsRouteGIS inspektionsroute) { if (inspektionsroute == null) { return("{ \"type\": \"FeatureCollection\", \"features\": []}"); } FeatureWithID feature = new FeatureWithID(); IAttributesTable attributes = new AttributesTable(); IList <FeatureWithID> strassenabschnitte = new List <FeatureWithID>(); feature.Id = inspektionsroute.Id.ToString(); feature.Geometry = inspektionsroute.Shape; attributes.AddAttribute(geoJSONAttribute_InspektionsrouteID, inspektionsroute.Id); attributes.AddAttribute(geoJSONAttribute_InspektionsrouteBezeichnung, inspektionsroute.Bezeichnung); attributes.AddAttribute(geoJSONAttribute_IsLocked, inspektionsroute.IsLocked); //GEOJSON PROPERTIES: Strassenabschnitte foreach (InspektionsRtStrAbschnitte inspektionsrouteStrassenabschnitt in inspektionsroute.InspektionsRtStrAbschnitteList) { FeatureWithID featureIrs = new FeatureWithID(); IAttributesTable attributeIrs = new AttributesTable(); IList <AchsenReferenz> achsenreferenzenIrs = achsenReferenzService.GetAchsenReferenzGruppe(inspektionsrouteStrassenabschnitt.StrassenabschnittGIS.ReferenzGruppe.Id); IList <FeatureWithID> achsenreferenzen = new List <FeatureWithID>(); featureIrs.Id = inspektionsrouteStrassenabschnitt.StrassenabschnittGIS.Id.ToString(); featureIrs.Geometry = inspektionsrouteStrassenabschnitt.StrassenabschnittGIS.Shape; foreach (AchsenReferenz achsenreferenz in achsenreferenzenIrs) { FeatureWithID featAr = new FeatureWithID(); IAttributesTable attAr = new AttributesTable(); featAr.Id = achsenreferenz.Id.ToString(); featAr.Geometry = achsenreferenz.Shape; attAr.AddAttribute(geoJSONAttribute_AchsenSegmentId, achsenreferenz.AchsenSegment.Id); featAr.Attributes = attAr; achsenreferenzen.Add(featAr); } attributeIrs.AddAttribute(geoJSONAttribute_childs, achsenreferenzen); featureIrs.Attributes = attributeIrs; strassenabschnitte.Add(featureIrs); } attributes.AddAttribute(geoJSONAttribute_Strassenabschnitte, strassenabschnitte); feature.Attributes = attributes; TextWriter sw = new StringWriter(); GeoJSONWriter.WriteWithID(feature, sw); string geoJSONstring = sw.ToString(); return(geoJSONstring); }
public string GetNearestAchsenSegment(double x, double y, double tolerance) { IGeometry clickedPoint = EMSG.Business.Services.GIS.GISService.CreateGeometryFactory().CreatePoint(new Coordinate((double)x, (double)y, 0)); var buffer = clickedPoint.Buffer(tolerance); IList <AchsenSegment> achsegmentList = GetCurrentEntityListBySpatialFilter(buffer); AchsenSegment selectedAchsensegment = gisService.GetNearestGeometry(clickedPoint, achsegmentList); TextWriter tw = new StringWriter(); IAttributesTable table = new AttributesTable(); //GEOJSON PROPERTIES: STRASSENABSCHNITTE List <FeatureWithID> features = new List <FeatureWithID>(); if (selectedAchsensegment == null) { return(GeoJSONStrings.GeoJSONFailure("No Achsen found")); } foreach (AchsenReferenz achsenreferenz in selectedAchsensegment.AchsenReferenzen.Where(ar => ar.Erfassungsperiod == historizationService.GetCurrentErfassungsperiod())) { if (achsenreferenz.ReferenzGruppe.StrassenabschnittGIS != null) { FeatureWithID feat = new FeatureWithID(); IAttributesTable att = new AttributesTable(); feat.Id = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Id.ToString(); feat.Geometry = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Shape; feat.Attributes = att; if (!features.Contains(feat)) { features.Add(feat); } } } table.AddAttribute("Strassenabschnitte", features); table.AddAttribute("AchsenId", selectedAchsensegment.Achse.Id); table.AddAttribute("AchsenName", selectedAchsensegment.Achse.Name); table.AddAttribute("IsInverted", selectedAchsensegment.IsInverted); FeatureWithID feature = new FeatureWithID(); feature.Id = selectedAchsensegment.Id.ToString(); feature.Geometry = selectedAchsensegment.Shape; feature.Attributes = table; TextWriter sw = new StringWriter(); GeoJSONWriter.WriteFeatureWithID(feature, sw); return(sw.ToString()); }
public override void ProcessRequest(HttpContext context) { try { string s = context.Request.Params["BBOX"]; if (String.IsNullOrEmpty(s)) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified", context); return; } Map map = this.GetMap(context.Request); bool flip = map.Layers[0].TargetSRID == 4326; BoundingBox bbox = WmsServer.ParseBBOX(s, flip); if (bbox == null) { WmsException.ThrowWmsException("Invalid parameter BBOX", context); return; } string ls = context.Request.Params["LAYERS"]; if (!String.IsNullOrEmpty(ls)) { string[] layers = ls.Split(','); foreach (ILayer layer in map.Layers) { if (!layers.Contains(layer.LayerName)) { layer.Enabled = false; } } } IEnumerable <GeoJSON> items = GetData(map, bbox); StringWriter writer = new StringWriter(); GeoJSONWriter.Write(items, writer); string buffer = writer.ToString(); context.Response.Clear(); context.Response.ContentType = "text/json"; context.Response.BufferOutput = true; context.Response.Write(buffer); context.Response.Flush(); context.Response.SuppressContent = true; context.ApplicationInstance.CompleteRequest(); //context.Response.End(); } catch (Exception ex) { Trace.WriteLine(ex); throw; } }
protected override AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map, IEnumerable <string> requestedLayers, float x, float y, int featureCount, string cqlFilter, int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate) { List <GeoJSON> items = new List <GeoJSON>(); foreach (string requestLayer in requestedLayers) { ICanQueryLayer queryLayer = GetQueryLayer(map, requestLayer); FeatureDataSet fds; if (!TryGetData(map, x, y, pixelSensitivity, intersectDelegate, queryLayer, cqlFilter, out fds)) { continue; } IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(fds); // reproject geometries if needed IMathTransform transform = null; if (queryLayer is VectorLayer) { ICoordinateTransformation transformation = (queryLayer as VectorLayer).CoordinateTransformation; if (transformation != null) { transform = transformation.MathTransform; } } if (transform != null) { #if DotSpatialProjections throw new NotImplementedException(); #else data = data.Select(d => { IGeometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform, map.Factory); d.SetGeometry(converted); return(d); }); #endif } items.AddRange(data); } StringWriter sb = new StringWriter(); GeoJSONWriter.Write(items, sb); return(new GetFeatureInfoResponseJson(sb.ToString())); }
public override void ProcessRequest(IContext context) { IContextRequest request = context.Request; IContextResponse response = context.Response; try { string s = request.GetParam("BBOX"); if (String.IsNullOrEmpty(s)) { throw new WmsInvalidParameterException("BBOX"); } Map map = GetMap(request); LayerCollection layers = map.Layers; ILayer first = layers.First(); bool flip = first.TargetSRID == 4326; BoundingBox bbox = AbstractHandler.ParseBBOX(s, flip); if (bbox == null) { throw new WmsInvalidBboxException(s); } string ls = request.GetParam("LAYERS"); if (!String.IsNullOrEmpty(ls)) { string[] strings = ls.Split(','); foreach (ILayer layer in layers) { if (!strings.Contains(layer.LayerName)) { layer.Enabled = false; } } } IEnumerable <GeoJSON> items = GetData(map, bbox); StringWriter writer = new StringWriter(); GeoJSONWriter.Write(items, writer); string buffer = writer.ToString(); IHandlerResponse result = new GetFeatureInfoResponseJson(buffer); result.WriteToContextAndFlush(response); } catch (WmsExceptionBase ex) { ex.WriteToContextAndFlush(response); } }
public string GenereateGeoJsonStringfromEntities(IEnumerable <IAbschnittGISBase> entities) { IList <FeatureWithID> features = new List <FeatureWithID>(); foreach (IAbschnittGISBase entity in entities) { features.Add(getFeatureWithId(entity)); } TextWriter sw = new StringWriter(); GeoJSONWriter.WritewithID(features, sw); string geoJSONstring = sw.ToString(); return(geoJSONstring); }
private ActionResult MakeResponse(IEnumerable <IGeometry> geometries) { if (geometries == null) { throw new ArgumentNullException("geometries"); } // we should return a GeometryCollection object IGeometry[] array = geometries.ToArray(); IGeometryCollection result = this.factory.CreateGeometryCollection(array); StringWriter writer = new StringWriter(); GeoJSONWriter.Write(result, writer); return(this.Json(new { geo = writer.ToString() })); }
public string GenerateGeoJsonStringFromEntities(IEnumerable <IDTOGeometryHolder> entities) { IList <FeatureWithID> features = new List <FeatureWithID>(); foreach (IDTOGeometryHolder entity in entities) { features.Add(getFeatureWithId(entity)); } TextWriter sw = new StringWriter(); GeoJSONWriter.WritewithID(features, sw); string geoJSONstring = sw.ToString(); return(geoJSONstring); }
public string GenerateGeoJsonStringFromEntity(IAbschnittGISBase entity) { if (entity == null) { return("{ \"type\": \"FeatureCollection\", \"features\": []}"); } FeatureWithID feature = getFeatureWithId(entity); TextWriter sw = new StringWriter(); GeoJSONWriter.WriteWithID(feature, sw); string geoJSONstring = sw.ToString(); return(geoJSONstring); }
public string GenerateGeoJsonStringFromEntity(IDTOGeometryHolder entity) { if (entity == null) { return(geoJSON_EmptyFeatureCollection); } FeatureWithID feature = getFeatureWithId(entity); TextWriter sw = new StringWriter(); GeoJSONWriter.WriteWithID(feature, sw); string geoJSONstring = sw.ToString(); return(geoJSONstring); }
public string GetAchsensegmentCollection(string achsensegmentIds) { var splitachsensegmentIds = achsensegmentIds.Split(','); List <FeatureWithID> achsensegmente = new List <FeatureWithID>(); StringWriter sw = new StringWriter(); foreach (string achsensegmentId in splitachsensegmentIds) { AchsenSegment aseg = GetEntityById(Guid.Parse(achsensegmentId)); FeatureWithID feat = new FeatureWithID(); IAttributesTable att = new AttributesTable(); List <FeatureWithID> strassenabschnitte = new List <FeatureWithID>(); foreach (AchsenReferenz achsenreferenz in aseg.AchsenReferenzen.Where(a => a.Erfassungsperiod == historizationService.GetCurrentErfassungsperiod())) { if (achsenreferenz.ReferenzGruppe.StrassenabschnittGIS != null) { FeatureWithID strabsfeat = new FeatureWithID(); IAttributesTable strabsatt = new AttributesTable(); strabsfeat.Id = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Id.ToString(); strabsfeat.Geometry = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Shape; strabsfeat.Attributes = strabsatt; if (!strassenabschnitte.Contains(strabsfeat)) { strassenabschnitte.Add(strabsfeat); } } } att.AddAttribute("AchsenId", aseg.Achse.Id); att.AddAttribute("AchsenName", aseg.Achse.Name); att.AddAttribute("IsInverted", aseg.IsInverted); att.AddAttribute("Strassenabschnitte", strassenabschnitte); feat.Geometry = aseg.Shape; feat.Id = aseg.Id.ToString(); feat.Attributes = att; achsensegmente.Add(feat); } GeoJSONWriter.WritewithID(achsensegmente, sw); sw.Flush(); return(sw.ToString()); }
public string GenereateGeoJsonStringfromAchsenSegment(IEnumerable <AchsenSegment> entities) { List <FeatureWithID> achsensegmente = new List <FeatureWithID>(); StringWriter sw = new StringWriter(); foreach (var aseg in entities) { FeatureWithID feat = new FeatureWithID(); IAttributesTable att = new AttributesTable(); att.AddAttribute(geoJSONAttribute_AchsenId, aseg.Achse.Id); att.AddAttribute(geoJSONAttribute_AchsenName, aseg.Achse.Name); att.AddAttribute(geoJSONAttribute_IsInverted, aseg.IsInverted); feat.Geometry = aseg.Shape; feat.Id = aseg.Id.ToString(); feat.Attributes = att; achsensegmente.Add(feat); } GeoJSONWriter.WritewithID(achsensegmente, sw); sw.Flush(); return(sw.ToString()); }
public override void ProcessRequest(HttpContext context) { try { string s = context.Request.Params["BBOX"]; if (String.IsNullOrEmpty(s)) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified"); return; } BoundingBox bbox = WmsServer.ParseBBOX(s); if (bbox == null) { WmsException.ThrowWmsException("Invalid parameter BBOX"); return; } Map map = this.GetMap(context.Request); IEnumerable <GeoJSON> items = this.GetData(map, bbox); StringWriter writer = new StringWriter(); GeoJSONWriter.Write(items, writer); string buffer = writer.ToString(); context.Response.Clear(); context.Response.ContentType = "text/json"; context.Response.BufferOutput = true; context.Response.Write(buffer); context.Response.End(); } catch (Exception ex) { Trace.WriteLine(ex); throw; } }
public void ToJSON(JsonTextWriter writer) { GeoJSONWriter.Write(this, writer, _nonSerializedFields); }
public void ToJSON(Jayrock.Json.JsonTextWriter jwriter) { GeoJSONWriter.Write(this, jwriter, _nonSerializedFields); }
public override void Handle() { string queryLayers = this.context.Request.Params["LAYERS"]; string styles = this.context.Request.Params["STYLES"]; string crs = this.context.Request.Params["CRS"]; string queryBBOX = this.context.Request.Params["BBOX"]; string queryWidth = this.context.Request.Params["WIDTH"]; string queryHeight = this.context.Request.Params["HEIGHT"]; string format = this.context.Request.Params["FORMAT"]; string transparent = this.context.Request.Params["TRANSPARENT"]; string background = this.context.Request.Params["BGCOLOR"]; if (queryLayers == null) { WmsException.ThrowWmsException("Required parameter LAYERS not specified"); return; } if (styles == null) { WmsException.ThrowWmsException("Required parameter STYLES not specified"); return; } if (crs == null) { WmsException.ThrowWmsException("Required parameter CRS not specified"); return; } if (!this.Check(String.Format("EPSG:{0}", this.map.Layers[0].SRID), crs)) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidCRS, "CRS not supported"); return; } if (queryBBOX == null) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified"); return; } if (queryWidth == null) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter WIDTH not specified"); return; } if (queryHeight == null) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter HEIGHT not specified"); return; } if (format == null) { WmsException.ThrowWmsException("Required parameter FORMAT not specified"); return; } //Set background color of map if (!this.Check("TRUE", transparent)) { if (background != null) { try { this.map.BackColor = ColorTranslator.FromHtml(background); } catch { WmsException.ThrowWmsException("Invalid parameter BGCOLOR"); return; } } else { this.map.BackColor = Color.White; } } else { this.map.BackColor = Color.Transparent; } //Parse map size int width; if (!Int32.TryParse(queryWidth, out width)) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Invalid parameter WIDTH"); return; } if (this.description.MaxWidth > 0 && width > this.description.MaxWidth) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.OperationNotSupported, "Parameter WIDTH too large"); return; } int height; if (!Int32.TryParse(queryHeight, out height)) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Invalid parameter HEIGHT"); return; } if (this.description.MaxHeight > 0 && height > this.description.MaxHeight) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.OperationNotSupported, "Parameter HEIGHT too large"); return; } this.map.Size = new Size(width, height); BoundingBox bbox = this.ParseBBOX(queryBBOX); if (bbox == null) { WmsException.ThrowWmsException("Invalid parameter BBOX"); return; } this.map.PixelAspectRatio = (width / (double)height) / (bbox.Width / bbox.Height); this.map.Center = bbox.GetCentroid(); this.map.Zoom = bbox.Width; //Set layers on/off if (!String.IsNullOrEmpty(queryLayers)) //If LAYERS is empty, use default layer on/off settings { string[] layers = queryLayers.Split(new[] { ',' }); if (this.description.LayerLimit > 0) { if (layers.Length == 0 && this.map.Layers.Count > this.description.LayerLimit || layers.Length > this.description.LayerLimit) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.OperationNotSupported, "Too many layers requested"); return; } } foreach (ILayer layer in this.map.Layers) { layer.Enabled = false; } foreach (string layer in layers) { ILayer lay = this.map.GetLayerByName(layer); if (lay == null) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.LayerNotDefined, String.Format("Unknown layer '{0}'", layer)); return; } lay.Enabled = true; } } bool json = this.Check("text/json", format); if (json) { List <GeoJSON> items = new List <GeoJSON>(); //Only queryable data! IQueryable <ICanQueryLayer> collection = this.map.Layers.AsQueryable() .OfType <ICanQueryLayer>().Where(l => l.Enabled && l.IsQueryEnabled); foreach (ICanQueryLayer layer in collection) { //Query for data FeatureDataSet ds = new FeatureDataSet(); layer.ExecuteIntersectionQuery(bbox, ds); IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(ds); //Filter only visible items //double f = bbox.GetArea() / (width * height); //data = data.Where(i => //{ // Geometry g = i.Geometry; // BoundingBox p = g.GetBoundingBox(); // double area = p.GetArea(); // return area == 0 || area > f; //}); //Reproject geometries if needed IMathTransform transform = null; if (layer is VectorLayer) { ICoordinateTransformation transformation = (layer as VectorLayer).CoordinateTransformation; transform = transformation == null ? null : transformation.MathTransform; } if (transform != null) { data = data.Select(d => { Geometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform); d.SetGeometry(converted); return(d); }); } items.AddRange(data); } StringWriter writer = new StringWriter(); GeoJSONWriter.Write(items, writer); string buffer = writer.ToString(); this.context.Response.Clear(); this.context.Response.ContentType = "text/json"; this.context.Response.BufferOutput = true; this.context.Response.Write(buffer); this.context.Response.End(); } else { //Get the image format requested ImageCodecInfo imageEncoder = this.GetEncoderInfo(format); if (imageEncoder == null) { WmsException.ThrowWmsException("Invalid MimeType specified in FORMAT parameter"); return; } //Render map Image img = this.map.GetMap(); //Png can't stream directy. Going through a memorystream instead MemoryStream ms = new MemoryStream(); img.Save(ms, imageEncoder, null); img.Dispose(); byte[] buffer = ms.ToArray(); this.context.Response.Clear(); this.context.Response.ContentType = imageEncoder.MimeType; this.context.Response.BufferOutput = true; this.context.Response.BinaryWrite(buffer); this.context.Response.End(); } }
public void ToJSON(Jayrock.Json.JsonTextWriter jwriter) { GeoJSONWriter.Write(this, jwriter); }