Esempio n. 1
0
        /// <summary>
        /// Creates the WFS XML string that can be used in a HTTP Post request.
        /// </summary>
        /// <param name="requestUrl">The request URL.</param>
        /// <param name="boundingBox">The bounding box.</param>
        /// <returns>A string containing WFS XML-text.</returns>
        private static string CreateWfsGetFeatureXmlString(string requestUrl, WfsBoundingBox boundingBox)
        {
            NameValueCollection nameValueCollection;
            StringBuilder       sb;
            const string        getFeatureStart = "<wfs:GetFeature xmlns:wfs=\"http://www.opengis.net/wfs\" service=\"WFS\" version=\"[Version]\" outputFormat=\"[OutputFormat]\" xsi:schemaLocation=\"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
            const string        getFeatureEnd   = "</wfs:GetFeature>";
            const string        queryStart      = "<wfs:Query typeName=\"[TypeName]\" srsName=\"[SrsName]\">";
            const string        queryEnd        = "</wfs:Query>";

            nameValueCollection = HttpUtility.ParseQueryString(requestUrl);
            string version  = nameValueCollection["version"];
            string typeName = nameValueCollection["typename"];
            string srsName  = nameValueCollection["srsName"];
            string filter   = nameValueCollection["filter"];

            // Get geometry name
            WFSDescribeFeatureType describeFeatureType = GetWFSDescribeFeatureType(requestUrl, typeName);
            string geometryName = describeFeatureType.GeometryField.Name;

            string strFilterXml = CreateWfsXmlFilterString(filter, geometryName, boundingBox);

            sb = new StringBuilder();
            sb.Append(getFeatureStart.Replace("[Version]", version).Replace("[OutputFormat]", "json"));
            sb.Append(queryStart.Replace("[TypeName]", typeName).Replace("[SrsName]", srsName));
            sb.Append(strFilterXml);
            sb.Append(queryEnd);
            sb.Append(getFeatureEnd);

            string str = sb.ToString();

            return(str);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the WFS features using a HTTP Post request.
        /// </summary>
        /// <param name="requestUrl">The request URL.</param>
        public static FeatureCollection GetWfsFeaturesUsingHttpPost(string requestUrl)
        {
            WfsBoundingBox      boundingBox         = null;
            NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(requestUrl);

            // try parse bounding box
            string srsName = nameValueCollection["srsName"];
            string strBBox = nameValueCollection["bbox"];

            if (!string.IsNullOrEmpty(strBBox) && !string.IsNullOrEmpty(srsName))
            {
                string[] bboxItems = strBBox.Split(',');
                if (bboxItems.Length == 4)
                {
                    double minX, minY, maxX, maxY;
                    if (double.TryParse(bboxItems[0], NumberStyles.Number, CultureInfo.InvariantCulture, out minX) && double.TryParse(bboxItems[1], NumberStyles.Number, CultureInfo.InvariantCulture, out minY) &&
                        double.TryParse(bboxItems[2], NumberStyles.Number, CultureInfo.InvariantCulture, out maxX) && double.TryParse(bboxItems[3], NumberStyles.Number, CultureInfo.InvariantCulture, out maxY))
                    {
                        boundingBox = new WfsBoundingBox(minX, minY, maxX, maxY, srsName);
                    }
                }
            }

            return(GetWfsFeaturesUsingHttpPost(requestUrl, boundingBox));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a WFS XML filter string.
        /// </summary>
        /// <param name="filter">The filter string.</param>
        /// <param name="geometryName">Name of the geometry object.</param>
        /// <param name="boundingBox">The bounding box.</param>
        /// <returns>A string containing WFS XML-text.</returns>
        private static string CreateWfsXmlFilterString(string filter, string geometryName, WfsBoundingBox boundingBox)
        {
            FormulaOperation formulaOperation;
            SpatialOperation bboxOperation = null;

            if (string.IsNullOrEmpty(geometryName))
            {
                geometryName = "the_geom";
            }
            if (boundingBox != null)
            {
                SpatialBoundingBox spatialBoundingBox = new SpatialBoundingBox(boundingBox.MinX, boundingBox.MinY, boundingBox.MaxX, boundingBox.MaxY, boundingBox.SrsName);
                bboxOperation = new SpatialOperation(new SpatialFieldValue(geometryName), spatialBoundingBox, WFSSpatialOperator.InsideBbox);
            }

            if (string.IsNullOrEmpty(filter))
            {
                formulaOperation = bboxOperation ?? null;
            }
            else
            {
                WfsFormulaParser parser = new WfsFormulaParser();
                formulaOperation = parser.Parse(filter);
                if (bboxOperation != null)
                {
                    formulaOperation = new BinaryLogicalOperation(formulaOperation, bboxOperation, WFSBinaryLogicalOperator.And);
                }
            }
            WFSFilter wfsFilter = new WFSFilter {
                Formula = formulaOperation
            };
            string strWfsXmlRepresentation = wfsFilter.WfsXmlRepresentation();

            return(strWfsXmlRepresentation);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the WFS features using a HTTP Post request.
        /// </summary>
        /// <param name="requestUrl">The request URL.</param>
        /// <param name="boundingBox">The bounding box.</param>
        public static FeatureCollection GetWfsFeaturesUsingHttpPost(string requestUrl, WfsBoundingBox boundingBox)
        {
            var    uri      = new Uri(requestUrl);
            string baseUrl  = uri.GetLeftPart(UriPartial.Path);
            string postData = CreateWfsGetFeatureXmlString(requestUrl, boundingBox);

            string strJson = MakeHttpPostRequest(baseUrl, postData);
            // Make a Json string to a featue collection type
            FeatureCollection featureCollection = JsonConvert.DeserializeObject(strJson, typeof(FeatureCollection)) as FeatureCollection;

            return(featureCollection);
        }