예제 #1
0
        ////定义地图图层的表达式,针对组图层二级分组
        public static void setGpLyrsDefinitionOfHPoint(string in_sDefinition, ILayer in_Layer)
        {
            //ICompositeLayer
            IGroupLayer   pTmpGroupLyr = in_Layer as IGroupLayer;
            IFeatureLayer pTmpFeaLayer = in_Layer as IFeatureLayer;

            if (pTmpGroupLyr != null)
            {
                ICompositeLayer pComLayer = pTmpGroupLyr as ICompositeLayer;
                for (int i = 0; i < pComLayer.Count; i++)
                {
                    ILayer pLyr = pComLayer.get_Layer(i);
                    if (pLyr.Valid && pLyr.Visible)
                    {
                        if (pLyr is IFeatureLayer)
                        {
                            ILayerFields pLyrFds        = pLyr as ILayerFields;
                            int          idxValidDate   = pLyrFds.FindField("QSRQ"),
                                         idxInvalidDate = pLyrFds.FindField("ZZRQ");
                            if (idxInvalidDate != -1 && idxValidDate != -1)
                            {
                                IFeatureLayerDefinition2 pPFLD2 = pLyr as IFeatureLayerDefinition2;
                                pPFLD2.DefinitionExpression = in_sDefinition;
                            }
                        }
                    }
                }
                return;
            }
            if (pTmpFeaLayer != null)
            {
                ILayerFields pLyrFds        = pTmpFeaLayer as ILayerFields;
                int          idxValidDate   = pLyrFds.FindField("QSRQ"),
                             idxInvalidDate = pLyrFds.FindField("ZZRQ");
                if (idxInvalidDate != -1 && idxValidDate != -1)
                {
                    IFeatureLayerDefinition2 pPFLD2 = in_Layer as IFeatureLayerDefinition2;
                    pPFLD2.DefinitionExpression = in_sDefinition;
                }
            }
        }
        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();
            }
        }
예제 #3
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();
            }
        }
예제 #4
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();
     }
 }
예제 #5
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();
            }
        }
예제 #6
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);
        }
예제 #7
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;
        }
예제 #8
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();
             * } */
        }
예제 #9
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();
            }
        }
예제 #10
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();
        }
예제 #11
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.";
        }
예제 #12
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();
             }
         }
     }
 }
        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;
                }
            }
        }