Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpRequest request = context.Request;
                Uri         uri     = request.Url;
                string      url;
                string      absoluteUri = uri.AbsoluteUri;
                if (uri.Query.Length > 0)
                {
                    string s = absoluteUri.Replace(uri.Query, String.Empty);
                    url = s;
                }
                else
                {
                    url = absoluteUri;
                }

                Map map = MapHelper.InitializeMap();
                Capabilities.WmsServiceDescription description = GetDescription(url);
                WmsServer.ParseQueryString(map, description);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                throw;
            }
        }
Пример #2
0
 public void RemoveWmsServer(WmsServer server)
 {
     if (_wmsServers.Remove(server))
     {
         // TODO: fire event
     }
 }
Пример #3
0
        public GetFeatureInfoParams(int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate)
        {
            if (intersectDelegate == null) { /* can be null */}

            this.pixelSensitivity = Math.Max(0, pixelSensitivity);
            this.intersectDelegate = intersectDelegate;
        }
Пример #4
0
        /// <summary>
        ///     Prepares the response.
        /// </summary>
        public void ProcessRequest(string url)
        {
            var map         = GetMap();
            var description = GetDescription(url);

            WmsServer.ParseQueryString(map, description);
        }
Пример #5
0
        protected override AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map,
            IEnumerable<string> requestedLayers,
            float x, float y,
            int featureCount,
            string cqlFilter,
            int pixelSensitivity,
            WmsServer.InterSectDelegate intersectDelegate)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("GetFeatureInfo results:{0}", NewLine);
            foreach (string requestLayer in requestedLayers)
            {
                ICanQueryLayer layer = GetQueryLayer(map, requestLayer);
                FeatureDataSet fds;
                if (!TryGetData(map, x, y, pixelSensitivity, intersectDelegate, layer, cqlFilter, out fds))
                {
                    sb.AppendFormat("Search returned no results on layer: {0}{1}", requestLayer, NewLine);
                    continue;
                }

                sb.AppendFormat("Layer: '{0}'{1}", requestLayer, NewLine);
                sb.AppendFormat("Featureinfo:{0}", NewLine);
                FeatureDataTable table = fds.Tables[0];
                string rowsText = GetRowsText(table.Rows, featureCount);
                sb.Append(rowsText).Append(NewLine);
            }
            return new GetFeatureInfoResponsePlain(sb.ToString());
        }
Пример #6
0
        protected override AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map,
            IEnumerable<string> requestedLayers,
            float x, float y,
            int featureCount,
            string cqlFilter,
            int pixelSensitivity,
            WmsServer.InterSectDelegate intersectDelegate)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string requestLayer in requestedLayers)
            {
                ICanQueryLayer layer = GetQueryLayer(map, requestLayer);
                FeatureDataSet fds;
                if (!TryGetData(map, x, y, pixelSensitivity, intersectDelegate, layer, cqlFilter, out fds))
                    continue;

                FeatureDataTable table = fds.Tables[0];
                StringBuilder sbTable = new StringBuilder();
                sbTable.AppendFormat("<tr>{0}", NewLine);
                foreach (DataColumn col in table.Columns)
                    sbTable.AppendFormat("<th>{0}</th>{1}", col.ColumnName, NewLine);
                sbTable.AppendFormat("</tr>{0}", NewLine);
                string rowsText = GetRowsText(table.Rows, featureCount);
                sbTable.Append(rowsText);

                string tpl = TableTemplate.
                    Replace("{{LAYER_NAME}}", requestLayer).
                    Replace("{{LAYER_TABLE}}", sbTable.ToString());
                sb.AppendFormat("{0}\n{1}\n", tpl, "<br />");
            }


            string html = HtmlTemplate.Replace("{{HTML_BODY}}", sb.ToString());
            return new GetFeatureInfoResponseHtml(html);
        }
Пример #7
0
 public GetFeatureInfoParams(int pixelSensitivity,
     WmsServer.InterSectDelegate intersectDelegate, 
     Encoding encoding)
 {
     _pixelSensitivity = pixelSensitivity;
     _intersectDelegate = intersectDelegate;
     _encoding = encoding;
 }
Пример #8
0
 public void AddWmsServer(WmsServer server)
 {
     if (server != null)
     {
         // TODO: fire event
         _wmsServers.Add(server);
     }
 }
Пример #9
0
        public override void ProcessRequest(IContext context)
        {
            string url = GetFixedUrl(context.Request);

            Capabilities.WmsServiceDescription description = GetDescription(url);
            Map map = GetMap(context.Request);

            WmsServer.ParseQueryString(map, description, 10, null, context);
        }
Пример #10
0
        public void UpdateServer(WmsServer server = null)
        {
            RefreshServerList();

            if (server != null)
            {
                Server = server;
            }
        }
Пример #11
0
        public void UpdateWmsServer(WmsServer server)
        {
            int index = _wmsServers.IndexOf(server);

            if (index != -1)
            {
                _wmsServers[index] = server;
            }
        }
Пример #12
0
        /// <summary>
        /// Runs the command.
        /// </summary>
        public override void RunCommand(WmsCommand command)
        {
            switch (command)
            {
            case WmsCommand.Connect:
                ConnectServer();
                break;

            case WmsCommand.Create:
            {
                var server = new WmsServer();
                if (_context.Container.Run <WmsServerPresenter, WmsServer>(server))
                {
                    Model.Repository.AddWmsServer(server);
                    View.UpdateServer(server);
                }
            }
            break;

            case WmsCommand.Edit:
            {
                var server = View.Server;
                if (server != null)
                {
                    if (_context.Container.Run <WmsServerPresenter, WmsServer>(server))
                    {
                        Model.Repository.UpdateWmsServer(server);
                        View.UpdateServer(server);
                        LoadCachedCapabilities(server);
                    }
                }
            }
            break;

            case WmsCommand.Delete:
                if (View.Server != null)
                {
                    string msg = "Do you want to remove the selected WMS server from the list: " + View.Server.Name + "?";

                    if (MessageService.Current.Ask(msg))
                    {
                        Model.Repository.RemoveWmsServer(View.Server);
                        View.UpdateServer(Model.Repository.WmsServers.FirstOrDefault());
                    }
                }
                break;

            case WmsCommand.Add:
                AddProvider();
                break;

            default:
                throw new ArgumentOutOfRangeException("command");
            }
        }
Пример #13
0
        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;
            }
        }
Пример #14
0
        /// <summary>
        /// Loads and displayes the cached capabilities for the server.
        /// </summary>
        private bool LoadCachedCapabilities(WmsServer server)
        {
            var capabilities = WmsCapabilitiesCache.Load(server.Url);

            if (capabilities != null)
            {
                DisplayServerCapabilities(capabilities);
                return(true);
            }

            return(false);
        }
Пример #15
0
 public override void ProcessRequest(HttpContext context)
 {
     try
     {
         HttpRequest request = context.Request;
         string      url     = GetFixedUrl(request);
         Capabilities.WmsServiceDescription description = GetDescription(url);
         Map map = this.GetMap(request);
         WmsServer.ParseQueryString(map, description, 10, null);
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
         throw;
     }
 }
Пример #16
0
 public override void ProcessRequest(HttpContext context)
 {
     try
     {
         var request     = context.Request;
         var url         = this.GetFixedUrl(request);
         var description = this.GetDescription(url);
         var map         = this.GetMap(request);
         WmsServer.ParseQueryString(map, description, 10, null, context);
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
         throw;
     }
 }
Пример #17
0
        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);
                IFeatureCollectionSet 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());
        }
Пример #18
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpRequest request = context.Request;
                Uri         uri     = request.Url;
                string      url;
                string      absoluteUri = uri.AbsoluteUri;
                if (uri.Query.Length > 0)
                {
                    string s = absoluteUri.Replace(uri.Query, String.Empty);
                    url = s;
                }
                else
                {
                    url = absoluteUri;
                }
                Capabilities.WmsServiceDescription description = GetDescription(url);

                Map    map;
                string type = request.Params["MAP_TYPE"];
                if (String.Equals(type, "OL", StringComparison.InvariantCultureIgnoreCase))
                {
                    map = MapHelper.OpenLayers();
                }
                else if (String.Equals(type, "PM", StringComparison.InvariantCultureIgnoreCase))
                {
                    map = MapHelper.PolyMaps();
                }
                else
                {
                    string format = String.Format("unsupported map type: '{0}'", type);
                    throw new NotSupportedException(format);
                }
                WmsServer.ParseQueryString(map, description);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                throw;
            }
        }
Пример #19
0
        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;
            }
        }
Пример #20
0
 /// <summary>
 /// Gets FeatureInfo.
 /// </summary>
 /// <param name="map">The map to create the feature info from.</param>
 /// <param name="requestedLayers">The layers to create the feature info for.</param>
 /// <param name="x">The x-ordinate.</param>
 /// <param name="y">The y-ordinate.</param>
 /// <param name="featureCount">The max number of features retrieved.</param>
 /// <param name="cqlFilter">The CQL Filter string.</param>
 /// <param name="pixelSensitivity">The sensitivity to use when querying data.</param>
 /// <param name="intersectDelegate">A <see cref="WmsServer.InterSectDelegate"/> to filter data.</param>
 /// <returns>Text string with featureinfo results.</returns>
 protected abstract AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map,
     IEnumerable<string> requestedLayers,
     float x, float y,
     int featureCount,
     string cqlFilter,
     int pixelSensitivity,
     WmsServer.InterSectDelegate intersectDelegate);
Пример #21
0
        /// <summary>
        /// Check if the layer can be queried and retrieve data, if there is any.
        /// </summary>
        protected bool TryGetData(Map map,
            float x, float y,
            int pixelSensitivity,
            WmsServer.InterSectDelegate intersectDelegate,
            ICanQueryLayer queryLayer,
            string cqlFilter,
            out IFeatureCollectionSet fds)
        {
            if (!queryLayer.IsQueryEnabled)
            {
                fds = null;
                return false;
            }

            float queryBoxMinX = x - pixelSensitivity;
            float queryBoxMinY = y - pixelSensitivity;
            float queryBoxMaxX = x + pixelSensitivity;
            float queryBoxMaxY = y + pixelSensitivity;

            Coordinate minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY));
            Coordinate maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY));
            Envelope queryBox = new Envelope(minXY, maxXY);

            fds = new FeatureCollectionSet();
            queryLayer.ExecuteIntersectionQuery(queryBox, fds);

            if (fds.Count == 0)
                return false;

            var table = fds[0];
            if (intersectDelegate != null)
            {
                fds.Remove(table);
                fds.Add(intersectDelegate(table, queryBox));
                table = fds[0];
            }

            // filter the rows with the CQLFilter if one is provided
            if (cqlFilter != null)
            {
                var toKeep = table.Clone();
                foreach (var feature in table)
                {
                    if (CqlFilter(feature, cqlFilter))
                        toKeep.Add(feature);
                }
                fds.Remove(table);
                fds.Add(toKeep);
            }

            return fds[0].Count > 0;
        }
Пример #22
0
        /// <summary>
        /// Check if the layer can be queried and retrieve data, if there is any.
        /// </summary>
        protected bool TryGetData(Map map,
            float x, float y,
            int pixelSensitivity,
            WmsServer.InterSectDelegate intersectDelegate,
            ICanQueryLayer queryLayer,
            string cqlFilter,
            out FeatureDataSet fds)
        {
            if (!queryLayer.IsQueryEnabled)
            {
                fds = null;
                return false;
            }

            float queryBoxMinX = x - pixelSensitivity;
            float queryBoxMinY = y - pixelSensitivity;
            float queryBoxMaxX = x + pixelSensitivity;
            float queryBoxMaxY = y + pixelSensitivity;

            Coordinate minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY));
            Coordinate maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY));
            Envelope queryBox = new Envelope(minXY, maxXY);

            fds = new FeatureDataSet();
            queryLayer.ExecuteIntersectionQuery(queryBox, fds);

            FeatureTableCollection tables = fds.Tables;
            FeatureDataTable table = tables[0];
            if (intersectDelegate != null)
                tables[0] = intersectDelegate(table, queryBox);

            // filter the rows with the CQLFilter if one is provided
            if (cqlFilter != null)
            {
                DataRowCollection rows = table.Rows;
                for (int i = rows.Count - 1; i >= 0; i--)
                {
                    FeatureDataRow row = (FeatureDataRow)rows[i];
                    bool b = CqlFilter(row, cqlFilter);
                    if (!b)
                        rows.RemoveAt(i);
                }
            }

            bool res = tables.Count > 0 && table.Rows.Count > 0;
            return res;
        }