美文网首页
feature创建gdb并进行修改

feature创建gdb并进行修改

作者: 一位热爱文学的程序员 | 来源:发表于2019-09-30 09:46 被阅读0次

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using DevComponents.DotNetBar;

using Uninpho.SXDBGIS.Project.DataDeal;

using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Geometry;

using System.Linq;

namespace Uninpho.SXDBGIS.Project.DataCheck

{

    public partial class GDBDataShow : UIDialog

    {

        public IWorkspace GDBWorkspace;

        private string DS_Name = null;

        private string[] fc_name;

        IDataset SubmyDS;

        private List<System.Object> GDBClassList = new List<System.Object>();

        private string ListBoxName;

        private string ParamerNumber;

        public static event Action<string> ParamerEvent;

        public static event Action GDBRemoveEvent;

        public GDBDataShow()

        {

            InitializeComponent();

        }

        private void GDBDataShow_Load(object sender, EventArgs e)

        {

            IFeatureClassContainer myFCContainer = get_FCName(GDBWorkspace);

            string[] myFCName;

            myFCName = get_FCName2(GDBWorkspace);

            if (myFCContainer.ClassCount != 0 && myFCName != null)

            {

                int j = 0;

                if (myFCContainer.ClassCount != 0)

                {

                    while (j < myFCContainer.ClassCount)

                    {

                        this.listBoxAdv1.Items.Add(myFCName[j]);

                        j++;

                    }

                }

                else

                {

                    MessageBox.Show("There is no FeatureClass in your DataSet!");

                    return;

                }

            }

        }

        //返回用于访问要素类成员名称ID的访问权限

        public IFeatureClassContainer get_FCName(IWorkspace myWSp)

        {

            //获取esriDTFeatureDataset类型数据集里面的成员

            IEnumDataset myEDS = myWSp.get_Datasets(esriDatasetType.esriDTFeatureDataset);

            IDataset myDS = myEDS.Next();

            //IFeatureWorkspace myFWSp = myWSp as IFeatureWorkspace;

            if (myDS != null)

            {

                IFeatureDataset myFDS = myDS as IFeatureDataset;

                IFeatureClassContainer myFCContainer = myFDS as IFeatureClassContainer;

                return myFCContainer;

            }

            else

                return null;

        }

        //返回DS中的要素名供用户选择

        public string[] get_FCName2(IWorkspace myWorkSpace)

        {

            GDBRemoveEvent();

            string[] mystr;

            StringBuilder mySb = new StringBuilder();

            IEnumDataset myEDS = myWorkSpace.get_Datasets(esriDatasetType.esriDTAny);

            IDataset myDS = myEDS.Next();

            DS_Name = myDS.Name;

            while (myDS != null)

            {

                //如果是要素类直接获取其name

                if (myDS.Type == esriDatasetType.esriDTFeatureClass)

                {

                    Classification(myDS);

                    mySb.Append(myDS.Name + ',');

                    myDS = myEDS.Next();

                }

                //如果是特征数据集就直接再往下挖一个子集,然后再进行遍历(subsets)

                else if (myDS.Type == esriDatasetType.esriDTFeatureDataset)

                {

                    IEnumDataset SubmyEDS = myDS.Subsets;

                    SubmyDS = SubmyEDS.Next();

                    while (SubmyDS != null)

                    {

                        Classification(SubmyDS);

                        mySb.Append(SubmyDS.Name + ',');

                        SubmyDS = SubmyEDS.Next();

                    }

                    myDS = SubmyDS;

                }

                else

                {

                    MessageBox.Show("Error,there is no standar FCDS in your GeoDB!");

                    break;

                }

            }

            string tempstr = mySb.ToString().Remove(mySb.ToString().Length - 1);

            int count = mySb.ToString().Length;

            mystr = tempstr.Split(',');

            fc_name = mystr;

            return mystr;

        }

        public void Classification(IDataset SubmyDS)

        {

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = SubmyDS as IFeatureClass;

            if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)

            {

                string Name = SubmyDS.Name;

                bool[] CanableCheck = new bool[] { false, false, false, false, false, true, false, false, true };

                var ClassObject = new { CanableCheck = CanableCheck, SubmyDS = SubmyDS, Name = Name };

                GDBClassList.Add(ClassObject);

            }

            else if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)

            {

                string Name = SubmyDS.Name;

                //classificationline = new ClassificationLine(SubmyDS);

                bool[] CanableCheck = new bool[] { true, true, false, false, true, false, false, true, true };

                //classificationline.CanableCheck = CanableCheck;

                var ClassObject = new { CanableCheck = CanableCheck, SubmyDS = SubmyDS, Name = Name };

                GDBClassList.Add(ClassObject);

            }

            else if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)

            {

                string Name = SubmyDS.Name;

                //classificationpolygon = new ClassificationPolygon(SubmyDS);

                bool[] CanableCheck = new bool[] { false, false, true, true, false, false, true, false, true };

                //classificationpolygon.CanableCheck = CanableCheck;

                var ClassObject = new { CanableCheck = CanableCheck, SubmyDS = SubmyDS, Name = Name };

                GDBClassList.Add(ClassObject);

            }

        }

        private void listBoxAdv1_ItemClick(object sender, EventArgs e)

        {

        ListBoxName = (string)listBoxAdv1.SelectedItem;

        //ListBoxName = (string)GetPropertyValue(ListBoxObject, "Text");

        IEnumDataset myEDS = GDBWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);

        IDataset myDS = myEDS.Next();

        if (myDS != null)

        {

            IFeatureDataset myFDS = myDS as IFeatureDataset;

            //要素类容器

            ITopologyContainer myTopologyContainer = myFDS as ITopologyContainer;

            ParamerNumber = myTopologyContainer.DefaultClusterTolerance.ToString();

        }

        }

        /// <summary>

        /// 获取属性值

        /// </summary>

        /// <param name="info"></param>

        /// <param name="field"></param>

        /// <returns></returns>

        private static object GetPropertyValue(object info, string field)

        {

            if (info == null) return null;

            Type t = info.GetType();

            IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;

            return property.First().GetValue(info, null);

        }

        private void buttonX1_Click(object sender, EventArgs e)

        {

            TopologyCheck.ClassList = GDBClassList;

            TopologyCheck.ListBoxSelectName = ListBoxName;

            ParamerEvent(ParamerNumber);

            this.Hide();

        }

        private void buttonX2_Click(object sender, EventArgs e)

        {

            this.Hide();

        }

    }

}

相关文章

网友评论

      本文标题:feature创建gdb并进行修改

      本文链接:https://www.haomeiwen.com/subject/wzkdyctx.html