예제 #1
0
        public object Clone()
        {
            WMSClass clone = new WMSClass(_dataset);

            clone._clonedThemes = new List <IWebServiceTheme>();

            foreach (IWebServiceTheme theme in Themes)
            {
                if (theme == null || theme.Class == null)
                {
                    continue;
                }

                WebServiceTheme clonedTheme = new WebServiceTheme(
                    theme.Class, theme.Title, theme.LayerID, theme.Visible, clone);
                clonedTheme.ID = theme.ID;
                clone._clonedThemes.Add(clonedTheme);
            }

            clone._exceptions               = this._exceptions;
            clone._srs                      = (SRS)this._srs.Clone();
            clone._sRef                     = this._sRef;
            clone._envelope                 = this._envelope;
            clone._getCapabilities          = this._getCapabilities;
            clone._getFeatureInfo           = this._getFeatureInfo;
            clone._getMap                   = this._getMap;
            clone._userDefinedSymbolization = this._userDefinedSymbolization;
            clone.AfterMapRequest           = AfterMapRequest;
            clone.BeforeMapRequest          = BeforeMapRequest;
            return(clone);
        }
예제 #2
0
        public bool Open()
        {
            try
            {
                _opened = true;
                _themes.Clear();

                MapServerConnection server = new MapServerConnection(ConfigTextStream.ExtractValue(_connection, "server"));
                string axl = "<ARCXML version=\"1.1\"><REQUEST><GET_SERVICE_INFO fields=\"true\" envelope=\"true\" renderer=\"false\" extensions=\"false\" gv_meta=\"true\" /></REQUEST></ARCXML>";
                axl = server.Send(_name, axl, "BB294D9C-A184-4129-9555-398AA70284BC",
                                  ConfigTextStream.ExtractValue(_connection, "user"),
                                  ConfigTextStream.ExtractValue(_connection, "pwd"));

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(axl);

                if (_class == null)
                {
                    _class = new MapServerClass(this);
                }

                double  dpi    = 96.0;
                XmlNode screen = doc.SelectSingleNode("//ENVIRONMENT/SCREEN");
                if (screen != null)
                {
                    if (screen.Attributes["dpi"] != null)
                    {
                        dpi = Convert.ToDouble(screen.Attributes["dpi"].Value.Replace(".", ","));
                    }
                }
                double dpm = (dpi / 0.0254);

                XmlNode spatialReference = doc.SelectSingleNode("//PROPERTIES/SPATIALREFERENCE");
                if (spatialReference != null)
                {
                    if (spatialReference.Attributes["param"] != null)
                    {
                        SpatialReference sRef = new SpatialReference();
                        gView.Framework.Geometry.SpatialReference.FromProj4(sRef, spatialReference.Attributes["param"].Value);

                        if (spatialReference.Attributes["name"] != null)
                        {
                            sRef.Name = spatialReference.Attributes["name"].Value;
                        }

                        _class.SpatialReference = sRef;
                    }
                }
                else
                {
                    XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS");
                    if (FeatureCoordSysNode != null)
                    {
                        if (FeatureCoordSysNode.Attributes["id"] != null)
                        {
                            _class.SpatialReference = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + FeatureCoordSysNode.Attributes["id"].Value);
                        }
                        else if (FeatureCoordSysNode.Attributes["string"] != null)
                        {
                            _class.SpatialReference = gView.Framework.Geometry.SpatialReference.FromWKT(FeatureCoordSysNode.Attributes["string"].Value);
                        }

                        // TODO: Geogr. Datum aus "datumtransformid" und "datumtransformstring"
                        //if (_sRef != null && FeatureCoordSysNode.Attributes["datumtransformstring"] != null)
                        //{

                        //}
                    }
                }

                foreach (XmlNode envelopeNode in doc.SelectNodes("//ENVELOPE"))
                {
                    if (_envelope == null)
                    {
                        _envelope = (new Envelope(envelopeNode)).MakeValid();
                    }
                    else
                    {
                        _envelope.Union((new Envelope(envelopeNode)).MakeValid());
                    }
                }
                foreach (XmlNode layerNode in doc.SelectNodes("//LAYERINFO[@id]"))
                {
                    bool visible = true;

                    ISpatialReference sRef = _class.SpatialReference;

                    /*
                     * spatialReference = doc.SelectSingleNode("//PROPERTIES/SPATIALREFERENCE");
                     * if (spatialReference != null)
                     * {
                     *  if (spatialReference.Attributes["param"] != null)
                     *  {
                     *      sRef = new SpatialReference();
                     *      gView.Framework.Geometry.SpatialReference.FromProj4(sRef, spatialReference.Attributes["param"].Value);
                     *
                     *      if (spatialReference.Attributes["name"] != null)
                     *          ((SpatialReference)sRef).Name = spatialReference.Attributes["name"].Value;
                     *  }
                     * }
                     * else
                     * {
                     *  XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS");
                     *  if (FeatureCoordSysNode != null)
                     *  {
                     *      if (FeatureCoordSysNode.Attributes["id"] != null)
                     *      {
                     *          sRef = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + FeatureCoordSysNode.Attributes["id"].Value);
                     *      }
                     *      else if (FeatureCoordSysNode.Attributes["string"] != null)
                     *      {
                     *          sRef = gView.Framework.Geometry.SpatialReference.FromWKT(FeatureCoordSysNode.Attributes["string"].Value);
                     *      }
                     *
                     *      // TODO: Geogr. Datum aus "datumtransformid" und "datumtransformstring"
                     *      //if (_sRef != null && FeatureCoordSysNode.Attributes["datumtransformstring"] != null)
                     *      //{
                     *
                     *      //}
                     *  }
                     * }
                     */

                    if (layerNode.Attributes["visible"] != null)
                    {
                        bool.TryParse(layerNode.Attributes["visible"].Value, out visible);
                    }

                    IClass           themeClass = null;
                    IWebServiceTheme theme      = null;
                    if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "featureclass")
                    {
                        themeClass = new MapThemeFeatureClass(this, layerNode.Attributes["id"].Value);
                        ((MapThemeFeatureClass)themeClass).Name             = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value;
                        ((MapThemeFeatureClass)themeClass).fieldsFromAXL    = layerNode.InnerXml;
                        ((MapThemeFeatureClass)themeClass).SpatialReference = sRef;

                        XmlNode FCLASS = layerNode.SelectSingleNode("FCLASS[@type]");
                        if (FCLASS != null)
                        {
                            ((MapThemeFeatureClass)themeClass).fClassTypeString = FCLASS.Attributes["type"].Value;
                        }
                        theme = LayerFactory.Create(themeClass, _class) as IWebServiceTheme;
                        if (theme == null)
                        {
                            continue;
                        }
                        theme.Visible = visible;
                    }
                    else if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "image")
                    {
                        if (layerNode.SelectSingleNode("gv_meta/class/implements[@type='gView.Framework.Data.IPointIdentify']") != null)
                        {
                            themeClass = new MapThemeQueryableRasterClass(this, layerNode.Attributes["id"].Value);
                            ((MapThemeQueryableRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value;
                        }
                        else
                        {
                            themeClass = new MapThemeRasterClass(this, layerNode.Attributes["id"].Value);
                            ((MapThemeRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value;
                        }
                        theme = new WebServiceTheme(
                            themeClass,
                            themeClass.Name,
                            layerNode.Attributes["id"].Value,
                            visible,
                            _class);
                    }
                    else
                    {
                        continue;
                    }

                    try
                    {
                        if (layerNode.Attributes["minscale"] != null)
                        {
                            theme.MinimumScale = Convert.ToDouble(layerNode.Attributes["minscale"].Value.Replace(".", ",")) * dpm;
                        }
                        if (layerNode.Attributes["maxscale"] != null)
                        {
                            theme.MaximumScale = Convert.ToDouble(layerNode.Attributes["maxscale"].Value.Replace(".", ",")) * dpm;
                        }
                    }
                    catch { }
                    _themes.Add(theme);
                }
                _state = DatasetState.opened;
                return(true);
            }
            catch (Exception ex)
            {
                _state = DatasetState.unknown;
                _class = null;
                return(false);
            }
        }
예제 #3
0
        internal void Init(string CapabilitiesString, WFSDataset wfsDataset)
        {
            try
            {
                _themes = new List <IWebServiceTheme>();

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(CapabilitiesString);

                XmlNode CapabilitiesNode = doc.SelectSingleNode("WMT_MS_Capabilities/Capability");
                _getCapabilities          = new GetCapabilities(CapabilitiesNode.SelectSingleNode("Request/GetCapabilities"));
                _getMap                   = new GetMap(CapabilitiesNode.SelectSingleNode("Request/GetMap"));
                _getFeatureInfo           = new GetFeatureInfo(CapabilitiesNode.SelectSingleNode("Request/GetFeatureInfo"));
                _describeLayer            = new DescribeLayer(CapabilitiesNode.SelectSingleNode("Request/DescribeLayer"));
                _getLegendGraphic         = new GetLegendGraphic(CapabilitiesNode.SelectSingleNode("Request/GetLegendGraphic"));
                _getStyles                = new GetStyles(CapabilitiesNode.SelectSingleNode("Request/GetStyles"));
                _exceptions               = new WMSExceptions(CapabilitiesNode.SelectSingleNode("Exception"));
                _userDefinedSymbolization = new UserDefinedSymbolization(CapabilitiesNode.SelectSingleNode("UserDefinedSymbolization"));

                XmlNode service = CapabilitiesNode.SelectSingleNode("Layer");
                XmlNode title   = service.SelectSingleNode("Title");
                if (title != null)
                {
                    _name = title.InnerText;
                }

                _srs         = new SRS(service);
                this.SRSCode = _srs.Srs[_srs.SRSIndex];

                foreach (XmlNode layer in service.SelectNodes("Layer"))
                {
                    string  name = "", Title = "";
                    XmlNode nameNode  = layer.SelectSingleNode("Name");
                    XmlNode titleNode = layer.SelectSingleNode("Title");

                    if (nameNode == null)
                    {
                        continue;
                    }
                    name = Title = nameNode.InnerText;
                    if (titleNode != null)
                    {
                        Title = titleNode.InnerText;
                    }
                    XmlNodeList styles = layer.SelectNodes("Style");

                    WFSFeatureClass wfsFc = null;
                    if (wfsDataset != null)
                    {
                        IDatasetElement wfsElement = wfsDataset[name];
                        if (wfsElement != null && wfsElement.Class is WFSFeatureClass)
                        {
                            wfsFc = wfsElement.Class as WFSFeatureClass;
                        }
                    }

                    if (styles.Count == 0)
                    {
                        IClass wClass = null;
                        if (wfsFc != null)
                        {
                            wClass = wfsFc;
                        }
                        else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1")
                        {
                            wClass = new WMSQueryableThemeClass(_dataset, name, String.Empty, layer, _getFeatureInfo, _srs, _exceptions);
                        }
                        else
                        {
                            wClass = new WMSThemeClass(_dataset, name, String.Empty, layer);
                        }

                        IWebServiceTheme theme;
                        if (wClass is WFSFeatureClass)
                        {
                            theme = new WebServiceTheme2(
                                wClass, Title, name, true, this);
                        }
                        else
                        {
                            theme = new WebServiceTheme(
                                wClass, Title, name, true, this
                                );
                        }

                        _themes.Add(theme);
                    }
                    else
                    {
                        foreach (XmlNode style in styles)
                        {
                            string  sName = "", sTitle = "";
                            XmlNode sNameNode  = style.SelectSingleNode("Name");
                            XmlNode sTitleNode = style.SelectSingleNode("Title");

                            if (sNameNode == null)
                            {
                                continue;
                            }
                            sName = sTitle = sNameNode.InnerText;
                            if (sTitleNode != null)
                            {
                                sTitle = sTitleNode.InnerText;
                            }

                            IClass wClass = null;
                            if (wfsFc is WFSFeatureClass)
                            {
                                wClass = wfsFc;
                                ((WFSFeatureClass)wClass).Style = sName;
                            }
                            else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1")
                            {
                                wClass = new WMSQueryableThemeClass(_dataset, name, sName, layer, _getFeatureInfo, _srs, _exceptions);
                            }
                            else
                            {
                                wClass = new WMSThemeClass(_dataset, name, sName, layer);
                            }

                            IWebServiceTheme theme;
                            if (wClass is WFSFeatureClass)
                            {
                                theme = new WebServiceTheme2(
                                    wClass, Title + " (Style=" + sTitle + ")", name, true, this);
                            }
                            else
                            {
                                theme = new WebServiceTheme(
                                    wClass, Title + " (Style=" + sTitle + ")", name, true, this
                                    );
                            }

                            _themes.Add(theme);
                        }
                    }
                }
                doc = null;
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message;
            }
        }
예제 #4
0
        async public Task <bool> Open(IServiceRequestContext context)
        {
            if (_class == null)
            {
                _class = new ArcIMSClass(this);
            }

            string server  = ConfigTextStream.ExtractValue(ConnectionString, "server");
            string service = ConfigTextStream.ExtractValue(ConnectionString, "service");
            string user    = ConfigTextStream.ExtractValue(ConnectionString, "user");
            string pwd     = ConfigTextStream.ExtractValue(ConnectionString, "pwd");

            //if ((user == "#" || user == "$") &&
            //        context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null)
            //{
            //    string roles = String.Empty;
            //    if (user == "#" && context.ServiceRequest.Identity.UserRoles != null)
            //    {
            //        foreach (string role in context.ServiceRequest.Identity.UserRoles)
            //        {
            //            if (String.IsNullOrEmpty(role)) continue;
            //            roles += "|" + role;
            //        }
            //    }
            //    user = context.ServiceRequest.Identity.UserName + roles;
            //    pwd = context.ServiceRequest.Identity.HashedPassword;
            //}

            dotNETConnector connector = new dotNETConnector();

            if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd))
            {
                connector.setAuthentification(user, pwd);
            }

            try
            {
                _themes.Clear();

                string axl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\"><REQUEST><GET_SERVICE_INFO fields=\"true\" envelope=\"true\" renderer=\"true\" extensions=\"true\" /></REQUEST></ARCXML>";
                //string axl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\"><REQUEST><GET_SERVICE_INFO dpi=\"96\" toc=\"true\" /></REQUEST></ARCXML>";

                await ArcIMSClass.LogAsync(context, "GetServiceInfo Response", server, service, axl);

                axl = connector.SendRequest(axl, server, service);
                await ArcIMSClass.LogAsync(context, "GetServiceInfo Response", server, service, axl);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(axl);

                double  dpi    = 96.0;
                XmlNode screen = doc.SelectSingleNode("//ENVIRONMENT/SCREEN");
                if (screen != null)
                {
                    if (screen.Attributes["dpi"] != null)
                    {
                        dpi = Convert.ToDouble(screen.Attributes["dpi"].Value.Replace(".", ","));
                    }
                }
                double dpm = (dpi / 0.0254);

                XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS");
                _sRef = ArcXMLGeometry.AXL2SpatialReference(FeatureCoordSysNode);

                foreach (XmlNode envelopeNode in doc.SelectNodes("//ENVELOPE"))
                {
                    if (_envelope == null)
                    {
                        _envelope = new Envelope(envelopeNode);
                    }
                    else
                    {
                        _envelope.Union(new Envelope(envelopeNode));
                    }
                }
                foreach (XmlNode layerNode in doc.SelectNodes("//LAYERINFO[@id]"))
                {
                    bool visible = true;

                    if (layerNode.Attributes["visible"] != null)
                    {
                        bool.TryParse(layerNode.Attributes["visible"].Value, out visible);
                    }

                    XmlNode tocNode = layerNode.SelectSingleNode("TOC");
                    if (tocNode != null)
                    {
                        ReadTocNode(tocNode);
                    }
                    IClass           themeClass = null;
                    IWebServiceTheme theme;
                    if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "featureclass")
                    {
                        themeClass = await ArcIMSThemeFeatureClass.CreateAsync(this, layerNode.Attributes["id"].Value);

                        ((ArcIMSThemeFeatureClass)themeClass).Name             = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value;
                        ((ArcIMSThemeFeatureClass)themeClass).fieldsFromAXL    = layerNode.InnerXml;
                        ((ArcIMSThemeFeatureClass)themeClass).SpatialReference = _sRef;

                        XmlNode FCLASS = layerNode.SelectSingleNode("FCLASS[@type]");
                        if (FCLASS != null)
                        {
                            ((ArcIMSThemeFeatureClass)themeClass).fClassTypeString = FCLASS.Attributes["type"].Value;
                        }
                        foreach (XmlNode child in layerNode.ChildNodes)
                        {
                            switch (child.Name)
                            {
                            case "SIMPLERENDERER":
                            case "SIMPLELABELRENDERER":
                            case "VALUEMAPRENDERER":
                            case "SCALEDEPENDENTRENDERER":
                            case "VALUEMAPLABELRENDERER":
                            case "GROUPRENDERER":
                                ((ArcIMSThemeFeatureClass)themeClass).OriginalRendererNode = child;
                                break;
                            }
                        }
                        theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme;
                        if (theme == null)
                        {
                            continue;
                        }
                        theme.Visible = visible;
                    }
                    else if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "image")
                    {
                        //themeClass = new ArcIMSThemeRasterClass(this,
                        //    layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value);
                        themeClass = new ArcIMSThemeRasterClass(this, layerNode.Attributes["id"].Value);
                        ((ArcIMSThemeRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value;

                        theme = new WebServiceTheme(
                            themeClass,
                            themeClass.Name,
                            layerNode.Attributes["id"].Value,
                            visible,
                            _class as IWebServiceClass);
                    }
                    else
                    {
                        continue;
                    }

                    try
                    {
                        if (layerNode.Attributes["minscale"] != null)
                        {
                            theme.MinimumScale = Convert.ToDouble(layerNode.Attributes["minscale"].Value.Replace(".", ",")) * dpm;
                        }
                        if (layerNode.Attributes["maxscale"] != null)
                        {
                            theme.MaximumScale = Convert.ToDouble(layerNode.Attributes["maxscale"].Value.Replace(".", ",")) * dpm;
                        }
                    }
                    catch { }
                    _themes.Add(theme);
                }
                _state = DatasetState.opened;

                ((ArcIMSClass)_class).SpatialReference = await this.GetSpatialReference();

                return(true);
            }
            catch (Exception ex)
            {
                _state  = DatasetState.unknown;
                _errMsg = ex.Message;
                await ArcIMSClass.ErrorLog(context, "Open Dataset", server, service, ex);

                return(false);
            }
        }