Ejemplo n.º 1
0
        async protected override Task <IFeatureCursor> FeatureCursor(IQueryFilter filter)
        {
            string response = "";

            string srsName = _sRef != null ? _sRef.Name : String.Empty;

            if (filter is ISpatialFilter)
            {
                filter = SpatialFilter.Project(filter as ISpatialFilter, this.SpatialReference);
                ((ISpatialFilter)filter).FilterSpatialReference = this.SpatialReference;
            }

            if (_dataset._getCapabilities.Post_OnlineResource == String.Empty &&
                _dataset._getCapabilities.Get_OnlineResource != String.Empty)
            {
                string param = "VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=" + this.Name + "&MAXFEATURES=10&FILTER=";
                if (_dataset._getCapabilities.Get_OnlineResource.IndexOf("&SERVICE=") == -1 &&
                    _dataset._getCapabilities.Get_OnlineResource.IndexOf("?SERVICE=") == -1)
                {
                    param = "SERVICE=WFS&" + param;
                }

                string wfsFilter = await Filter.ToWFS(this, filter, _dataset._filter_capabilites, _dataset._gmlVersion);

                string url = _dataset._getFeature.Get_OnlineResource;

                response = WebFunctions.HttpSendRequest(url, "GET", null);
            }
            else if (_dataset._getCapabilities.Post_OnlineResource != String.Empty)
            {
                string url = _dataset._getFeature.Post_OnlineResource;
                if (_dataset._getCapabilities.Get_OnlineResource.IndexOf("&SERVICE=") == -1 &&
                    _dataset._getCapabilities.Get_OnlineResource.IndexOf("?SERVICE=") == -1)
                {
                    url = WMSDataset.Append2Url(url, "SERVICE=WFS");
                }

                string wfsFilter = GetFeatureRequest.Create(this, this.Name, filter, srsName, _dataset._filter_capabilites, _dataset._gmlVersion);

                response = WebFunctions.HttpSendRequest(url, "POST",
                                                        Encoding.UTF8.GetBytes(wfsFilter));
            }
            if (response == String.Empty)
            {
                return(null);
            }

            try
            {
                StringReader  stringReader = new StringReader(response);
                XmlTextReader xmlReader    = new XmlTextReader(stringReader);

                XmlDocument doc = new XmlDocument();
                //doc.LoadXml(response);
                XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
                ns.AddNamespace("GML", "http://www.opengis.net/gml");
                ns.AddNamespace("WFS", "http://www.opengis.net/wfs");
                ns.AddNamespace("OGC", "http://www.opengis.net/ogc");
                ns.AddNamespace("myns", _targetNamespace);

                //XmlNode featureCollection = doc.SelectSingleNode("WFS:FeatureCollection", ns);
                //if (featureCollection == null)
                //    featureCollection = doc.SelectSingleNode("GML:FeatureCollection", ns);
                //if (featureCollection == null) return null;

                return(new gView.Framework.OGC.GML.FeatureCursor2(this, xmlReader, ns, filter, _dataset._gmlVersion, _dataset._filter_capabilites));
            }
            catch { }
            return(null);
        }
Ejemplo n.º 2
0
        public WFSFeatureClass(WFSDataset dataset, string name, WMSClass.SRS srs)
        {
            _dataset = dataset;
            _name    = name;
            _srs     = srs;

            if (_srs.Srs.Count > 0)
            {
                _sRef = gView.Framework.Geometry.SpatialReference.FromID(_srs.Srs[_srs.SRSIndex]);
            }

            try
            {
                string param = "VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=" + _name;
                if (_dataset._decribeFeatureType.Get_OnlineResource.IndexOf("&SERVICE=") == -1 &&
                    _dataset._decribeFeatureType.Get_OnlineResource.IndexOf("?SERVICE=") == -1)
                {
                    param = "SERVICE=WFS&" + param;
                }

                string url      = WMSDataset.Append2Url(_dataset._decribeFeatureType.Get_OnlineResource, param);
                string response = WebFunctions.HttpSendRequest(url, "GET", null);
                response = WMSDataset.RemoveDOCTYPE(response);

                XmlDocument schema = new XmlDocument();
                schema.LoadXml(response);
                XmlSchemaReader schemaReader = new XmlSchemaReader(schema);
                _targetNamespace = schemaReader.TargetNamespaceURI;
                if (_targetNamespace == String.Empty)
                {
                    return;
                }

                _fields = schemaReader.ElementFields(name, out _shapefieldName, out _geomtype);

                // Id Feld suchen
                foreach (IField field in _fields.ToEnumerable())
                {
                    if (field.type == FieldType.ID)
                    {
                        _idFieldname = field.name;
                        break;
                    }
                }
                // passendes feld suchen...
                //if (_idFieldname == String.Empty)
                //{
                //    foreach (IField field in _fields)
                //    {
                //        if (!(field is Field)) continue;
                //        switch (field.name.ToLower())
                //        {
                //            case "fdb_oid":
                //            case "oid":
                //            case "fid":
                //            case "objectid":
                //            case "featureid":
                //            case "ogc_fid":
                //                ((Field)field).type = FieldType.ID;
                //                _idFieldname = field.name;
                //                break;
                //        }
                //        if (_idFieldname != String.Empty) break;
                //    }
                //}
            }
            catch { }
        }
Ejemplo n.º 3
0
        public bool Open()
        {
            try
            {
                _elements.Clear();
                string param = "REQUEST=GetCapabilities&VERSION=1.0.0&SERVICE=WFS";

                string url      = WMSDataset.Append2Url(_url, param);
                string response = WebFunctions.HttpSendRequest(url, "GET", null);
                response = WMSDataset.RemoveDOCTYPE(response);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(response);
                XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
                ns.AddNamespace("WFS", "http://www.opengis.net/wfs");
                ns.AddNamespace("OGC", "http://www.opengis.net/ogc");
                ns.AddNamespace("GML", "http://www.opengis.net/gml");

                XmlNode CapabilitiesNode = doc.SelectSingleNode("WFS:WFS_Capabilities/WFS:Capability", ns);
                _getCapabilities    = new GetCapabilities(CapabilitiesNode.SelectSingleNode("WFS:Request/WFS:GetCapabilities", ns), ns);
                _decribeFeatureType = new DescribeFeatureType(CapabilitiesNode.SelectSingleNode("WFS:Request/WFS:DescribeFeatureType", ns), ns);
                _getFeature         = new GetFeature(CapabilitiesNode.SelectSingleNode("WFS:Request/WFS:GetFeature", ns), ns);

                XmlNode FeatureTypeListNode = doc.SelectSingleNode("WFS:WFS_Capabilities/WFS:FeatureTypeList", ns);
                _operations = new Operations(FeatureTypeListNode.SelectSingleNode("WFS:Operations", ns));

                foreach (XmlNode featureTypeNode in FeatureTypeListNode.SelectNodes("WFS:FeatureType", ns))
                {
                    string name  = "";
                    string title = "";

                    XmlNode nameNode  = featureTypeNode.SelectSingleNode("WFS:Name", ns);
                    XmlNode titleNode = featureTypeNode.SelectSingleNode("WFS:Title", ns);

                    WMSClass.SRS srs = new WMSClass.SRS(featureTypeNode, ns, "WFS");

                    name = title = nameNode.InnerText;
                    if (titleNode != null)
                    {
                        title = titleNode.InnerText;
                    }

                    WFSFeatureClass featureClass = new WFSFeatureClass(this, name, srs);
                    //DatasetElement dselement = new DatasetElement(featureClass);
                    ILayer dselement = LayerFactory.Create(featureClass);
                    if (dselement == null)
                    {
                        continue;
                    }
                    dselement.Title = name;

                    _elements.Add(dselement);
                }

                _filter_capabilites = new Filter_Capabilities(doc.SelectSingleNode("WFS:WFS_Capabilities/OGC:Filter_Capabilities", ns), ns);
                return(true);
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                return(false);
            }
        }