zoukankan      html  css  js  c++  java
  • ArcEngine载入中SDE问题栅格数据

    当直接加载矢量数据到IFeatureWorkspace接口可,但是,在装载门格当要传送的数据IRasterWorkspaceEx接口。

    效果如下面的,对可以被添加到双击Globe在。


    代码例如以下:

       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
    
        }
    欢迎留言交流。

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    WebApi 接口参数不再困惑:传参详解
    文件 jq 传到后台
    【XML】-- C#读取XML中元素和属性的值
    【jQuery】jquery.metadata.js验证失效
    jQuery插件 -- 表单验证插件jquery.validate.js
    c#批量上传图片到服务器示例分享
    程序如何实现设置系统WIFI共享
    百度编辑器ueditor插入表格没有边框,没有颜色的解决方法
    百度UEditor粘贴或插入的表格不显示边框的解决办法
    AttributeError at /home/home/ Exception Type: AttributeError at /home/home/
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4672328.html
Copyright © 2011-2022 走看看