Esempio n. 1
0
        /// <summary>
        /// This method gets metadata about the featuretype to query from 'GetCapabilities' and 'DescribeFeatureType'.
        /// </summary>
        private void GetFeatureTypeInfo()
        {
            try
            {
                _featureTypeInfo = new WfsFeatureTypeInfo();
                WFSClientHTTPConfigurator config = new WFSClientHTTPConfigurator(_textResources);

                _featureTypeInfo.Prefix = _nsPrefix;
                _featureTypeInfo.Name = _featureType;

                string featureQueryName = string.IsNullOrEmpty(_nsPrefix)
                                              ? _featureType
                                              : _nsPrefix + ":" + _featureType;

                /***************************/
                /* GetCapabilities request  /
                /***************************/

                if (_featureTypeInfoQueryManager == null)
                {
                    /* Initialize IXPathQueryManager with configured HttpClientUtil */
                    _featureTypeInfoQueryManager =
                        new XPathQueryManager_CompiledExpressionsDecorator(new XPathQueryManager());
                    _featureTypeInfoQueryManager.SetDocumentToParse(
                        config.configureForWfsGetCapabilitiesRequest(_httpClientUtil, _getCapabilitiesUri));
                    /* Namespaces for XPath queries */
                    _featureTypeInfoQueryManager.AddNamespace(_textResources.NSWFSPREFIX, _textResources.NSWFS);
                    _featureTypeInfoQueryManager.AddNamespace(_textResources.NSOWSPREFIX, _textResources.NSOWS);
                    _featureTypeInfoQueryManager.AddNamespace(_textResources.NSXLINKPREFIX, _textResources.NSXLINK);
                }

                /* Service URI (for WFS GetFeature request) */
                _featureTypeInfo.ServiceURI = _featureTypeInfoQueryManager.GetValueFromNode
                    (_featureTypeInfoQueryManager.Compile(_textResources.XPATH_GETFEATURERESOURCE));
                /* If no GetFeature URI could be found, try GetCapabilities URI */
                if (_featureTypeInfo.ServiceURI == null) _featureTypeInfo.ServiceURI = _getCapabilitiesUri;
                else if (_featureTypeInfo.ServiceURI.EndsWith("?", StringComparison.Ordinal))
                    _featureTypeInfo.ServiceURI =
                        _featureTypeInfo.ServiceURI.Remove(_featureTypeInfo.ServiceURI.Length - 1);

                /* URI for DescribeFeatureType request */
                string describeFeatureTypeUri = _featureTypeInfoQueryManager.GetValueFromNode
                    (_featureTypeInfoQueryManager.Compile(_textResources.XPATH_DESCRIBEFEATURETYPERESOURCE));
                /* If no DescribeFeatureType URI could be found, try GetCapabilities URI */
                if (describeFeatureTypeUri == null) describeFeatureTypeUri = _getCapabilitiesUri;
                else if (describeFeatureTypeUri.EndsWith("?", StringComparison.Ordinal))
                    describeFeatureTypeUri =
                        describeFeatureTypeUri.Remove(describeFeatureTypeUri.Length - 1);

                /* Spatial reference ID */
                _featureTypeInfo.SRID = _featureTypeInfoQueryManager.GetValueFromNode(
                    _featureTypeInfoQueryManager.Compile(_textResources.XPATH_SRS),
                    new[] {new DictionaryEntry("_param1", featureQueryName)});
                /* If no SRID could be found, try '4326' by default */
                if (_featureTypeInfo.SRID == null) _featureTypeInfo.SRID = "4326";
                else
                    /* Extract number */
                    _featureTypeInfo.SRID = _featureTypeInfo.SRID.Substring(_featureTypeInfo.SRID.LastIndexOf(":") + 1);

                /* Bounding Box */
                IXPathQueryManager bboxQuery = _featureTypeInfoQueryManager.GetXPathQueryManagerInContext(
                    _featureTypeInfoQueryManager.Compile(_textResources.XPATH_BBOX),
                    new[] {new DictionaryEntry("_param1", featureQueryName)});

                if (bboxQuery != null)
                {
                    WfsFeatureTypeInfo.BoundingBox bbox = new WfsFeatureTypeInfo.BoundingBox();
                    NumberFormatInfo formatInfo = new NumberFormatInfo();
                    formatInfo.NumberDecimalSeparator = ".";
                    string bboxVal = null;

                    if (_wfsVersion == WFSVersionEnum.WFS1_0_0)
                        bbox._MinLat =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMINY))) !=
                                null
                                    ? bboxVal
                                    : "0.0", formatInfo);
                    else if (_wfsVersion == WFSVersionEnum.WFS1_1_0)
                        bbox._MinLat =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMINY))) !=
                                null
                                    ? bboxVal.Substring(bboxVal.IndexOf(' ') + 1)
                                    : "0.0", formatInfo);

                    if (_wfsVersion == WFSVersionEnum.WFS1_0_0)
                        bbox._MaxLat =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMAXY))) !=
                                null
                                    ? bboxVal
                                    : "0.0", formatInfo);
                    else if (_wfsVersion == WFSVersionEnum.WFS1_1_0)
                        bbox._MaxLat =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMAXY))) !=
                                null
                                    ? bboxVal.Substring(bboxVal.IndexOf(' ') + 1)
                                    : "0.0", formatInfo);

                    if (_wfsVersion == WFSVersionEnum.WFS1_0_0)
                        bbox._MinLong =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMINX))) !=
                                null
                                    ? bboxVal
                                    : "0.0", formatInfo);
                    else if (_wfsVersion == WFSVersionEnum.WFS1_1_0)
                        bbox._MinLong =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMINX))) !=
                                null
                                    ? bboxVal.Substring(0, bboxVal.IndexOf(' ') + 1)
                                    : "0.0", formatInfo);

                    if (_wfsVersion == WFSVersionEnum.WFS1_0_0)
                        bbox._MaxLong =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMAXX))) !=
                                null
                                    ? bboxVal
                                    : "0.0", formatInfo);
                    else if (_wfsVersion == WFSVersionEnum.WFS1_1_0)
                        bbox._MaxLong =
                            Convert.ToDouble(
                                (bboxVal =
                                 bboxQuery.GetValueFromNode(bboxQuery.Compile(_textResources.XPATH_BOUNDINGBOXMAXX))) !=
                                null
                                    ? bboxVal.Substring(0, bboxVal.IndexOf(' ') + 1)
                                    : "0.0", formatInfo);

                    _featureTypeInfo.BBox = bbox;
                }

                //Continue with a clone in order to preserve the 'GetCapabilities' response
                IXPathQueryManager describeFeatureTypeQueryManager = _featureTypeInfoQueryManager.Clone();

                /******************************/
                /* DescribeFeatureType request /
                /******************************/

                /* Initialize IXPathQueryManager with configured HttpClientUtil */
                describeFeatureTypeQueryManager.ResetNamespaces();
                describeFeatureTypeQueryManager.SetDocumentToParse(config.configureForWfsDescribeFeatureTypeRequest
                                                                       (_httpClientUtil, describeFeatureTypeUri,
                                                                        featureQueryName));

                /* Namespaces for XPath queries */
                describeFeatureTypeQueryManager.AddNamespace(_textResources.NSSCHEMAPREFIX, _textResources.NSSCHEMA);
                describeFeatureTypeQueryManager.AddNamespace(_textResources.NSGMLPREFIX, _textResources.NSGML);

                /* Get target namespace */
                string targetNs = describeFeatureTypeQueryManager.GetValueFromNode(
                    describeFeatureTypeQueryManager.Compile(_textResources.XPATH_TARGETNS));
                if (targetNs != null)
                    _featureTypeInfo.FeatureTypeNamespace = targetNs;

                /* Get geometry */
                string geomType = _geometryType == GeometryTypeEnum.Unknown ? null : _geometryType.ToString();
                string geomName = null;
                string geomComplexTypeName = null;

                /* The easiest way to get geometry info, just ask for the 'gml'-prefixed type-attribute...
                   Simple, but effective in 90% of all cases...this is the standard GeoServer creates.*/
                /* example: <xs:element nillable = "false" name = "the_geom" maxOccurs = "1" type = "gml:MultiPolygonPropertyType" minOccurs = "0" /> */
                /* Try to get context of the geometry element by asking for a 'gml:*' type-attribute */
                IXPathQueryManager geomQuery = describeFeatureTypeQueryManager.GetXPathQueryManagerInContext(
                    describeFeatureTypeQueryManager.Compile(_textResources.XPATH_GEOMETRYELEMENT_BYTYPEATTRIBUTEQUERY));
                if (geomQuery != null)
                {
                    geomName = geomQuery.GetValueFromNode(geomQuery.Compile(_textResources.XPATH_NAMEATTRIBUTEQUERY));

                    /* Just, if not set manually... */
                    if (geomType == null)
                        geomType = geomQuery.GetValueFromNode(geomQuery.Compile(_textResources.XPATH_TYPEATTRIBUTEQUERY));
                }
                else
                {
                    /* Try to get context of a complexType with element ref ='gml:*' - use the global context */
                    /* example:
                    <xs:complexType name="geomType">
                        <xs:sequence>
                            <xs:element ref="gml:polygonProperty" minOccurs="0"/>
                        </xs:sequence>
                    </xs:complexType> */
                    geomQuery = describeFeatureTypeQueryManager.GetXPathQueryManagerInContext(
                        describeFeatureTypeQueryManager.Compile(
                            _textResources.XPATH_GEOMETRYELEMENTCOMPLEXTYPE_BYELEMREFQUERY));
                    if (geomQuery != null)
                    {
                        /* Ask for the name of the complextype - use the local context*/
                        geomComplexTypeName =
                            geomQuery.GetValueFromNode(geomQuery.Compile(_textResources.XPATH_NAMEATTRIBUTEQUERY));

                        if (geomComplexTypeName != null)
                        {
                            /* Ask for the name of an element with a complextype of 'geomComplexType' - use the global context */
                            geomName =
                                describeFeatureTypeQueryManager.GetValueFromNode(
                                    describeFeatureTypeQueryManager.Compile(
                                        _textResources.XPATH_GEOMETRY_ELEMREF_GEOMNAMEQUERY), new[]
                                                                                                  {
                                                                                                      new DictionaryEntry
                                                                                                          ("_param1",
                                                                                                           _featureTypeInfo
                                                                                                               .
                                                                                                               FeatureTypeNamespace)
                                                                                                      ,
                                                                                                      new DictionaryEntry
                                                                                                          ("_param2",
                                                                                                           geomComplexTypeName)
                                                                                                  });
                        }
                        else
                        {
                            /* The geometry element must be an ancestor, if we found an anonymous complextype */
                            /* Ask for the element hosting the anonymous complextype - use the global context */
                            /* example:
                            <xs:element name ="SHAPE">
                                <xs:complexType>
                                    <xs:sequence>
                              		    <xs:element ref="gml:lineStringProperty" minOccurs="0"/>
                                  </xs:sequence>
                                </xs:complexType>
                            </xs:element> */
                            geomName =
                                describeFeatureTypeQueryManager.GetValueFromNode(
                                    describeFeatureTypeQueryManager.Compile(
                                        _textResources.XPATH_GEOMETRY_ELEMREF_GEOMNAMEQUERY_ANONYMOUSTYPE));
                        }
                        /* Just, if not set manually... */
                        if (geomType == null)
                        {
                            /* Ask for the 'ref'-attribute - use the local context */
                            if (
                                (geomType =
                                 geomQuery.GetValueFromNode(
                                     geomQuery.Compile(_textResources.XPATH_GEOMETRY_ELEMREF_GMLELEMENTQUERY))) != null)
                            {
                                switch (geomType)
                                {
                                    case "gml:pointProperty":
                                        geomType = "PointPropertyType";
                                        break;
                                    case "gml:lineStringProperty":
                                        geomType = "LineStringPropertyType";
                                        break;
                                    case "gml:curveProperty":
                                        geomType = "CurvePropertyType";
                                        break;
                                    case "gml:polygonProperty":
                                        geomType = "PolygonPropertyType";
                                        break;
                                    case "gml:surfaceProperty":
                                        geomType = "SurfacePropertyType";
                                        break;
                                    case "gml:multiPointProperty":
                                        geomType = "MultiPointPropertyType";
                                        break;
                                    case "gml:multiLineStringProperty":
                                        geomType = "MultiLineStringPropertyType";
                                        break;
                                    case "gml:multiCurveProperty":
                                        geomType = "MultiCurvePropertyType";
                                        break;
                                    case "gml:multiPolygonProperty":
                                        geomType = "MultiPolygonPropertyType";
                                        break;
                                    case "gml:multiSurfaceProperty":
                                        geomType = "MultiSurfacePropertyType";
                                        break;
                                        // e.g. 'gml:_geometryProperty'
                                    default:
                                        break;
                                }
                            }
                        }
                    }
                }

                if (geomName == null)
                    /* Default value for geometry column = geom */
                    geomName = "geom";

                if (geomType == null)
                    /* Set geomType to an empty string in order to avoid exceptions.
                    The geometry type is not necessary by all means - it can be detected in 'GetFeature' response too.. */
                    geomType = string.Empty;

                /* Remove prefix */
                if (geomType.Contains(":"))
                    geomType = geomType.Substring(geomType.IndexOf(":") + 1);

                WfsFeatureTypeInfo.GeometryInfo geomInfo = new WfsFeatureTypeInfo.GeometryInfo();
                geomInfo._GeometryName = geomName;
                geomInfo._GeometryType = geomType;
                _featureTypeInfo.Geometry = geomInfo;
            }
            finally
            {
                _httpClientUtil.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the features within the specified <see cref="GeoAPI.Geometries.Envelope"/>
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns>Features within the specified <see cref="GeoAPI.Geometries.Envelope"/></returns>
        public Collection<IGeometry> GetGeometriesInView(Envelope bbox)
        {
            if (_featureTypeInfo == null) return null;

            var geoms = new Collection<IGeometry>();

            string geometryTypeString = _featureTypeInfo.Geometry._GeometryType;

            GeometryFactory geomFactory = null;

            if (!string.IsNullOrEmpty(_label))
            {
                _labelInfo = new FeatureDataTable();
                _labelInfo.Columns.Add(_label);
                // Turn off quick geometries, if a label is applied...
                _quickGeometries = false;
            }

            // Configuration for GetFeature request */
            WFSClientHTTPConfigurator config = new WFSClientHTTPConfigurator(_textResources);
            config.configureForWfsGetFeatureRequest(_httpClientUtil, _featureTypeInfo, _label, bbox, _ogcFilter,
                                                    _getFeatureGETRequest);

            try
            {
                switch (geometryTypeString)
                {
                        /* Primitive geometry elements */

                        // GML2
                    case "PointPropertyType":
                        geomFactory = new PointFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML2
                    case "LineStringPropertyType":
                        geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML2
                    case "PolygonPropertyType":
                        geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML3
                    case "CurvePropertyType":
                        geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML3
                    case "SurfacePropertyType":
                        geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        /* Aggregate geometry elements */

                        // GML2
                    case "MultiPointPropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiPointFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new PointFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML2
                    case "MultiLineStringPropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiLineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML2
                    case "MultiPolygonPropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiPolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML3
                    case "MultiCurvePropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiLineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // GML3
                    case "MultiSurfacePropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiPolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                        // .e.g. 'gml:GeometryAssociationType' or 'GeometryPropertyType'
                        //It's better to set the geometry type manually, if it is known...
                    default:
                        geomFactory = new UnspecifiedGeometryFactory_WFS1_0_0_GML2(_httpClientUtil, _featureTypeInfo,
                                                                                   _multiGeometries, _quickGeometries,
                                                                                   _labelInfo);
                        geoms = geomFactory.createGeometries();
                        return geoms;
                }

                geoms = _quickGeometries
                            ? geomFactory.createQuickGeometries(geometryTypeString)
                            : geomFactory.createGeometries();
                geomFactory.Dispose();

                return geoms;
            }
                // Free resources (net connection of geometry factory)
            finally
            {
                if (geomFactory != null)
                {
                    geomFactory.Dispose();
                }
            }
        }
Esempio n. 3
0
        public System.Collections.ObjectModel.Collection <SharpMap.Geometries.Geometry> GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox)
        {
            if (_FeatureTypeInfo == null)
            {
                return(null);
            }

            System.Collections.ObjectModel.Collection <Geometry> geoms = new System.Collections.ObjectModel.Collection <Geometry>();

            string geometryTypeString = _FeatureTypeInfo.Geometry._GeometryType;

            GeometryFactory geomFactory = null;

            if (!string.IsNullOrEmpty(_Label))
            {
                _LabelInfo = new FeatureDataTable();
                _LabelInfo.Columns.Add(_Label);
                // Turn off quick geometries, if a label is applied...
                _QuickGeometries = false;
            }

            // Configuration for GetFeature request */
            WFSClientHTTPConfigurator config = new WFSClientHTTPConfigurator(_TextResources);

            config.configureForWfsGetFeatureRequest(_HttpClientUtil, _FeatureTypeInfo, _Label, bbox, _OGCFilter, _GetFeatureGETRequest);

            try
            {
                switch (geometryTypeString)
                {
                /* Primitive geometry elements */

                // GML2
                case "PointPropertyType":
                    geomFactory = new PointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML2
                case "LineStringPropertyType":
                    geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML2
                case "PolygonPropertyType":
                    geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML3
                case "CurvePropertyType":
                    geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML3
                case "SurfacePropertyType":
                    geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                /* Aggregate geometry elements */

                // GML2
                case "MultiPointPropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiPointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new PointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML2
                case "MultiLineStringPropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiLineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML2
                case "MultiPolygonPropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiPolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML3
                case "MultiCurvePropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiLineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML3
                case "MultiSurfacePropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiPolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // .e.g. 'gml:GeometryAssociationType' or 'GeometryPropertyType'
                //It's better to set the geometry type manually, if it is known...
                default:
                    geomFactory = new UnspecifiedGeometryFactory_WFS1_0_0_GML2(_HttpClientUtil, _FeatureTypeInfo, _MultiGeometries, _QuickGeometries, _LabelInfo);
                    geoms       = geomFactory.createGeometries();
                    return(geoms);
                }

                geoms = _QuickGeometries ? geomFactory.createQuickGeometries(geometryTypeString) : geomFactory.createGeometries();
                geomFactory.Dispose();

                return(geoms);
            }
            // Free resources (net connection of geometry factory)
            finally
            {
                geomFactory.Dispose();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This method gets metadata about the featuretype to query from 'GetCapabilities' and 'DescribeFeatureType'.
        /// </summary>
        private void GetFeatureTypeInfo()
        {
            try
            {
                _FeatureTypeInfo = new WfsFeatureTypeInfo();
                WFSClientHTTPConfigurator config = new WFSClientHTTPConfigurator(_TextResources);

                _FeatureTypeInfo.Prefix = _NsPrefix;
                _FeatureTypeInfo.Name   = _FeatureType;

                string featureQueryName = string.IsNullOrEmpty(_NsPrefix) ? _FeatureType : _NsPrefix + ":" + _FeatureType;

                /***************************/

                /* GetCapabilities request  /
                *  /***************************/

                if (_FeatureTypeInfoQueryManager == null)
                {
                    /* Initialize IXPathQueryManager with configured HttpClientUtil */
                    _FeatureTypeInfoQueryManager = new XPathQueryManager_CompiledExpressionsDecorator(new XPathQueryManager());
                    _FeatureTypeInfoQueryManager.SetDocumentToParse(config.configureForWfsGetCapabilitiesRequest(_HttpClientUtil, _GetCapabilitiesURI));
                    /* Namespaces for XPath queries */
                    _FeatureTypeInfoQueryManager.AddNamespace(_TextResources.NSWFSPREFIX, _TextResources.NSWFS);
                    _FeatureTypeInfoQueryManager.AddNamespace(_TextResources.NSOWSPREFIX, _TextResources.NSOWS);
                    _FeatureTypeInfoQueryManager.AddNamespace(_TextResources.NSXLINKPREFIX, _TextResources.NSXLINK);
                }

                /* Service URI (for WFS GetFeature request) */
                _FeatureTypeInfo.ServiceURI = _FeatureTypeInfoQueryManager.GetValueFromNode
                                                  (_FeatureTypeInfoQueryManager.Compile(_TextResources.XPATH_GETFEATURERESOURCE));
                /* If no GetFeature URI could be found, try GetCapabilities URI */
                if (_FeatureTypeInfo.ServiceURI == null)
                {
                    _FeatureTypeInfo.ServiceURI = _GetCapabilitiesURI;
                }
                else
                if (_FeatureTypeInfo.ServiceURI.EndsWith("?", StringComparison.Ordinal))
                {
                    _FeatureTypeInfo.ServiceURI =
                        _FeatureTypeInfo.ServiceURI.Remove(_FeatureTypeInfo.ServiceURI.Length - 1);
                }

                /* URI for DescribeFeatureType request */
                string describeFeatureTypeUri = _FeatureTypeInfoQueryManager.GetValueFromNode
                                                    (_FeatureTypeInfoQueryManager.Compile(_TextResources.XPATH_DESCRIBEFEATURETYPERESOURCE));
                /* If no DescribeFeatureType URI could be found, try GetCapabilities URI */
                if (describeFeatureTypeUri == null)
                {
                    describeFeatureTypeUri = _GetCapabilitiesURI;
                }
                else
                if (describeFeatureTypeUri.EndsWith("?", StringComparison.Ordinal))
                {
                    describeFeatureTypeUri =
                        describeFeatureTypeUri.Remove(describeFeatureTypeUri.Length - 1);
                }

                /* Spatial reference ID */
                _FeatureTypeInfo.SRID = _FeatureTypeInfoQueryManager.GetValueFromNode(
                    _FeatureTypeInfoQueryManager.Compile(_TextResources.XPATH_SRS),
                    new DictionaryEntry[] { new DictionaryEntry("_param1", featureQueryName) });
                /* If no SRID could be found, try '4326' by default */
                if (_FeatureTypeInfo.SRID == null)
                {
                    _FeatureTypeInfo.SRID = "4326";
                }
                else
                {
                    /* Extract number */
                    _FeatureTypeInfo.SRID = _FeatureTypeInfo.SRID.Substring(_FeatureTypeInfo.SRID.LastIndexOf(":") + 1);
                }

                /* Bounding Box */
                IXPathQueryManager bboxQuery = _FeatureTypeInfoQueryManager.GetXPathQueryManagerInContext(
                    _FeatureTypeInfoQueryManager.Compile(_TextResources.XPATH_BBOX),
                    new DictionaryEntry[] { new DictionaryEntry("_param1", featureQueryName) });

                if (bboxQuery != null)
                {
                    WfsFeatureTypeInfo.BoundingBox        bbox       = new WfsFeatureTypeInfo.BoundingBox();
                    System.Globalization.NumberFormatInfo formatInfo = new System.Globalization.NumberFormatInfo();
                    formatInfo.NumberDecimalSeparator = ".";
                    string bboxVal = null;

                    if (_WfsVersion == WFSVersionEnum.WFS1_0_0)
                    {
                        bbox._MinLat = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMINY))) != null ? bboxVal : "0.0", formatInfo);
                    }
                    else if (_WfsVersion == WFSVersionEnum.WFS1_1_0)
                    {
                        bbox._MinLat = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMINY))) != null ? bboxVal.Substring(bboxVal.IndexOf(' ') + 1) : "0.0", formatInfo);
                    }

                    if (_WfsVersion == WFSVersionEnum.WFS1_0_0)
                    {
                        bbox._MaxLat = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMAXY))) != null ? bboxVal : "0.0", formatInfo);
                    }
                    else if (_WfsVersion == WFSVersionEnum.WFS1_1_0)
                    {
                        bbox._MaxLat = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMAXY))) != null ? bboxVal.Substring(bboxVal.IndexOf(' ') + 1) : "0.0", formatInfo);
                    }

                    if (_WfsVersion == WFSVersionEnum.WFS1_0_0)
                    {
                        bbox._MinLong = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMINX))) != null ? bboxVal : "0.0", formatInfo);
                    }
                    else if (_WfsVersion == WFSVersionEnum.WFS1_1_0)
                    {
                        bbox._MinLong = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMINX))) != null ? bboxVal.Substring(0, bboxVal.IndexOf(' ') + 1) : "0.0", formatInfo);
                    }

                    if (_WfsVersion == WFSVersionEnum.WFS1_0_0)
                    {
                        bbox._MaxLong = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMAXX))) != null ? bboxVal : "0.0", formatInfo);
                    }
                    else if (_WfsVersion == WFSVersionEnum.WFS1_1_0)
                    {
                        bbox._MaxLong = Convert.ToDouble((bboxVal = bboxQuery.GetValueFromNode(bboxQuery.Compile(_TextResources.XPATH_BOUNDINGBOXMAXX))) != null ? bboxVal.Substring(0, bboxVal.IndexOf(' ') + 1) : "0.0", formatInfo);
                    }

                    _FeatureTypeInfo.BBox = bbox;
                }

                //Continue with a clone in order to preserve the 'GetCapabilities' response
                IXPathQueryManager describeFeatureTypeQueryManager = _FeatureTypeInfoQueryManager.Clone();

                /******************************/

                /* DescribeFeatureType request /
                *  /******************************/

                /* Initialize IXPathQueryManager with configured HttpClientUtil */
                describeFeatureTypeQueryManager.ResetNamespaces();
                describeFeatureTypeQueryManager.SetDocumentToParse(config.configureForWfsDescribeFeatureTypeRequest
                                                                       (_HttpClientUtil, describeFeatureTypeUri, featureQueryName));

                /* Namespaces for XPath queries */
                describeFeatureTypeQueryManager.AddNamespace(_TextResources.NSSCHEMAPREFIX, _TextResources.NSSCHEMA);
                describeFeatureTypeQueryManager.AddNamespace(_TextResources.NSGMLPREFIX, _TextResources.NSGML);

                /* Get target namespace */
                string targetNs = describeFeatureTypeQueryManager.GetValueFromNode(
                    describeFeatureTypeQueryManager.Compile(_TextResources.XPATH_TARGETNS));
                if (targetNs != null)
                {
                    _FeatureTypeInfo.FeatureTypeNamespace = targetNs;
                }

                /* Get geometry */
                string geomType            = _GeometryType == GeometryTypeEnum.Unknown ? null : _GeometryType.ToString();
                string geomName            = null;
                string geomComplexTypeName = null;

                /* The easiest way to get geometry info, just ask for the 'gml'-prefixed type-attribute...
                 * Simple, but effective in 90% of all cases...this is the standard GeoServer creates.*/
                /* example: <xs:element nillable = "false" name = "the_geom" maxOccurs = "1" type = "gml:MultiPolygonPropertyType" minOccurs = "0" /> */
                /* Try to get context of the geometry element by asking for a 'gml:*' type-attribute */
                IXPathQueryManager geomQuery = describeFeatureTypeQueryManager.GetXPathQueryManagerInContext(
                    describeFeatureTypeQueryManager.Compile(_TextResources.XPATH_GEOMETRYELEMENT_BYTYPEATTRIBUTEQUERY));
                if (geomQuery != null)
                {
                    geomName = geomQuery.GetValueFromNode(geomQuery.Compile(_TextResources.XPATH_NAMEATTRIBUTEQUERY));

                    /* Just, if not set manually... */
                    if (geomType == null)
                    {
                        geomType = geomQuery.GetValueFromNode(geomQuery.Compile(_TextResources.XPATH_TYPEATTRIBUTEQUERY));
                    }
                }
                else
                {
                    /* Try to get context of a complexType with element ref ='gml:*' - use the global context */

                    /* example:
                     * <xs:complexType name="geomType">
                     *  <xs:sequence>
                     *      <xs:element ref="gml:polygonProperty" minOccurs="0"/>
                     *  </xs:sequence>
                     * </xs:complexType> */
                    geomQuery = describeFeatureTypeQueryManager.GetXPathQueryManagerInContext(
                        describeFeatureTypeQueryManager.Compile(_TextResources.XPATH_GEOMETRYELEMENTCOMPLEXTYPE_BYELEMREFQUERY));
                    if (geomQuery != null)
                    {
                        /* Ask for the name of the complextype - use the local context*/
                        geomComplexTypeName = geomQuery.GetValueFromNode(geomQuery.Compile(_TextResources.XPATH_NAMEATTRIBUTEQUERY));

                        if (geomComplexTypeName != null)
                        {
                            /* Ask for the name of an element with a complextype of 'geomComplexType' - use the global context */
                            geomName = describeFeatureTypeQueryManager.GetValueFromNode(describeFeatureTypeQueryManager.Compile(
                                                                                            _TextResources.XPATH_GEOMETRY_ELEMREF_GEOMNAMEQUERY), new DictionaryEntry[] {
                                new DictionaryEntry("_param1", _FeatureTypeInfo.FeatureTypeNamespace),
                                new DictionaryEntry("_param2", geomComplexTypeName)
                            });
                        }
                        else
                        {
                            /* The geometry element must be an ancestor, if we found an anonymous complextype */
                            /* Ask for the element hosting the anonymous complextype - use the global context */

                            /* example:
                             * <xs:element name ="SHAPE">
                             *  <xs:complexType>
                             *      <xs:sequence>
                             *              <xs:element ref="gml:lineStringProperty" minOccurs="0"/>
                             *    </xs:sequence>
                             *  </xs:complexType>
                             * </xs:element> */
                            geomName = describeFeatureTypeQueryManager.GetValueFromNode(describeFeatureTypeQueryManager.Compile(_TextResources.XPATH_GEOMETRY_ELEMREF_GEOMNAMEQUERY_ANONYMOUSTYPE));
                        }
                        /* Just, if not set manually... */
                        if (geomType == null)
                        {
                            /* Ask for the 'ref'-attribute - use the local context */
                            if ((geomType = geomQuery.GetValueFromNode(geomQuery.Compile(_TextResources.XPATH_GEOMETRY_ELEMREF_GMLELEMENTQUERY))) != null)
                            {
                                switch (geomType)
                                {
                                case "gml:pointProperty": geomType = "PointPropertyType"; break;

                                case "gml:lineStringProperty": geomType = "LineStringPropertyType"; break;

                                case "gml:curveProperty": geomType = "CurvePropertyType"; break;

                                case "gml:polygonProperty": geomType = "PolygonPropertyType"; break;

                                case "gml:surfaceProperty": geomType = "SurfacePropertyType"; break;

                                case "gml:multiPointProperty": geomType = "MultiPointPropertyType"; break;

                                case "gml:multiLineStringProperty": geomType = "MultiLineStringPropertyType"; break;

                                case "gml:multiCurveProperty": geomType = "MultiCurvePropertyType"; break;

                                case "gml:multiPolygonProperty": geomType = "MultiPolygonPropertyType"; break;

                                case "gml:multiSurfaceProperty": geomType = "MultiSurfacePropertyType"; break;

                                // e.g. 'gml:_geometryProperty'
                                default: break;
                                }
                            }
                        }
                    }
                }

                if (geomName == null)
                {
                    /* Default value for geometry column = geom */
                    geomName = "geom";
                }

                if (geomType == null)
                {
                    /* Set geomType to an empty string in order to avoid exceptions.
                     * The geometry type is not necessary by all means - it can be detected in 'GetFeature' response too.. */
                    geomType = string.Empty;
                }

                /* Remove prefix */
                if (geomType.Contains(":"))
                {
                    geomType = geomType.Substring(geomType.IndexOf(":") + 1);
                }

                WfsFeatureTypeInfo.GeometryInfo geomInfo = new WfsFeatureTypeInfo.GeometryInfo();
                geomInfo._GeometryName    = geomName;
                geomInfo._GeometryType    = geomType;
                _FeatureTypeInfo.Geometry = geomInfo;
            }
            finally
            {
                _HttpClientUtil.Close();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the features within the specified <see cref="GeoAPI.Geometries.Envelope"/>
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns>Features within the specified <see cref="GeoAPI.Geometries.Envelope"/></returns>
        public IEnumerable<IGeometry> GetGeometriesInView(Envelope bbox, CancellationToken? cancellationToken = null)
        {
            if (_featureTypeInfo == null) return null;

            var geoms = new Collection<IGeometry>();

            string geometryTypeString = _featureTypeInfo.Geometry._GeometryType;

            GeometryFactory geomFactory = null;

            if (!string.IsNullOrEmpty(_label))
            {
                var ff = FeatureFactory.CreateInt32(GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(SRID),
                    new FeatureAttributeDefinition
                    {
                        AttributeName = "Label",
                        Default = string.Empty,
                        AttributeType = typeof(string),
                        IsNullable = true
                    });
                _labelInfo = new FeatureCollection<int>(ff);
                // Turn off quick geometries, if a label is applied...
                _quickGeometries = false;
            }

            // Configuration for GetFeatureByOid request */
            WFSClientHTTPConfigurator config = new WFSClientHTTPConfigurator(_textResources);
            config.configureForWfsGetFeatureRequest(_httpClientUtil, _featureTypeInfo, _label, bbox, _ogcFilter,
                                                    _getFeatureGETRequest);

            try
            {
                switch (geometryTypeString)
                {
                    /* Primitive geometry elements */

                    // GML2
                    case "PointPropertyType":
                        geomFactory = new PointFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML2
                    case "LineStringPropertyType":
                        geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML2
                    case "PolygonPropertyType":
                        geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML3
                    case "CurvePropertyType":
                        geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML3
                    case "SurfacePropertyType":
                        geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    /* Aggregate geometry elements */

                    // GML2
                    case "MultiPointPropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiPointFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new PointFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML2
                    case "MultiLineStringPropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiLineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML2
                    case "MultiPolygonPropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiPolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML3
                    case "MultiCurvePropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiLineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // GML3
                    case "MultiSurfacePropertyType":
                        if (_multiGeometries)
                            geomFactory = new MultiPolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        else
                            geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo, _labelInfo);
                        break;

                    // .e.g. 'gml:GeometryAssociationType' or 'GeometryPropertyType'
                    //It's better to set the geometry type manually, if it is known...
                    default:
                        geomFactory = new UnspecifiedGeometryFactory_WFS1_0_0_GML2(_httpClientUtil, _featureTypeInfo,
                                                                                   _multiGeometries, _quickGeometries,
                                                                                   _labelInfo);
                        geoms = geomFactory.createGeometries();
                        return geoms;
                }

                geoms = _quickGeometries
                            ? geomFactory.createQuickGeometries(geometryTypeString)
                            : geomFactory.createGeometries();
                geomFactory.Dispose();

                return geoms;
            }
            // Free resources (net connection of geometry factory)
            finally
            {
                if (geomFactory != null)
                {
                    geomFactory.Dispose();
                }
            }
        }