private bool getElevationTableAndField(ref Dictionary <int, string> FeatureLayerIDAndFieldNamesList, ref List <string> ElevationLayerNames)
        {
            IMap map = ArcMap.Document.FocusMap;
            // get the elevation layers in the focus map
            int        iLayerPos  = 0; //relying on layer index
            IEnumLayer enumLayers = map.get_Layers(null, true);
            ILayer     pLayer     = enumLayers.Next();

            while (pLayer != null)
            {
                iLayerPos++;//use the TOC index
                if (pLayer is ICadastralFabricSubLayer2)
                {
                    pLayer = enumLayers.Next();
                    continue;
                }
                if (!(pLayer is IFeatureLayer))
                {//filter for feature layers only
                    pLayer = enumLayers.Next();
                    continue;
                }

                ILayerFields pLyrFlds = pLayer as ILayerFields;
                for (int i = 0; i < pLyrFlds.FieldCount; i++)
                {
                    if (pLyrFlds.get_Field(i).Type == esriFieldType.esriFieldTypeDouble)
                    {
                        IFieldInfo pFldInfo = pLyrFlds.get_FieldInfo(i);
                        if (!pFldInfo.Visible)
                        {
                            continue;
                        }

                        string sFieldName = pLyrFlds.get_Field(i).Name;
                        if (sFieldName.ToLower().Contains("elevation") || sFieldName.ToLower() == ("z") || sFieldName.ToLower().Contains("height"))
                        {
                            if (!FeatureLayerIDAndFieldNamesList.ContainsKey(iLayerPos))
                            {
                                FeatureLayerIDAndFieldNamesList.Add(iLayerPos, sFieldName);
                                ElevationLayerNames.Add(pLayer.Name);
                            }
                            else
                            {
                                FeatureLayerIDAndFieldNamesList[iLayerPos] += "," + sFieldName;
                            }
                        }
                    }
                }
                pLayer = enumLayers.Next();
            }
            return(false);
        }
Esempio n. 2
0
        private void InitDataLayer()
        {
            IFeatureLayer featureLayer = GetFeatLayerByName(comboBoxLayer.Text);
            //Query inteface for ILayerFields
            ILayerFields layerFields = (ILayerFields)featureLayer;

            int j = 0;

            comboBoxField.Items.Clear();
            comboBoxField.Enabled = true;
            //Loop through the fields
            for (int i = 0; i <= layerFields.FieldCount - 1; i++)
            {
                //Get IField interface
                IField field = layerFields.get_Field(i);
                //If the field is not the shape field
                if (field.Type != esriFieldType.esriFieldTypeGeometry)
                {
                    //Add field name to the control
                    comboBoxField.Items.Insert(j, field.Name);
                    //If the field name is the display field
                    if (field.Name == featureLayer.DisplayField)
                    {
                        //Select the field name in the control
                        comboBoxField.SelectedIndex = j;
                    }
                    j = j + 1;
                }
            }
        }
        private void FrmSelectField_Load(object sender, EventArgs e)
        {
            cbField.Items.Clear();
            if (m_pFeatureLayer == null || m_pFeatureLayer.FeatureClass == null)
            {
                return;
            }
            IFeatureClass pFeatureClass = m_pFeatureLayer.FeatureClass;

            ILayerFields pLayerFields = m_pFeatureLayer as ILayerFields;

            for (int k = 0; k < pLayerFields.FieldCount; k++)
            {
                IField pField     = pLayerFields.get_Field(k);
                string sFieldName = pField.Name;
                if (sFieldName.Equals("FID", StringComparison.OrdinalIgnoreCase) || sFieldName.Equals("OBJECTID", StringComparison.OrdinalIgnoreCase) ||
                    sFieldName.Equals("SHAPE", StringComparison.OrdinalIgnoreCase) || sFieldName.Equals("SHAPE_Length", StringComparison.OrdinalIgnoreCase) ||
                    sFieldName.Equals("SHAPE_Area", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                cbField.Items.Add(pField.Name);
            }
            if (cbField.Items.Count > 0)
            {
                cbField.SelectedIndex = 0;
            }
            cbField.SelectedIndex = cbField.FindString(m_strDefFieldName);
            if (cbField.SelectedIndex != -1)
            {
                cbField.SelectedIndex = 0;
            }
        }
Esempio n. 4
0
        public void AddItems(IFeatureLayer m_pFeatureLayer)
        {
            Items.Clear();
            if (m_pFeatureLayer == null || m_pFeatureLayer.FeatureClass == null)
            {
                return;
            }
            IFeatureClass pFeatureClass = m_pFeatureLayer.FeatureClass;

            ILayerFields pLayerFields = m_pFeatureLayer as ILayerFields;

            for (int k = 0; k < pLayerFields.FieldCount; k++)
            {
                IField pField = pLayerFields.get_Field(k);
                if (GeoBaseLib.IsSysField(pField.Name))
                {
                    continue;
                }
                Items.Add(pField.Name);
            }
            if (Items.Count > 0)
            {
                SelectedIndex = 0;
            }
        }
Esempio n. 5
0
        private void LayerDisplaySetCtrl_Load(object sender, EventArgs e)
        {
            this.chkShowMapTip.Checked = this.ilayer_0.ShowTips;
            if (this.ilayer_0 is ILayerEffects)
            {
                this.txtPercent.Text = (this.ilayer_0 as ILayerEffects).Transparency.ToString();
            }
            else
            {
                this.txtPercent.Enabled = false;
            }
            if (this.ilayer_0 is IFeatureLayer)
            {
                this.chkScaleSymbols.Checked = (this.ilayer_0 as IFeatureLayer2).ScaleSymbols;
                this.chkScaleSymbols.Enabled = true;
                this.chkShowMapTip.Enabled   = true;
            }
            else
            {
                this.chkScaleSymbols.Enabled = false;
                this.chkShowMapTip.Enabled   = true;
            }
            ILayerFields fields = this.ilayer_0 as ILayerFields;

            this.cboFields.Properties.Items.Clear();
            this.cboFields.Properties.Items.Add("<无>");
            if (this.ilayer_0 is IHotlinkContainer)
            {
                int    num2         = 0;
                string hotlinkField = (this.ilayer_0 as IHotlinkContainer).HotlinkField;
                this.HyperLinkGroup.Visible = true;
                for (int i = 0; i < fields.FieldCount; i++)
                {
                    IField     field = fields.get_Field(i);
                    IFieldInfo info  = fields.get_FieldInfo(i);
                    if ((field.Type == esriFieldType.esriFieldTypeString) && info.Visible)
                    {
                        this.cboFields.Properties.Items.Add(new FieldWrapEx(field, info));
                        if (field.Name == hotlinkField)
                        {
                            num2 = this.cboFields.Properties.Items.Count - 1;
                        }
                    }
                }
                this.cboFields.SelectedIndex         = num2;
                this.rdoHyperLinkeType.SelectedIndex = (int)(this.ilayer_0 as IHotlinkContainer).HotlinkType;
            }
            else
            {
                this.HyperLinkGroup.Visible = false;
            }
            this.bool_0 = true;
        }
Esempio n. 6
0
        public SelectByAttribute(ILayer player)
        {
            InitializeComponent();
            this.featureLayer = (IFeatureLayer)player as IFeatureLayer;
            ILayerFields layerFields = (ILayerFields)featureLayer;

            for (int i = 0; i < layerFields.FieldCount; i++)
            {
                IField field = layerFields.get_Field(i);
                comboBox1.Items.Add(field.Name);
            }
        }
        private void FormAtrribute_Load(object sender, EventArgs e)
        {
            try
            {
                pFeatureLayer = pLayer as IFeatureLayer;
                pFeatureClass = pFeatureLayer.FeatureClass;
                pLayerFields  = pFeatureLayer as ILayerFields;
                DataSet    ds = new DataSet("dsTest");
                DataTable  dt = new DataTable(pFeatureLayer.Name);
                DataColumn dc = null;
                for (int i = 0; i < pLayerFields.FieldCount; i++)
                {
                    dc = new DataColumn(pLayerFields.get_Field(i).Name);
                    //if (pLayerFields.get_Field(i).Editable == true)
                    //    dc.ReadOnly = false;
                    //else
                    //    dc.ReadOnly = true;

                    dt.Columns.Add(dc);
                    dc = null;
                }
                IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                IFeature       pFeature       = pFeatureCursor.NextFeature();
                while (pFeature != null)
                {
                    DataRow dr = dt.NewRow();
                    for (int j = 0; j < pLayerFields.FieldCount; j++)
                    {
                        if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
                        {
                            dr[j] = pFeatureClass.ShapeType.ToString();
                        }
                        else
                        {
                            dr[j] = pFeature.get_Value(j);
                        }
                    }
                    dt.Rows.Add(dr);
                    pFeature = pFeatureCursor.NextFeature();
                }
                dataGridView1.DataSource = dt;
            }
            catch (Exception exc)
            {
                MessageBox.Show("读取属性表失败:" + exc.Message);
                this.Dispose();
            }
            finally
            {
                //this.Close();
            }
        }
Esempio n. 8
0
        private void attributeTable_Load(object sender, EventArgs e)
        {
            try
            {
                pFeatureLayer = pLayer as IFeatureLayer;
                pFeatureClass = pFeatureLayer.FeatureClass;
                pLayerFields  = pFeatureLayer as ILayerFields;
                DataSet   ds = new DataSet("dsTest");
                DataTable dt = new DataTable(pFeatureLayer.Name);

                DataColumn dc = null;
                for (int i = 0; i < pLayerFields.FieldCount; i++)
                {
                    dc = new DataColumn(pLayerFields.get_Field(i).Name);

                    dt.Columns.Add(dc);
                    dc = null;
                }
                IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                IFeature       pFeature       = pFeatureCursor.NextFeature();
                while (pFeature != null)
                {
                    DataRow dr = dt.NewRow();
                    for (int i = 0; i < pLayerFields.FieldCount; i++)
                    {
                        if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == i)
                        {
                            dr[i] = pFeatureClass.ShapeType.ToString();
                        }
                        else
                        {
                            dr[i] = pFeature.get_Value(i);
                        }
                    }

                    dt.Rows.Add(dr);
                    pFeature = pFeatureCursor.NextFeature();
                }

                dataGridView1.DataSource = dt;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("读取属性表失败" + ex.Message);
                this.Dispose();
            }
        }
Esempio n. 9
0
 private void AttributeForm_Load(object sender, EventArgs e)
 {
     try
     {
         string tableName;
         tableName     = getValidFeatureClassName(pLayer.Name); //从图层名中获取图层名
         this.Text     = tableName + "属性表".ToString();          //替换窗体名称
         pFeatureLayer = pLayer as IFeatureLayer;
         pFeatureClass = pFeatureLayer.FeatureClass;
         pLayerFields  = pFeatureLayer as ILayerFields;
         DataTable  dt = new DataTable(pFeatureLayer.Name);//实例化数据表
         DataColumn dc = null;
         for (int i = 0; i < pLayerFields.FieldCount; i++)
         {
             //通过实例化获取数据表的字段名
             dc = new DataColumn(pLayerFields.get_Field(i).Name);
             dt.Columns.Add(dc);//在数据表得到列
             dc = null;
         }
         //
         IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
         IFeature       pFeature       = pFeatureCursor.NextFeature();
         while (pFeature != null)//当要素不为空
         {
             DataRow dr = dt.NewRow();
             for (int j = 0; j < pLayerFields.FieldCount; j++)
             {// 在pLayerFields对象中找到pFeatureClass.ShapeFieldName的索引,并在数据表中显示该shape的类型。
                 if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
                 {
                     dr[j] = pFeatureClass.ShapeType.ToString();// pFeatureClass.ShapeType得到类型值,然后转换为字符串。若没有该句就无法显示形状类型,效果见下页。
                 }
                 else
                 {
                     dr[j] = pFeature.get_Value(j);//直接返回这个值
                 }
             }
             dt.Rows.Add(dr);
             pFeature = pFeatureCursor.NextFeature();//游标下移
         }
         dataGridView1.DataSource = dt;
     }
     catch (Exception exc)
     {
         MessageBox.Show("读取属性表失败:" + exc.Message);
         this.Dispose();
     }
 }
Esempio n. 10
0
        private void FrmAttribute_Load(object sender, EventArgs e)
        {
            try
            {
                string tableName = pLayer.Name;
                this.Text     = tableName + "属性表".ToString();//替换窗体名称
                pFeatureLayer = pLayer as IFeatureLayer;
                pFeatureClass = pFeatureLayer.FeatureClass;
                pLayerFields  = pFeatureLayer as ILayerFields;
                DataTable  dt = new DataTable(pFeatureLayer.Name);
                DataColumn dc = null;
                for (int i = 0; i < pLayerFields.FieldCount; i++)
                {
                    dc = new DataColumn(pLayerFields.get_Field(i).Name);
                    dt.Columns.Add(dc);
                    dc = null;
                }
                IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                IFeature       pFeature       = pFeatureCursor.NextFeature();

                while (pFeature != null)
                {
                    DataRow dr = dt.NewRow();
                    for (int j = 0; j < pLayerFields.FieldCount; j++)
                    {
                        if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
                        {
                            dr[j] = pFeatureClass.ShapeType.ToString();
                        }
                        else
                        {
                            dr[j] = pFeature.get_Value(j);
                        }
                    }
                    dt.Rows.Add(dr);
                    pFeature = pFeatureCursor.NextFeature();
                }
                dataGridView1.DataSource = dt;
            }
            catch (Exception exc)
            {
                MessageBox.Show("读取属性表失败:" + exc.Message);
                this.Dispose();
            }
        }
Esempio n. 11
0
        private int ConstructDataSet(IFeatureLayer pFeatLyr)
        {
            ILayerFields  pFeatlyrFields = pFeatLyr as ILayerFields;
            IFeatureClass pFeatCls       = pFeatLyr.FeatureClass;
            int           rows           = 0;

            if (m_layerDataSet.Tables[pFeatLyr.Name] == null)
            {
                DataTable  pTable = new DataTable(pFeatLyr.Name);
                DataColumn pTableCol;
                for (int i = 0; i <= pFeatlyrFields.FieldCount - 1; i++)
                {
                    pTableCol = new DataColumn(pFeatlyrFields.get_Field(i).AliasName);
                    pTable.Columns.Add(pTableCol);
                    pTableCol = null;
                }

                IFeatureCursor features = pFeatLyr.Search(null, false);
                IFeature       feature  = features.NextFeature();
                while (feature != null)
                {
                    DataRow pTableRow = pTable.NewRow();
                    for (int i = 0; i <= pFeatlyrFields.FieldCount - 1; i++)
                    {
                        //pTableRow[i] = feature.get_Value(i);
                        if (pFeatlyrFields.FindField(pFeatCls.ShapeFieldName) == i)
                        {
                            pTableRow[i] = pFeatCls.ShapeType;
                        }
                        else
                        {
                            pTableRow[i] = feature.get_Value(i);
                        }
                    }
                    pTable.Rows.Add(pTableRow);
                    feature = features.NextFeature();
                }
                rows = pTable.Rows.Count;
                m_layerDataSet.Tables.Add(pTable);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(features);
            }
            return(rows);
        }
        private void cboLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Get IFeatureLayer interface
            IFeatureLayer featureLayer = (IFeatureLayer)Map.get_Layer(cboLayers.SelectedIndex);
            //Query interface for ILayerFields
            ILayerFields layerFields = (ILayerFields)featureLayer;

            int j = 0;

            cboFields.Items.Clear();
            cboFields.Enabled = true;

            if (m_Fields == null)
            {
                m_Fields = new List <IField>();
            }
            else
            {
                m_Fields.Clear();
            }

            //Loop through the fields
            for (int i = 0; i <= layerFields.FieldCount - 1; i++)
            {
                //Get IField interface
                IField field = layerFields.get_Field(i);
                //If the field is not the shape field
                if (IsValid(field))
                {
                    //Add field name to the control
                    cboFields.Items.Insert(j, field.AliasName);
                    m_Fields.Add(field);
                    //If the field name is the display field
                    if (field.Name == featureLayer.DisplayField)
                    {
                        //Select the field name in the control
                        cboFields.SelectedIndex = j;
                    }
                    j = j + 1;
                }
            }
        }
Esempio n. 13
0
        private void cboDataField_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            //Get IFeatureLayer interface
            IFeatureLayer featureLayer = (IFeatureLayer)axMapControl1.get_Layer(cboDataLayer.SelectedIndex);
            //Query interface for IlayerFields
            ILayerFields layerFields = (ILayerFields)featureLayer;

            //Loop through the fields
            for (int i = 0; i <= layerFields.FieldCount - 1; i++)
            {
                //Get IField interface
                IField field = layerFields.get_Field(i);
                //If the field name is the name selected in the control
                if (field.Name == cboDataField.Text)
                {
                    //Set the field as the display field
                    featureLayer.DisplayField = field.Name;
                    break;
                }
            }
        }
Esempio n. 14
0
        private void cboDataLayer_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            //Disable field combo if feature layer is not selected and exit
            if (axMapControl1.get_Layer(cboDataLayer.SelectedIndex) is IFeatureLayer == false)
            {
                cboDataField.Items.Clear();
                cboDataField.Enabled = false;
                return;
            }

            //Get IFeatureLayer interface
            IFeatureLayer featureLayer = (IFeatureLayer)axMapControl1.get_Layer(cboDataLayer.SelectedIndex);
            //Query interface for ILayerFields
            ILayerFields layerFields = (ILayerFields)featureLayer;

            int j = 0;

            cboDataField.Items.Clear();
            cboDataField.Enabled = true;
            //Loop through the fields
            for (int i = 0; i <= layerFields.FieldCount - 1; i++)
            {
                //Get IField interface
                IField field = layerFields.get_Field(i);
                //If the field is not the shape field
                if (field.Type != esriFieldType.esriFieldTypeGeometry)
                {
                    //Add field name to the control
                    cboDataField.Items.Insert(j, field.Name);
                    //If the field name is the display field
                    if (field.Name == featureLayer.DisplayField)
                    {
                        //Select the field name in the control
                        cboDataField.SelectedIndex = j;
                    }
                    j = j + 1;
                }
            }
            ShowLayerTips();
        }
Esempio n. 15
0
        private void method_0(IFeatureLayer featureLayer)
        {
            ILayerFields layerField = (ILayerFields)featureLayer;
            int          fieldCount = featureLayer.FeatureClass.Fields.FieldCount;
            Regex        regex      = new Regex("^[\\u4e00-\\u9fa5]+$");

            for (int i = 0; i < fieldCount; i++)
            {
                string name = layerField.get_Field(i).Name;
                if (!this.dataGridView3.Columns.Contains(name))
                {
                    this.dataGridView3.Columns.Add(name, name);
                    if (name == "起点管顶高程")
                    {
                        this.dataGridView3.Columns.Add("起点管底高程", "起点管底高程");
                    }
                    if (name == "终点管顶高程")
                    {
                        this.dataGridView3.Columns.Add("终点管底高程", "终点管底高程");
                    }
                }
            }
        }
Esempio n. 16
0
        public void Refresh(DataGridView _data, IFeatureLayer pFLayer)
        {
            pFeatureLayer = pFLayer;
            pFeatureClass = pFeatureLayer.FeatureClass;
            pLayerFields  = pFeatureLayer as ILayerFields;
            DataSet    ds = new DataSet("dsTests");
            DataTable  dt = new DataTable(pFeatureLayer.Name);
            DataColumn dc = null;

            for (int i = 0; i < pLayerFields.FieldCount; i++)
            {
                dc = new DataColumn(pLayerFields.get_Field(i).Name);
                dt.Columns.Add(dc);
                dc = null;
            }
            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature       pFeature       = pFeatureCursor.NextFeature();

            while (pFeature != null)
            {
                DataRow dr = dt.NewRow();
                for (int j = 0; j < pLayerFields.FieldCount; j++)
                {
                    if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
                    {
                        dr[j] = pFeatureClass.ShapeType.ToString();
                    }
                    else
                    {
                        dr[j] = pFeature.get_Value(j);
                    }
                }
                dt.Rows.Add(dr);
                pFeature = pFeatureCursor.NextFeature();
            }
            _data.DataSource = dt;
        }
Esempio n. 17
0
        public void AddItems(IFeatureLayer m_pFeatureLayer, seismicGCBaseRelativeYearFieldFormat format = seismicGCBaseRelativeYearFieldFormat.seismicGCBRYFTypeYRS)
        {
            m_nFieldFormat = format;
            Items.Clear();
            if (m_pFeatureLayer == null || m_pFeatureLayer.FeatureClass == null)
            {
                return;
            }
            IFeatureClass pFeatureClass = m_pFeatureLayer.FeatureClass;

            ILayerFields pLayerFields = m_pFeatureLayer as ILayerFields;

            for (int k = 0; k < pLayerFields.FieldCount; k++)
            {
                IField pField = pLayerFields.get_Field(k);
                if (GeoBaseLib.IsSysField(pField.Name))
                {
                    continue;
                }
                if (m_nFieldFormat == seismicGCBaseRelativeYearFieldFormat.seismicGCBRYFTypeYRS)
                {
                    if (pField.Name.Contains("YRS"))
                    {
                        Items.Add(pField.Name);
                    }
                }
                else if (m_nFieldFormat == seismicGCBaseRelativeYearFieldFormat.seismicGCBRYFTypeNone)
                {
                    Items.Add(pField.Name);
                }
            }
            if (Items.Count > 0)
            {
                SelectedIndex = 0;
            }
        }
Esempio n. 18
0
        //初始化属性表
        public void SetTable()
        {
            try
            {
                pLayer = currentLayer;

                pFeatureLayer = pLayer as IFeatureLayer;
                pFeatureClass = pFeatureLayer.FeatureClass;
                pLayerFields  = pFeatureLayer as ILayerFields;
                DataSet    ds = new DataSet("dsTest");
                DataTable  dt = new DataTable(pFeatureLayer.Name);
                DataColumn dc = null;
                for (int i = 0; i < pLayerFields.FieldCount; i++)
                {
                    dc = new DataColumn(pLayerFields.get_Field(i).Name);
                    dt.Columns.Add(dc);
                    dc = null;
                }

                IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                IFeature       pFeature       = pFeatureCursor.NextFeature();
                while (pFeature != null)
                {
                    DataRow dr = dt.NewRow();
                    for (int j = 0; j < pLayerFields.FieldCount; j++)
                    {
                        if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
                        {
                            dr[j] = pFeatureClass.ShapeType.ToString();
                        }
                        else
                        {
                            dr[j] = pFeature.get_Value(j);
                        }
                    }
                    dt.Rows.Add(dr);
                    pFeature = pFeatureCursor.NextFeature();
                }
                dataGridView1.DataSource = dt;
                for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
                {
                    this.dataGridView1.Columns[i].SortMode     = DataGridViewColumnSortMode.NotSortable;
                    this.dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                }

                //if (currentLayer == null) { return; }
                //IFeature feature = null;
                //DataTable dataTable = new DataTable();
                //DataRow dataRow = null;
                //DataColumn dataColumn = null;
                //IField field = null;
                ////创建表的字段名
                //for (int i = 0; i < currentLayer.FeatureClass.Fields.FieldCount; i++)
                //{
                //    dataColumn = new DataColumn();
                //    field = currentLayer.FeatureClass.Fields.get_Field(i);
                //    dataColumn.ColumnName = field.AliasName;
                //    dataTable.Columns.Add(dataColumn);
                //}
                ////添加具体的数据
                //IFeatureCursor cursor = currentLayer.Search(null, true);
                //feature = cursor.NextFeature();
                //while (feature != null)
                //{
                //    dataRow = dataTable.NewRow();
                //    for (int i = 0; i < dataTable.Columns.Count; i++)
                //    {
                //        dataRow[i] = feature.get_Value(i);
                //    }
                //    dataTable.Rows.Add(dataRow);
                //    cursor.NextFeature();
                //}
                ////释放指针
                //System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                ////设置为数据源
                //dataGridView.DataSource = dataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                this.Dispose();
            }
        }
Esempio n. 19
0
        private void btnShowAllValue_Click(object sender, EventArgs e)
        {
            if (cmbFields.Text == "")
            {
                MessageBox.Show("请选择字段名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            listBoxValue.Items.Clear();
            IFeatureLayer pFeatureLayer;

            pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex);

            IFeatureCursor pFeatureCursor;

            pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false);

            IFeature pFeature;

            pFeature = pFeatureCursor.NextFeature();



            //对Table中当前字段进行排序,把结果赋给Cursor

            ITable pTable = pFeatureLayer as ITable;

            ITableSort pTableSort = new TableSortClass();

            pTableSort.Table = pTable;

            pTableSort.Fields = cmbFields.Text;

            pTableSort.set_Ascending(cmbFields.Text, true);

            pTableSort.set_CaseSensitive(cmbFields.Text, true);

            pTableSort.Sort(null);

            ICursor pCursor = pTableSort.Rows;


            //数值统计

            IDataStatistics pData = new DataStatisticsClass();

            pData.Cursor = pCursor;

            pData.Field = cmbFields.Text;



            System.Collections.IEnumerator pEnumeratorUniqueValues = pData.UniqueValues; //唯一值枚举
            int uniqueValueCount = pData.UniqueValueCount;                               //唯一值的个数

            this.listBoxValue.Items.Clear();

            string fldValue = null;

            pEnumeratorUniqueValues.Reset();

            ILayerFields pFields = pFeatureLayer as ILayerFields;

            if (pFields.get_Field(pFields.FindField(cmbFields.Text)).Type == esriFieldType.esriFieldTypeString)
            {
                while (pEnumeratorUniqueValues.MoveNext())
                {
                    fldValue = pEnumeratorUniqueValues.Current.ToString();
                    this.listBoxValue.Items.Add("'" + fldValue + "'");
                }
            }
            else if (cmbFields.Text == "shape")
            {
                fldValue = Convert.ToString(pFeature.Shape.GeometryType);
                this.listBoxValue.Items.Add(fldValue);
            }
            else
            {
                while (pEnumeratorUniqueValues.MoveNext())
                {
                    fldValue = pEnumeratorUniqueValues.Current.ToString();
                    this.listBoxValue.Items.Add(fldValue);
                }
            }



            /* while(pFeature!=null)
             * {
             *   string fldValue;
             *   if (cmbFields.Text == "Shape")
             *   {
             *       fldValue = Convert.ToString(pFeature.Shape.GeometryType);
             *   }
             *   else
             *       fldValue = Convert.ToString(pFeature.get_Value(iFieldIndex));
             *
             *   listBoxValue.Items.Add(fldValue);
             *   pFeature = pFeatureCursor.NextFeature();
             * } */
        }
Esempio n. 20
0
 private void method_0(ILayer layer)
 {
     if (layer is IFeatureLayer && layer.Visible)
     {
         IFeatureLayer   featureLayer = layer as IFeatureLayer;
         IFeatureClass   featureClass = featureLayer.FeatureClass;
         IFields         fields       = featureClass.Fields;
         IBasicLayerInfo layerInfo    = _config.GetBasicLayerInfo(featureClass);
         if (featureClass.ShapeType == esriGeometryType.esriGeometryPoint)
         {
             //this.m_strBuildDate = this.pPipeCfg.GetPointTableFieldName("爆管次数");
             this.m_strBuildDate = layerInfo.GetFieldName(PipeConfigWordHelper.PointWords.SGYHDJ);
         }
         else
         {
             this.m_strBuildDate = layerInfo.GetFieldName(PipeConfigWordHelper.PointWords.SGYHDJ);
             // this.m_strBuildDate = this.pPipeCfg.GetLineTableFieldName("爆管次数");
         }
         int num = fields.FindField(this.m_strBuildDate);
         if (num == -1)
         {
             MessageBox.Show("爆管次数字段不存在!返回");
         }
         else
         {
             IField field = fields.get_Field(num);
             if (layerInfo != null &&
                 (layerInfo.DataType == enumPipelineDataType.Point ||
                  layerInfo.DataType == enumPipelineDataType.Line))
             {
                 DateTime now = DateTime.Now;
                 now.ToShortDateString();
                 now.AddYears(-1 * this.m_nExpireTime).ToShortDateString();
                 string whereClause;
                 if (field.Type == (esriFieldType)4)
                 {
                     whereClause = this.m_strBuildDate + "> '" + this.m_nExpireTime.ToString() + "'";
                 }
                 else
                 {
                     whereClause = this.m_strBuildDate + "> " + this.m_nExpireTime.ToString();
                 }
                 IFeatureClass arg_162_0        = featureClass;
                 IQueryFilter  queryFilterClass = new QueryFilter();
                 queryFilterClass.WhereClause = (whereClause);
                 IFeatureCursor featureCursor = arg_162_0.Search(queryFilterClass, false);
                 ILayerFields   layerFields   = (ILayerFields)featureLayer;
                 int            fieldCount    = featureLayer.FeatureClass.Fields.FieldCount;
                 this.dataGridView3.Rows.Clear();
                 this.dataGridView3.Columns.Clear();
                 DataGridViewCellStyle columnHeadersDefaultCellStyle = new DataGridViewCellStyle();
                 this.dataGridView3.ColumnHeadersDefaultCellStyle           = columnHeadersDefaultCellStyle;
                 this.dataGridView3.ColumnHeadersDefaultCellStyle.BackColor = Color.FromName("Control");
                 this.dataGridView3.Columns.Clear();
                 this.dataGridView3.ColumnCount = fieldCount;
                 for (int i = 0; i < fieldCount; i++)
                 {
                     IField field2    = layerFields.get_Field(i);
                     string aliasName = field2.AliasName;
                     this.dataGridView3.Columns[i].Name     = aliasName;
                     this.dataGridView3.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                 }
                 IFeature feature = featureCursor.NextFeature();
                 int      num2    = 0;
                 while (feature != null)
                 {
                     if (!feature.HasOID || feature == null)
                     {
                         feature = featureCursor.NextFeature();
                     }
                     else
                     {
                         string text   = "esriGeometry";
                         int    length = text.Length;
                         int    num3   = layerFields.FindField(featureLayer.FeatureClass.ShapeFieldName);
                         string text2  = featureLayer.FeatureClass.ShapeType.ToString();
                         string value  = text2.Remove(0, length);
                         this.dataGridView3.Rows.Add(new object[]
                         {
                             ""
                         });
                         int num4 = 1;
                         for (int j = 0; j < fieldCount; j++)
                         {
                             if (num3 == j)
                             {
                                 this.dataGridView3[j, num2].Value = value;
                             }
                             else
                             {
                                 this.dataGridView3[j, num2].Value = feature.get_Value(j).ToString();
                             }
                             num4++;
                         }
                         num2++;
                         feature = featureCursor.NextFeature();
                     }
                 }
                 this.Text = "多次爆点列表: 记录条数--" + num2.ToString();
             }
         }
     }
 }
Esempio n. 21
0
        private void ReadFieldInfo()
        {
            IDomain           domain       = null;
            ICodedValueDomain domain2      = null;
            ILayerFields      featureLayer = this.FeatureLayer as ILayerFields;

            for (int i = 0; i < featureLayer.FieldCount; i++)
            {
                string     str;
                IFieldInfo info;
                FieldInfo  info2;
                IField     field = featureLayer.get_Field(i);
                if (field.Required)
                {
                    if ((featureLayer is IFDOGraphicsLayer) && (string.Compare(field.Name, "SymbolID", true) == 0))
                    {
                        str = (field.Type == esriFieldType.esriFieldTypeString)
                            ? string.Format("(长度={0})", field.Length)
                            : "";
                        info  = featureLayer.get_FieldInfo(i);
                        info2 = new FieldInfo
                        {
                            FieldName       = "SymbolID",
                            TypeDescription = RowOperator.GetFieldTypeString(field.Type) + str,
                            IsNull          = field.IsNullable,
                            IsVisible       = info.Visible,
                            LayerFieldAlias = info.Alias
                        };
                        this.m_listInfo.Add(info2);
                        this.m_sortAliaslistInfo.Add(info2.LayerFieldAlias, info2);
                        this.m_sortnamelistInfo.Add(info2.FieldName, info2);
                    }
                }
                else if (field.Editable &&
                         ((((field.Type != esriFieldType.esriFieldTypeGeometry) &&
                            (field.Type != esriFieldType.esriFieldTypeBlob)) &&
                           (field.Type != esriFieldType.esriFieldTypeRaster)) &&
                          (field.Type != esriFieldType.esriFieldTypeOID)))
                {
                    str = (field.Type == esriFieldType.esriFieldTypeString)
                        ? string.Format("(长度={0})", field.Length)
                        : "";
                    info  = featureLayer.get_FieldInfo(i);
                    info2 = new FieldInfo
                    {
                        FieldName       = field.Name,
                        TypeDescription = RowOperator.GetFieldTypeString(field.Type) + str,
                        IsNull          = field.IsNullable,
                        IsVisible       = info.Visible,
                        LayerFieldAlias = info.Alias
                    };
                    domain = field.Domain;
                    if ((domain != null) && (domain is ICodedValueDomain))
                    {
                        domain2 = domain as ICodedValueDomain;
                        List <string> list = new List <string>();
                        if (field.IsNullable)
                        {
                            list.Add("<空>");
                        }
                        for (int j = 0; j < domain2.CodeCount; j++)
                        {
                            list.Add(domain2.get_Name(j));
                        }
                        info2.CodeDomainList = list;
                    }
                    this.m_listInfo.Add(info2);
                    this.m_sortAliaslistInfo.Add(info2.LayerFieldAlias, info2);
                    this.m_sortnamelistInfo.Add(info2.FieldName, info2);
                }
            }
        }
Esempio n. 22
0
        private void FrmAttributeTab_Load(object sender, EventArgs e)
        {
            int nFeatureCount = 0;

            try
            {
                if (pFeatureLayer == null)
                {
                    return;
                }
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                if (pFeatureLayer == null)
                {
                    return;
                }
                ILayerFields pLayerFields = pFeatureLayer as ILayerFields;
                DataSet      ds           = new DataSet("dsTest");
                DataTable    dt           = new DataTable(pFeatureLayer.Name);
                DataColumn   dc           = null;
                for (int k = 0; k < pLayerFields.FieldCount; k++)
                {
                    dc = new DataColumn(pLayerFields.get_Field(k).Name);
                    dt.Columns.Add(dc);
                    dc = null;
                }
                if (m_nMode == 0)
                {
                    IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                    IFeature       pFeature       = pFeatureCursor.NextFeature();
                    while (pFeature != null)
                    {
                        nFeatureCount++;
                        DataRow dr = dt.NewRow();
                        for (int j = 0; j < pLayerFields.FieldCount; j++)
                        {
                            if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
                            {
                                dr[j] = pFeatureClass.ShapeType.ToString();
                            }
                            else
                            {
                                dr[j] = pFeature.get_Value(j).ToString();
                            }
                        }
                        dt.Rows.Add(dr);
                        pFeature = pFeatureCursor.NextFeature();
                    }
                    ds.Tables.Add(dt);
                    dataGridView1.DataSource = ds.Tables[pFeatureLayer.Name];
                }
                else if (m_nMode == 1)
                {
                    nFeatureCount = m_aFeatures.Count;
                    for (int i = 0; i < m_aFeatures.Count; i++)
                    {
                        IFeature pFeature = m_aFeatures.get_Element(i) as IFeature;
                        DataRow  dr       = dt.NewRow();
                        for (int j = 0; j < pLayerFields.FieldCount; j++)
                        {
                            if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j)
                            {
                                dr[j] = pFeatureClass.ShapeType.ToString();
                            }
                            else
                            {
                                dr[j] = pFeature.get_Value(j).ToString();
                            }
                        }
                        dt.Rows.Add(dr);
                    }
                    ds.Tables.Add(dt);
                    dataGridView1.DataSource = ds.Tables[pFeatureLayer.Name];
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Failed in read attributes: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            label1.Text = nFeatureCount.ToString() + " features in this table.";
        }
Esempio n. 23
0
        private void method_0(ILayer layer)
        {
            if (!(layer is IFeatureLayer) || !layer.Visible)
            {
                return;
            }
            IFeatureLayer   featureLayer = layer as IFeatureLayer;
            IFeatureClass   featureClass = featureLayer.FeatureClass;
            IFields         fields       = featureClass.Fields;
            string          text         = "节点性质";
            IBasicLayerInfo layerInfo    = _config.GetBasicLayerInfo(featureClass);

            if (featureClass.ShapeType == esriGeometryType.esriGeometryPoint)
            {
                this.m_strBuildDate = layerInfo.GetFieldName(PipeConfigWordHelper.PointWords.MSRQ);
                // this.pPipeCfg.GetPointTableFieldName("建设年代");
                text = layerInfo.GetFieldName(PipeConfigWordHelper.PointWords.TZW);
            }
            else
            {
                this.m_strBuildDate = layerInfo.GetFieldName(PipeConfigWordHelper.LineWords.MSRQ);
                // this.pPipeCfg.GetLineTableFieldName("建设年代");
            }
            int num = fields.FindField(this.m_strBuildDate);

            if (num == -1)
            {
                MessageBox.Show("建设年代字段不存在!返回");
                return;
            }

            IField field = fields.get_Field(num);

            if (layerInfo == null ||
                (layerInfo.DataType != enumPipelineDataType.Point && layerInfo.DataType != enumPipelineDataType.Line))
            {
                return;
            }
            DateTime now = DateTime.Now;

            now.ToShortDateString();
            string text2       = now.AddYears(-1 * this.m_nExpireTime).ToShortDateString();
            string whereClause = "";

            if (field.Type == esriFieldType.esriFieldTypeDate)
            {
                if (featureLayer.DataSourceType == "Personal Geodatabase Feature Class")
                {
                    whereClause = this.m_strBuildDate + "< #" + text2 + "#";
                    if (this.m_pCurLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        whereClause = string.Concat(new string[]
                        {
                            this.m_strBuildDate,
                            " < #",
                            text2,
                            "# AND ",
                            text,
                            " <> '直线点' AND ",
                            text,
                            " <> '转折点'"
                        });
                    }
                }
                if (featureLayer.DataSourceType == "SDE Feature Class")
                {
                    whereClause = this.m_strBuildDate + "< TO_DATE('" + text2 + "','YYYY-MM-DD')";
                    if (this.m_pCurLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        whereClause = string.Concat(new string[]
                        {
                            this.m_strBuildDate,
                            " < TO_DATE('",
                            text2,
                            "','YYYY-MM-DD') AND ",
                            text,
                            " <> '直线点' AND ",
                            text,
                            " <> '转折点'"
                        });
                    }
                }
            }
            else if (field.Type == (esriFieldType)4)
            {
                whereClause = this.m_strBuildDate + "< '" + text2 + "'";
                if (this.m_pCurLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                {
                    whereClause = string.Concat(new string[]
                    {
                        this.m_strBuildDate,
                        " < '",
                        text2,
                        "' AND ",
                        text,
                        " <> '直线点' AND ",
                        text,
                        " <> '转折点'"
                    });
                }
            }
            if (field.Type == (esriFieldType)1 || field.Type == 0)
            {
                whereClause = this.m_strBuildDate + "< " + text2;
                if (this.m_pCurLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                {
                    whereClause = string.Concat(new string[]
                    {
                        this.m_strBuildDate,
                        " < ",
                        text2,
                        " AND ",
                        text,
                        " <> '直线点' AND ",
                        text,
                        " <> '转折点'"
                    });
                }
            }
            IFeatureClass arg_396_0        = featureClass;
            IQueryFilter  queryFilterClass = new QueryFilter();

            queryFilterClass.WhereClause = (whereClause);
            IFeatureCursor featureCursor = arg_396_0.Search(queryFilterClass, false);
            ILayerFields   layerFields   = (ILayerFields)featureLayer;
            int            fieldCount    = featureLayer.FeatureClass.Fields.FieldCount;

            this.dataGridView3.Rows.Clear();
            this.dataGridView3.Columns.Clear();
            DataGridViewCellStyle columnHeadersDefaultCellStyle = new DataGridViewCellStyle();

            this.dataGridView3.ColumnHeadersDefaultCellStyle           = columnHeadersDefaultCellStyle;
            this.dataGridView3.ColumnHeadersDefaultCellStyle.BackColor = Color.FromName("Control");
            this.dataGridView3.Columns.Clear();
            this.dataGridView3.ColumnCount = fieldCount;
            for (int i = 0; i < fieldCount; i++)
            {
                IField field2    = layerFields.get_Field(i);
                string aliasName = field2.AliasName;
                this.dataGridView3.Columns[i].Name     = aliasName;
                this.dataGridView3.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }
            IFeature feature = featureCursor.NextFeature();
            int      num2    = 0;

            while (feature != null)
            {
                if (!feature.HasOID || feature == null)
                {
                    feature = featureCursor.NextFeature();
                }
                else
                {
                    string text3  = "esriGeometry";
                    int    length = text3.Length;
                    int    num3   = layerFields.FindField(featureLayer.FeatureClass.ShapeFieldName);
                    string text4  = featureLayer.FeatureClass.ShapeType.ToString();
                    string value  = text4.Remove(0, length);
                    this.dataGridView3.Rows.Add(new object[]
                    {
                        ""
                    });
                    int num4 = 1;
                    for (int j = 0; j < fieldCount; j++)
                    {
                        if (num3 == j)
                        {
                            this.dataGridView3[j, num2].Value = value;
                        }
                        else
                        {
                            this.dataGridView3[j, num2].Value = feature.get_Value(j).ToString();
                        }
                        num4++;
                    }
                    num2++;
                    feature = featureCursor.NextFeature();
                }
            }
            this.Text = "预警分析明析: 记录条数--" + num2.ToString();
        }
        private void LoadQueryResult()
        {
            IFeatureLayer featureLayer = this.layer as IFeatureLayer;

            if (featureLayer == null)
            {
                txb_Prompt.Visibility         = Visibility.Visible;
                datagrid_Attribute.Visibility = Visibility.Collapsed;
                return;
            }

            IFeatureClass featureClass = featureLayer.FeatureClass;
            ILayerFields  layerFields  = featureLayer as ILayerFields;

            DataColumn dataColumn      = null;
            DataTable  dataTable       = new DataTable(featureLayer.Name);
            DataTable  dataTableResult = new DataTable(featureLayer.Name);

            string classFilter = string.Empty;

            for (int i = 0; i < layerFields.FieldCount; i++)
            {
                dataColumn = new DataColumn(layerFields.get_Field(i).Name);
                dataTable.Columns.Add(dataColumn);
                dataColumn = null;
            }

            IFeature       feature     = null;
            IQueryFilter   queryFilter = new QueryFilterClass();
            IFeatureCursor featureCursor;

            featureCursor = featureClass.Search(null, true);
            feature       = featureCursor.NextFeature();

            while (feature != null)
            {
                DataRow dataRow = dataTable.NewRow();

                for (int i = 0; i < layerFields.FieldCount; i++)
                {
                    if (layerFields.FindField(featureClass.ShapeFieldName) == i)
                    {
                        dataRow[i] = featureClass.ShapeType.ToString();
                    }
                    else
                    {
                        dataRow[i] = feature.get_Value(i);
                    }
                }
                dataTable.Rows.Add(dataRow);
                feature = featureCursor.NextFeature();
            }

            classFilter = GetColumnCaption(dataTable);

            if (classFilter != string.Empty)
            {
                DataRow[] dataRows = dataTable.Select(classFilter + "=" + "'" + this.queryFilter + "'");

                dataTableResult = dataTable.Clone();

                foreach (var dataRow in dataRows)
                {
                    dataTableResult.ImportRow(dataRow);
                }

                dataTableResult.Columns[classFilter].SetOrdinal(0);

                if (dataTable.Rows.Count > 0)
                {
                    datagrid_Attribute.DataContext = dataTableResult;
                }
                else
                {
                    txb_Prompt.Visibility         = Visibility.Visible;
                    datagrid_Attribute.Visibility = Visibility.Collapsed;
                    return;
                }
            }
            else
            {
                if (dataTable.Rows.Count > 0)
                {
                    datagrid_Attribute.DataContext = dataTable;
                }
                else
                {
                    txb_Prompt.Visibility         = Visibility.Visible;
                    datagrid_Attribute.Visibility = Visibility.Collapsed;
                    return;
                }
            }
        }