public void WriteToContextAndFlush(IContextResponse response) { response.Clear(); response.ContentType = ContentType; using (XmlWriter writer = response.CreateXmlWriter()) Capabilities.WriteTo(writer); response.End(); }
public Context(HttpContext context) { if (context == null) throw new ArgumentNullException("context", "An attempt was made to access the WMS server outside a valid HttpContext"); _request = new ContextRequest(context); _response = new ContextResponse(context); }
public Context(HttpContext context) { if (context == null) { throw new ArgumentNullException("context", "An attempt was made to access the WMS server outside a valid HttpContext"); } _request = new ContextRequest(context); _response = new ContextResponse(context); }
public void WriteToContextAndFlush(IContextResponse response) { response.Clear(); if (Charset != null) { //"windows-1252"; response.Charset = Charset; } response.BufferOutput = _bufferOutput; response.Write(Response); response.End(); }
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 virtual void WriteToContextAndFlush(IContextResponse response) { response.Clear(); response.ContentType = "text/xml"; response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); response.Write( "<ServiceExceptionReport version=\"1.3.0\" xmlns=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd\">\n"); response.Write("<ServiceException"); if (ExceptionCode != WmsExceptionCode.NotApplicable) response.Write(" code=\"" + ExceptionCode + "\""); response.Write(">" + Message + "</ServiceException>\n"); response.Write("</ServiceExceptionReport>"); response.End(); }
public void WriteToContextAndFlush(IContextResponse response) { //Png can't stream directy. Going through a memorystream instead byte[] buffer; using (MemoryStream ms = new MemoryStream()) { Image.Save(ms, CodecInfo, null); Image.Dispose(); buffer = ms.ToArray(); } response.Clear(); response.ContentType = CodecInfo.MimeType; response.Write(buffer); response.End(); }
public virtual void WriteToContextAndFlush(IContextResponse response) { response.Clear(); response.ContentType = "text/xml"; response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); response.Write( "<ServiceExceptionReport version=\"1.3.0\" xmlns=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd\">\n"); response.Write("<ServiceException"); if (ExceptionCode != WmsExceptionCode.NotApplicable) { response.Write(" code=\"" + ExceptionCode + "\""); } response.Write(">" + Message + "</ServiceException>\n"); response.Write("</ServiceExceptionReport>"); response.End(); }
/// <summary> /// Generates a WMS 1.3.0 compliant response based on a <see cref="SharpMap.Map"/> and the current HttpRequest. /// </summary> /// <remarks> /// <para> /// The Web Map Server implementation in SharpMap requires v1.3.0 compatible clients, /// and support the basic operations "GetCapabilities" and "GetMap" /// as required by the WMS v1.3.0 specification. SharpMap does not support the optional /// GetFeatureInfo operation for querying. /// </para> /// <example> /// Creating a WMS server in ASP.NET is very simple using the classes in the SharpMap.Web.Wms namespace. /// <code lang="C#"> /// void page_load(object o, EventArgs e) /// { /// //Get the path of this page /// string url = (Request.Url.Query.Length>0?Request.Url.AbsoluteUri.Replace(Request.Url.Query,""):Request.Url.AbsoluteUri); /// SharpMap.Web.Wms.Capabilities.WmsServiceDescription description = /// new SharpMap.Web.Wms.Capabilities.WmsServiceDescription("Acme Corp. Map Server", url); /// /// // The following service descriptions below are not strictly required by the WMS specification. /// /// // Narrative description and keywords providing additional information /// description.Abstract = "Map Server maintained by Acme Corporation. Contact: [email protected]. High-quality maps showing roadrunner nests and possible ambush locations."; /// description.Keywords.Add("bird"); /// description.Keywords.Add("roadrunner"); /// description.Keywords.Add("ambush"); /// /// //Contact information /// description.ContactInformation.PersonPrimary.Person = "John Doe"; /// description.ContactInformation.PersonPrimary.Organisation = "Acme Inc"; /// description.ContactInformation.Address.AddressType = "postal"; /// description.ContactInformation.Address.Country = "Neverland"; /// description.ContactInformation.VoiceTelephone = "1-800-WE DO MAPS"; /// //Impose WMS constraints /// description.MaxWidth = 1000; //Set image request size width /// description.MaxHeight = 500; //Set image request size height /// /// //Call method that sets up the map /// //We just add a dummy-size, since the wms requests will set the image-size /// SharpMap.Map myMap = MapHelper.InitializeMap(new System.Drawing.Size(1,1)); /// /// //Parse the request and create a response /// SharpMap.Web.Wms.WmsServer.ParseQueryString(myMap,description); /// } /// </code> /// </example> /// </remarks> /// <param name="map">Map to serve on WMS</param> /// <param name="description">Description of map service</param> /// <param name="context">The context the <see cref="WmsServer"/> is running in.</param> public static void ParseQueryString(Map map, Capabilities.WmsServiceDescription description, IContext context) { const StringComparison @case = StringComparison.InvariantCultureIgnoreCase; IContextRequest request = context.Request; IContextResponse response = context.Response; try { if (PixelSensitivity < 0) { PixelSensitivity = 1; } if (map == null) { throw new WmsArgumentException("Map for WMS is null"); } if (map.Layers.Count == 0) { throw new WmsArgumentException("Map doesn't contain any layers for WMS service"); } string req = request.GetParam("REQUEST"); if (req == null) { throw new WmsParameterNotSpecifiedException("REQUEST"); } IHandler handler; if (String.Equals(req, "GetCapabilities", @case)) { handler = new GetCapabilities(description); } else if (String.Equals(req, "GetFeatureInfo", @case)) { // use text/plain as default handler // let the default handler validate params string format = request.GetParam("INFO_FORMAT") ?? String.Empty; GetFeatureInfoParams @params = new GetFeatureInfoParams(PixelSensitivity, IntersectDelegate, FeatureInfoResponseEncoding); if (String.Equals(format, "text/json", @case)) { handler = new GetFeatureInfoJson(description, @params); } else if (String.Equals(format, "text/html", @case)) { handler = new GetFeatureInfoHtml(description, @params); } else { handler = new GetFeatureInfoPlain(description, @params); } } else if (String.Equals(req, "GetMap", @case)) { handler = new GetMap(description); } else { string s = String.Format("Invalid request: {0}", req); throw new WmsOperationNotSupportedException(s); } IHandlerResponse result = handler.Handle(map, request); result.WriteToContextAndFlush(response); } catch (WmsExceptionBase ex) { ex.WriteToContextAndFlush(response); } }