ArcEngine加載SDE中的柵格數據的問題

在加載矢量數據時直接轉到IFeatureWorkspace接口便可,可是在加載柵格數據時要轉到IRasterWorkspaceEx接口。效果圖以下,雙擊便可添加到Globe中。函數


代碼以下:this

   public partial class SDEDataViewer : DevComponents.DotNetBar.Office2007Form
    {
        #region 私有變量
        private IWorkspace sdeWorkSpace; //sde工做控件
        private IGlobeControl globecontrol;
      
        private string selectedVectorName;//待添加矢量
        private string selectedRasterName;
        #endregion

        #region 構造函數
        public SDEDataViewer(IGlobeControl m_globecontrol , IWorkspace workspace)
        {
            this.sdeWorkSpace = workspace;
            this.globecontrol = m_globecontrol;
            InitializeComponent();
        }
        #endregion

        #region load

        private void SDEDataViewer_Load(object sender , EventArgs e)
        {
            IAoInitialize initAO = new AoInitializeClass();
            initAO.Initialize((esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB));
            loadData();
        }
        //獲取全部數據
        private void loadData()
        {
            listView_vector.GridLines = true;//表格是否顯示網格線
            listView_vector.FullRowSelect = true;//是否選中整行
            listView_vector.View = View.Details;//設置顯示方式
            listView_vector.Scrollable = true;//是否自動顯示滾動條
            listView_vector.MultiSelect = false;//是否能夠選擇多行

            listView_raster.GridLines = true;
            listView_raster.FullRowSelect = true;
            listView_raster.View = View.Details;
            listView_raster.Scrollable = true;
            listView_raster.MultiSelect = false;


            //添加表頭(列)
            listView_vector.Columns.Add("要素名稱" , 150 , HorizontalAlignment.Center);
            listView_vector.Columns.Add("要素類型" , 100 , HorizontalAlignment.Center);
            listView_raster.Columns.Add("數據名稱" , 150 , HorizontalAlignment.Center);
            listView_raster.Columns.Add("數據類型" , 100 , HorizontalAlignment.Center);

          
            try
            {
                IEnumDataset enumDataset = sdeWorkSpace.get_Datasets(esriDatasetType.esriDTAny);
                IDataset dataset = null;
                while ((dataset = enumDataset.Next()) != null)
                {
                    if (dataset.Type == esriDatasetType.esriDTFeatureClass)
                    {
                        ListViewItem item = new ListViewItem();
                        item.SubItems.Clear();
                        item.SubItems[0].Text = dataset.Name;
                        string strFeatureType = GetFeatureType(dataset.Name);
                        item.SubItems.Add(strFeatureType);
                        listView_vector.Items.Add(item);
                    }
                    else if (dataset.Type == esriDatasetType.esriDTRasterDataset)
                    {
                        ListViewItem item = new ListViewItem();
                        item.SubItems.Clear();
                        item.SubItems[0].Text = dataset.Name;
                        item.SubItems.Add("柵格數據集");
                        listView_raster.Items.Add(item);

                    }
                    
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //獲取要素類型
        private string GetFeatureType(string pDataSetName)
        {
            string featureType = "";
            IFeatureWorkspace pFeatureWS = sdeWorkSpace as IFeatureWorkspace;
            IFeatureClass featureClass = pFeatureWS.OpenFeatureClass(pDataSetName);

            switch (featureClass.ShapeType)
            {

                case esriGeometryType.esriGeometryPoint:
                    featureType = "點要素";
                    break;
                case esriGeometryType.esriGeometryPolyline:
                    featureType = "線要素";
                    break;
                case esriGeometryType.esriGeometryPolygon:
                    featureType = "面要素";
                    break;
                default:
                    break;
            }
            // System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureWS);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
            return featureType;
        }

        #endregion

        #region 添加數據
      
        //添加矢量
        private void listView_vector_MouseDoubleClick(object sender , MouseEventArgs e)
        {
            
            IFeatureClass featureClass = (sdeWorkSpace as IFeatureWorkspace).OpenFeatureClass(selectedVectorName);
            IFeatureLayer featureLayer = new FeatureLayerClass()
            {
                FeatureClass = featureClass ,
                Name = featureClass.AliasName
            };
            VectorHelper_FeatureOpt VectorAdderHelper = new VectorHelper_FeatureOpt(globecontrol , featureLayer);
            VectorAdderHelper.ShowDialog();
            this.Close();

            //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
            //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureLayer);
            
        }

        //添加柵格
        private void listView_raster_MouseDoubleClick(object sender , MouseEventArgs e)
        {

            IRasterWorkspaceEx rasterWSEx = sdeWorkSpace as IRasterWorkspaceEx;
            IRasterDataset rasterDataset = rasterWSEx.OpenRasterDataset(selectedRasterName);
            IRasterLayer rasterLayer = new RasterLayerClass();
            rasterLayer.CreateFromDataset(rasterDataset);

            RasterHelper_LayerType rasterAdderHelper = new RasterHelper_LayerType(globecontrol , rasterLayer);
            rasterAdderHelper.ShowDialog();
            this.Close();



            //System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterLayer);
           
        }

        //obtain selected vector
        private void listView_vector_SelectedIndexChanged(object sender , EventArgs e)
        {
            ListViewItem item = new ListViewItem();
            item = listView_vector.SelectedItems[0];
            string featureClassName_temp = item.SubItems[0].ToString();
            int lastIndex_left = featureClassName_temp.LastIndexOf("{");
            int lastIndex_right = featureClassName_temp.LastIndexOf("}");
            selectedVectorName = featureClassName_temp.Substring(lastIndex_left + 1 , lastIndex_right - lastIndex_left - 1);

        }
        //obtain selected raster
        private void listView_raster_SelectedIndexChanged(object sender , EventArgs e)
        {
            ListViewItem item = new ListViewItem();
            item = listView_raster.SelectedItems[0];
            string rasterName_temp = item.SubItems[0].ToString();
            int lastIndex_left = rasterName_temp.LastIndexOf("{");
            int lastIndex_right = rasterName_temp.LastIndexOf("}");
            selectedRasterName = rasterName_temp.Substring(lastIndex_left + 1 , lastIndex_right - lastIndex_left - 1);

        }
        #endregion

    }
歡迎留言交流。
相關文章
相關標籤/搜索