程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> ArcGis 9.2客戶端開發簡介(3)

ArcGis 9.2客戶端開發簡介(3)

編輯:.NET實例教程

 ArCGIs Server開發方式主要是利用本地的AO支持類庫對遠程MapServer進行連接,並通過取得的IMapServer遠程服務器接口取得上下文描述,調用遠程服務器上的AO控件來實現各種功能。因此本種開發模式需要有一台安裝有ArCGIs Server的服務器為開發提供MapServer支持。在ArCGIs Server上發布了相關的MapServer資源後,便可以對該MapServer資源服務進行開發。

       開發機上需要安裝Visual Studio 2005軟件開發平台。

       本種實現方式整體上與基於WebService方式有點類似,但是在接口實現上由於調用的AO接口不同,也會存在很大的差異,在下面實例中可以看到

環境需要

       ArCGIs Server開發方式主要是依靠服務器提供的MapServer服務來實現功能,因此需要有一台安裝有ArCGIs Server的服務器為開發提供支持。在ArCGIs Server上發布了相關的MapServer資源後,便可以對該WebService服務進行開發。

       開發機上需要安裝Visual Studio 2005軟件開發平台。

 

流程描述

       ArCGIs Server的基本開發方式是首先連接ArCGIs Server服務器上的某一個的MapServer服務。在找到服務並建立了連接以後,在取得這個MapServer的上下文描述。然後根據取得的上下文描述獲取到這個MapServerIMapServerAO接口。在獲取的ImaoServer接口的基礎上,利用上下文描述創建的多種接口,使用與WebService類似的實現方式,實現地圖操作和浏覽功能

      

開發步驟

打開VS2005,新建一個工程。工程名為:FzSecurityGisProxy

根據上面基於WebService例程建立類似的程序框架。

連接服務器

       在進行程序編寫的時候,首先需要建立與遠程MapServer的連接,代碼如下:

       public ESRI.ArCGIS.Carto.IMapServer getMapServer()

        {

            ServerConnection pServerConn = new ESRI.ArCGIS.Server.WebControls.ServerConnection("zhouj");//連接遠程服務器

            pServerConn.Connect();

            IServerObjectManager pSOM = pServerConn.ServerObjectManager;

            pSC = pSOM.CreateServerContext("fuzhou", "MapServer");//建立連接以後,根據本連接建立上下文描述

            IServerObject pSO = pSC.ServerObject;

            IMapServer pMapServer = (IMapServer)pSO;

            map = pMapServer;

            return pMapServer;

        }

取圖層

MapServerInfo則為取得的服務基本描述,在其中包含了大量的GISMap服務的基本信息。如果需要取得服務的圖層信息,取圖層有根據系統的需要基本有兩種方式。

1、讀取所有的圖層,並將其添加到相關的圖層顯示控件中。

public void AddLayToTree(TreeView m_TreeVIEw)

        {

            String m_sDataFrame = map.DefaultMapName;

            ESRI.ArCGIS.Carto.IMapDescription pMapDescription;

            ESRI.ArCGIS.Carto.IMapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

            pMapDescription = m_sMapDesc;

            int m = 0;

            m_TreeVIEw.Nodes.Clear();

            TreeNode[] m_tree;

            for (int n = 0; n < mapi.MapLayerInfos.Count; n++)

            {

                if (mapi.MapLayerInfos.get_Element(n).ParentLayerID == -1)

                {

                    m_TreeVIEw.Nodes.Add(mapi.MapLayerInfos.get_Element(n).ID.ToString(), mapi.MapLayerInfos.get_Element(n).Name);

                    m_TreeVIEw.Nodes[m].Checked = pMapDescription.LayerDescriptions.get_Element(n).Visible;

                    m = m + 1;

                }

                else

  {

                    if (mapi.MapLayerInfos.get_Element(n).Type == "Group Layer")

                    {

                        m_tree = m_TreeVIEw.Nodes.Find(mapi.MapLayerInfos.get_Element(n).ParentLayerID.ToString(), true);

                        m_tree[0].Nodes.Add(mapi.MapLayerInfos.get_Element(n).ID.ToString(), mapi.MapLayerInfos.get_Element(n).Name);

                        m_tree[0].Nodes[m_tree[0].Nodes.Count - 1].Checked = pMapDescription.LayerDescriptions.get_Element(n).Visible;

                    }

                    else

                    {

                        m_tree = m_TreeVIEw.Nodes.Find(mapi.MapLayerInfos.get_Element(n).ParentLayerID.ToString(), true);

                        m_tree[0].Nodes.Add(mapi.MapLayerInfos.get_Element(n).Name);

                        m_tree[0].Nodes[m_tree[0].Nodes.Count - 1].Checked = pMapDescription.LayerDescriptions.get_Element(n).Visible;

                    }

                }

            }

        }

       2、將某些特征圖層根據需要添加到某個控件中,本實例中是將Feature圖層添加到ComboBox控件中,並根據選擇能將圖層表中的各個字段添加到控件中:

       public void AddLayerToComb(ComboBox m_Comb)

        {

            String m_sDataFrame = map.DefaultMapName;

            ESRI.ArCGIS.Carto.IMapDescription pMapDescription;

            ESRI.ArCGIS.Carto.IMapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

    ;        pMapDescription = mapi.DefaultMapDescription;

            for (int n = 0; n < mapi.MapLayerInfos.Count; n++)

            {

                if (mapi.MapLayerInfos.get_Element(n).Type  == "Feature Layer")

                    m_Comb.Items.Add(mapi.MapLayerInfos.get_Element(n).Name);

            }

        }

 

     public void AddColumnToComb(String LayerName, ComboBox m_Comb)

        {

            String m_sDataFrame = map.DefaultMapName ;

 

            ESRI.ArCGIS.Carto.IMapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

            m_Comb.Items.Clear();

            m_Comb.Enabled = true;

            for (int i = 0; i < mapi.MapLayerInfos.Count ; i++)

            {

                if (mapi.MapLayerInfos.get_Element(i).Name == LayerName)

                {

                    IFields m_Fields = mapi.MapLayerInfos.get_Element(i).FIElds;

                    for (int j = 0; j < m_Fields.FIEldCount; j++)

                        m_Comb.Items.Add(m_Fields.get_FIEld(j).AliasName);

                }

            }

            m_Comb.SelectedIndex = 0;

        }

顯示圖形

       當需要顯示取得的圖像的時候,可以使用下面的函數

              public void drawMap(ref ESRI.ArCGIS.Carto.IMapDescriptio
n pMapDescriptoin, System.Windows.Forms.PictureBox m_PictureBox)

        {

            IImageType it = (IImageType)pSC.CreateObject("esriCarto.ImageType");

            it.Format = ESRI.ArCGIS.Carto.esriImageFormat.esriImageJPG;

            it.ReturnType = ESRI.ArCGIS.Carto.esriImageReturnType.esriImageReturnMimeData ;

            IImageDisplay idisp = (IImageDisplay)pSC.CreateObject("esriCarto.ImageDisplay");

            idisp.Height = m_PictureBox.Height;

            idisp.Width = m_PictureBox.Width;

            idisp.DeviceResolution = 150;

            IImageDescription pID = (IImageDescription)pSC.CreateObject("esriCarto.ImageDescription");

            pID.Display = idisp;

            pID.Type = it;

            IMapImage pMI = map.ExportMapImage(pMapDescriptoin, pID);

            System.IO.Stream pStream = new System.IO.MemoryStream((byte[])pMI.MimeData);

            pImage = Image.FromStream(pStream);

            m_PictureBox.Image = pImage;

            mapScale = pMI.MapScale;

            m_PictureBox.Refresh();

            return;

        }

編程實現

放大

       以下例程將實現對圖片的放大操作

              public void ZoomIn(PictureBox m_PictureBox)

        {

            ESRI.ArCGIS.Carto.IMapDescription pMapDescription = m_sMapDesc;           

            IEnvelope pEnvelope = pMapDescription.MapArea.Extent ;

            double eWidth = Math.Abs(pEnvelope.XMax - pEnvelope.XMin);

>

            double eHeight = Math.Abs(pEnvelope.YMax - pEnvelope.YMin);

            double xFactor = (eWidth - (eWidth * 0.5)) / 2;

            double yFactor = (eHeight - (eHeight * 0.5)) / 2;

            pEnvelope.XMax = pEnvelope.XMax - xFactor;

            pEnvelope.XMin = pEnvelope.XMin + xFactor;

            pEnvelope.YMax = pEnvelope.YMax - yFactor;

            pEnvelope.YMin = pEnvelope.YMin + yFactor;           

            IMapArea ma = pMapDescription.MapArea;

            IMapExtent pMapExtent = ma as IMapExtent;

            pMapExtent.Extent = pEnvelope;

            pMapDescription.MapArea = ma;

            m_sMapDesc = pMapDescription;

            drawMap(ref pMapDescription, m_PictureBox);

        }

放大操作的基本原理是取得當前的地圖描述MapDescription,然後按照比例計算出放大或縮小的比例。在得出按照比例計算出來的周邊坐標,然後將其提交服務器,取得圖形進行顯示。

實例圖形:

      

縮小

       public void ZoomOut(PictureBox m_PictureBox)

        {

            ESRI.ArCGIS.Carto.IMapDescription pMapDescription = m_sMapDesc;

            IEnvelope pEnvelope = pMapDescription.MapArea.Extent;

            double eWidth = Math.Abs(pEnvelope.XMax - pEnvelope.XMin);

            double eHeight = Math.Abs(pEnvelope.YMax - pEnvelope.YMin);

            double xFactor = (eWidth - (eWidth * 1.5)) / 2;

            double yFactor = (eHeight - (eHeight * 1.5)) / 2;


;     pEnvelope.XMax = pEnvelope.XMax - xFactor;

            pEnvelope.XMin = pEnvelope.XMin + xFactor;

            pEnvelope.YMax = pEnvelope.YMax - yFactor;

            pEnvelope.YMin = pEnvelope.YMin + yFactor;

            IMapArea ma = pMapDescription.MapArea;

            IMapExtent pMapExtent = ma as IMapExtent;

            pMapExtent.Extent = pEnvelope;

            pMapDescription.MapArea = ma;

            m_sMapDesc = pMapDescription;

            drawMap(ref pMapDescription, m_PictureBox);

        }

放大操作的基本原理是取得當前的地圖描述MapDescription,然後按照比例計算出放大或縮小的比例。在得出按照比例計算出來的周邊坐標,然後將其提交服務器,取得圖形進行顯示。 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved