首页 > 其他 > 详细

ArcEngine加载SDE中的栅格数据的问题

时间:2014-05-07 07:53:27      阅读:588      评论:0      收藏:0      [点我收藏+]

在加载矢量数据时直接转到IFeatureWorkspace接口即可,但是在加载栅格数据时要转到IRasterWorkspaceEx接口。效果图如下,双击即可添加到Globe中。

bubuko.com,布布扣

代码如下:

   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

    }
欢迎留言交流。

ArcEngine加载SDE中的栅格数据的问题,布布扣,bubuko.com

ArcEngine加载SDE中的栅格数据的问题

原文:http://blog.csdn.net/giser_whu/article/details/25083135

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!