コード例 #1
0
ファイル: Utils.cs プロジェクト: Geoneer/pdok-extensie
        /// <summary>
        /// Get folder path for CSW dll related folder, such as the data folder, transformation file folder, etc.
        /// </summary>
        /// <param name="folderName">enumeration of the CSW special folder</param>
        /// <returns>full path to the special folder</returns>
        public static string GetSpecialFolderPath(pdok4arcgis.SpecialFolder folder)
        {
            string folderPath = "";
            string configFileDir = null;
            RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\PDOK\\Applications\\PDOK4ArcGIS");
            if (regKey != null) configFileDir = (String)regKey.GetValue("ConfigFileDir");
            if (configFileDir == null) configFileDir = ExecutingAssemblyPath();

            switch (folder)
            {
                case SpecialFolder.ConfigurationFiles:

                    try
                    {
                        System.IO.StreamReader fStream = System.IO.File.OpenText(configFileDir + "\\CswConfigPath.properties");
                        folderPath = fStream.ReadLine();
                    }
                    catch (Exception e)
                    {
                        // throw e;
                    }
                    if (string.IsNullOrEmpty(folderPath)) folderPath = System.IO.Path.Combine(ExecutingAssemblyPath(), "Data");
                    //folderPath = GetSpecialFolderPath(Environment.SpecialFolder.ProgramFiles);
                    //folderPath = System.IO.Path.Combine(folderPath, "ESRI\\Portal\\CswClients\\Data");
                    break;
                case SpecialFolder.LogFiles:

                    try
                    {
                        System.IO.StreamReader fStream = System.IO.File.OpenText(configFileDir + "\\CswConfigPath.properties");
                        fStream.ReadLine();
                        if (fStream != null)
                        {
                            String debugFlag = fStream.ReadLine();
                            if (debugFlag != null && debugFlag.Trim().Equals("debug=on", StringComparison.CurrentCultureIgnoreCase))
                            {
                                folderPath = (String)regKey.GetValue("LogDir");
                            }

                        }
                    }
                    catch (Exception e)
                    {
                        // throw e;
                    }
                    break;
                case SpecialFolder.TransformationFiles:
                    // "Documents And Settings\<user>\Application Data\ESRI\PortalFindServices"
                    folderPath = GetSpecialFolderPath(Environment.SpecialFolder.ApplicationData);
                    folderPath = System.IO.Path.Combine(folderPath, "ESRI");
                    break;
                case SpecialFolder.Data:
                    folderPath = System.IO.Path.Combine(ExecutingAssemblyPath(), "Data");
                    break;
                case SpecialFolder.Help:
                    folderPath = System.IO.Path.Combine(ExecutingAssemblyPath(), "Help");
                    break;
                case SpecialFolder.ExecutingAssembly:
                    folderPath = ExecutingAssemblyPath();
                    break;
                case SpecialFolder.Application:
                    folderPath = System.Windows.Forms.Application.ExecutablePath;
                    break;
                case SpecialFolder.Temp:
                    // Returns the path of the current system's temporary folder
                    folderPath = System.IO.Path.GetTempPath();
                    break;
            }

            return folderPath;
        }
コード例 #2
0
ファイル: CswSearch.cs プロジェクト: Geoneer/pdok-extensie
        /// <summary>
        /// Add WMS map service layer to map
        /// </summary>
        /// <param name="msi">Map service information</param>
        private void AddLayerWMS(pdok4arcgis.MapServiceInfo msi, Boolean fromServerUrl, string sld)
        {
            if (msi == null) { throw new ArgumentNullException(); }

            try
            {
                string url = AppendQuestionOrAmpersandToUrlString(msi.Server);
                // append serviceParam to server url
                // todo: does msi.ServiceParam have a leading "?" or "&"?
                if (msi.ServiceParam.Length > 0 && !fromServerUrl)
                {
                    url = url + msi.ServiceParam;
                    url = AppendQuestionOrAmpersandToUrlString(url);
                }
                if (!String.IsNullOrEmpty(sld))
                {
                    url = String.Format("{0}SLD={1}&", url, sld);
                }
                IPropertySet propertySet = new PropertySetClass();
                propertySet.SetProperty("URL", url);

                IMxDocument mxDoc = (IMxDocument)m_application.Document;
                IMap map = (IMap)mxDoc.FocusMap;
                IActiveView activeView = (IActiveView)map;
                IWMSGroupLayer wmsGroupLayer = (IWMSGroupLayer)new WMSMapLayerClass();
                IWMSConnectionName wmsConnectionName = new WMSConnectionName();
                wmsConnectionName.ConnectionProperties = propertySet;

                // connect to wms service
                IDataLayer dataLayer;
                bool connected = false;
                try
                {
                    dataLayer = (IDataLayer)wmsGroupLayer;
                    IName connName = (IName)wmsConnectionName;
                    connected = dataLayer.Connect(connName);
                }
                catch (Exception ex) 
                {
                    ShowErrorMessageBox(StringResources.ConnectToMapServiceFailed + "\r\n" + "url:" + url +"\r\n" + ex.Message);
                    connected = false;
                }
                if (!connected) return;

                ILayer layer = (ILayer)wmsGroupLayer;
                if (wmsGroupLayer.Count == 0)
                { // Old code that was present for 9.3 but causes issues for 10.1, as the layers have already been added at this point. The documentation for IWMSMapLayer still states that this is necessary to get the layers (but the behaviour changed , probably in ArcGIS 10.0)
                    // get service description out of the layer. the service description contains 
                    // inforamtion about the wms categories and layers supported by the service
                    IWMSServiceDescription wmsServiceDesc = wmsGroupLayer.WMSServiceDescription;
                    IWMSLayerDescription wmsLayerDesc;
                    ILayer newLayer;
                    IWMSLayer newWmsLayer;
                    IWMSGroupLayer newWmsGroupLayer;
                    for (int i = 0; i < wmsServiceDesc.LayerDescriptionCount; i++)
                    {
                        newLayer = null;

                        wmsLayerDesc = wmsServiceDesc.get_LayerDescription(i);
                        if (wmsLayerDesc.LayerDescriptionCount == 0)
                        {
                            // wms layer
                            newWmsLayer = wmsGroupLayer.CreateWMSLayer(wmsLayerDesc);
                            newLayer = (ILayer)newWmsLayer;
                            if (newLayer == null) { throw new Exception(StringResources.CreateWmsLayerFailed); };
                        }
                        else
                        {
                            // wms group layer
                            newWmsGroupLayer = wmsGroupLayer.CreateWMSGroupLayers(wmsLayerDesc);
                            newLayer = (ILayer)newWmsGroupLayer;
                            if (newLayer == null) { throw new Exception(StringResources.CreateWmsGroupLayerFailed); }
                        }

                        // add newly created layer
                        wmsGroupLayer.InsertLayer(newLayer, 0);
                    }

                    // configure the layer before adding it to the map
                    layer.Name = wmsServiceDesc.WMSTitle;
                }
                ExpandLayer(layer, true);
                SetLayerVisibility(layer, true);

                // add to focus map
                map.AddLayer(layer);

                return;
            }
            catch (Exception ex)
            {
                ShowErrorMessageBox (StringResources.AddWmsLayerFailed + "\r\n" + ex.Message);
            }
        }
コード例 #3
0
ファイル: CswSearch.cs プロジェクト: Geoneer/pdok-extensie
        /// <summary>
        /// Add ArcIMS map service layer to map
        /// </summary>
        /// <param name="msi">Map service information</param>
        private void AddLayerArcIMS(pdok4arcgis.MapServiceInfo msi)
        {
            if (msi == null) { throw new ArgumentNullException(); }
            try
            {
                IMxDocument mxDoc = (IMxDocument)m_application.Document;
                IMap map = (IMap)mxDoc.FocusMap;
                IActiveView activeView = (IActiveView)map;

                bool isAlreadyInMap = false;
            /*    for (int i = 0; i < map.LayerCount; i++)
                {
                    // note: minimum checking. to make sure only unique services are added.
                    if (msi.Service.Equals(map.get_Layer(i).Name, StringComparison.OrdinalIgnoreCase))
                    {
                        isAlreadyInMap = true;
                        break;
                    }
                }*/

                if (isAlreadyInMap)
                {
                    ShowErrorMessageBox (StringResources.MapServiceLayerAlreadyExistInMap);
                    return;
                }
                else
                {
                    //IIMSConnection imsConnection;
                    IIMSMapLayer imsMapLayer;
                    
                    // create service description based on provided map service info
                    IIMSServiceDescription imsServiceDesc = new IMSServiceNameClass();
                    imsServiceDesc.URL = msi.Server;
                    imsServiceDesc.Name = msi.Service;
                    imsServiceDesc.ServiceType = acServiceType.acMapService;
                    // note: add as image map service
                    // todo: research on the relationship between MapServiceInfo.ServiceType and IIMSServiceDescription
                    #region acServiceType info
                    /*
                acMapService 0 An image map service. 
                acFeatureService 1 A feature stream service. 
                acMetadataService 2 A metadata service. 
                acGlobeService 3 A globe service. 
                acWMSService 4 A WMS service. 
                acUnknownService 5 An unknown service. 
                */
                    #endregion

                    // connect to service
                    try
                    {
                        imsMapLayer = new IMSMapLayerClass();
                        imsMapLayer.ConnectToService(imsServiceDesc);
                    }
                    catch (System.Runtime.InteropServices.COMException ex)
                    {
                        // note: when a site request usr/pwd to connect, user may choose "cancel". Then, imsMapLayer.ConnectToService() 
                        //       would then throw an System.Runtime.InteropServices.COMException. Catch it but no need to display 
                        //       any error message.
                        System.Diagnostics.Trace.WriteLine(ex.Message, "NoConnectionToService");
                        return;
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessageBox(StringResources.ConnectToMapServiceFailed + "\r\n" + ex.Message);
                        return;
                    }

                    ILayer layer = (ILayer)imsMapLayer;
                    ExpandLayer(layer, true);
                    SetLayerVisibility(layer, true);

                    // Add the layer
                    mxDoc.AddLayer(imsMapLayer);

                }
            }
            catch (Exception ex)
            {
                ShowErrorMessageBox(StringResources.AddArcimsLayerFailed + "\r\n" + ex.Message);
            }
        }
コード例 #4
0
ファイル: CswSearch.cs プロジェクト: Geoneer/pdok-extensie
        /// <summary>
        /// Add WCS map service layer to map
        /// </summary>
        /// <param name="msi">Map service information</param>
        private void AddLayerWCS(pdok4arcgis.MapServiceInfo msi, Boolean fromServerUrl)
        {
            if (msi == null) { throw new ArgumentNullException(); }

            try
            {
                string _mapServerUrl = AppendQuestionOrAmpersandToUrlString(msi.Server);
                // append serviceParam to server url
                // todo: does msi.ServiceParam have a leading "?" or "&"?
                if (msi.ServiceParam.Length > 0 && !fromServerUrl)
                {
                    _mapServerUrl = _mapServerUrl + msi.ServiceParam;
                    _mapServerUrl = AppendQuestionOrAmpersandToUrlString(_mapServerUrl);
                }

                /*
                IPropertySet propertySet = new PropertySetClass();
                propertySet.SetProperty("URL", url);

                IMxDocument mxDoc = (IMxDocument)m_application.Document;
                IMap map = (IMap)mxDoc.FocusMap;
                IActiveView activeView = (IActiveView)map;

                IWCSLayer wcsLayer = new WCSLayerClass();
                

       //         IWCSCoverageDescription
         //       IWCSGroupLayer wcsGroupLayer = (IWCSGroupLayer)new WCSMapLayerClass();

                IWCSConnectionName wcsConnectionName = new WCSConnectionName();
                wcsConnectionName.ConnectionProperties = propertySet;

                // connect to wms service
                IDataLayer dataLayer;
                bool connected = false;
                try
                {
                    dataLayer = (IDataLayer) wcsLayer;
                    IName connName = (IName) wcsConnectionName;
                    connected = dataLayer.Connect(connName);
                }
                catch (Exception ex)
                {
                    ShowErrorMessageBox(StringResources.ConnectToMapServiceFailed + "\r\n" + ex.Message);
                    connected = false;
                }
                if (!connected) return;


                // get service description out of the layer. the service description contains 
                // information about the wms categories and layers supported by the service
             //   IWCSServiceDescription wcsServiceDesc = wcsLayer.WMSServiceDescription;

                IWCSCoverageDescription wcsCoverageDesc;
                ILayer newLayer;
                ILayer layer;
                IWCSLayer newWcsLayer;
         //     IWCSGroupLayer newWmsGroupLayer;          
            
                // add to focus map
             //   map.AddLayer(layer);

                return;*/

                 // MapServiceInfo msi = new MapServiceInfo();
                        String[] s = _mapServerUrl.Trim().Split('?');

                        _mapServerUrl = s[0] + "?request=GetCapabilities&service=WCS";
                        CswClient client = new CswClient();
                        String response = client.SubmitHttpRequest("GET", _mapServerUrl, "");

                         XmlDocument xmlDocument = new XmlDocument();
                         try { xmlDocument.LoadXml(response); }
                         catch (XmlException xmlEx)
                         { }

                         XmlNodeList contentMetadata = xmlDocument.GetElementsByTagName("ContentMetadata");

                         if (contentMetadata != null && contentMetadata.Count > 0)
                         {
                             XmlNodeList coverageList = contentMetadata.Item(0).ChildNodes;

                             foreach (XmlNode coverage in coverageList) {
                                  
                                 XmlNodeList nodes = coverage.ChildNodes;

                                 foreach(XmlNode node in nodes)
                                 {
                                     if (node.Name.ToLower().Equals("name"))
                                     {
                                         _mapServerUrl = s[0] + "?request=GetCoverage&service=WCS&format=GeoTIFF&coverage=" + node.InnerText;

                                         try{
                                            String filePath  = client.SubmitHttpRequest("DOWNLOAD", _mapServerUrl, "");
                                            AddAGSService(filePath);

                                         } catch(Exception e){
                                             ShowErrorMessageBox("WCS service with no GeoTiff interface");
                                             return;
                                         }                                
                                     }
                                 }

                             }

                         }                                            

                        //msi.Server = s[0];
                       // AddLayerWCS(msi, true);
                    }
            
            catch (Exception ex)
            {
              //  ShowErrorMessageBox(StringResources.AddWcsLayerFailed + "\r\n" + ex.Message);
            }
        }