Пример #1
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 { }
        }
Пример #2
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);
            }
        }