FrmQuery.cs
资源名称:arcMAP.rar [点击查看]
上传用户:xianghe012
上传日期:2022-07-02
资源大小:77k
文件大小:5k
源码类别:
GIS编程
开发平台:
C#
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using ESRI.ArcGIS.esriSystem;
- using ESRI.ArcGIS.SystemUI;
- using ESRI.ArcGIS.Geometry;
- using ESRI.ArcGIS.Display;
- using ESRI.ArcGIS.Geodatabase;
- using ESRI.ArcGIS.Carto;
- using ESRI.ArcGIS.Controls;
- namespace ArcMap
- {
- public partial class FrmQuery : Form
- {
- public IMapControl2 pMapControl;
- public IMap pMap;
- public int iLayerIndex;
- public int iFieldIndex;
- public FrmQuery(IMapControl2 pFMapControl)
- {
- InitializeComponent();
- pMapControl = pFMapControl;
- pMap = pFMapControl.Map;
- }
- private void FrmQuery_Load(object sender, EventArgs e)
- {
- ILayer pLayer;
- for (int i = 0; i < pMap.LayerCount; i++)
- {
- pLayer = pMap.get_Layer(i);
- cmbLayers.Items.Add(pLayer.Name);
- }
- }
- private void cmbLayers_TextChanged(object sender, EventArgs e)
- {
- iLayerIndex = cmbLayers.Items.IndexOf(cmbLayers.Text);
- cmbFields.Items.Clear();
- }
- //获得图层的字段名称
- private void cmbFields_DropDown(object sender, EventArgs e)
- {
- cmbFields.Items.Clear();
- IFeatureLayer pFeatureLayer;
- pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex);
- IFields pFields;
- pFields = pFeatureLayer.FeatureClass.Fields;
- for (int i = 0; i < pFields.FieldCount; i++)
- {
- string fieldName;
- fieldName = pFields.get_Field(i).Name;
- cmbFields.Items.Add(fieldName);
- }
- }
- 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();
- 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();
- }
- }
- private void cmbFields_TextChanged(object sender, EventArgs e)
- {
- iFieldIndex = cmbFields.Items.IndexOf(cmbFields.Text);
- }
- private void listBoxValue_DoubleClick(object sender, EventArgs e)
- {
- txtValue.Text = Convert.ToString(listBoxValue.SelectedItem);
- }
- private void btnCancle_Click(object sender, EventArgs e)
- {
- // this.close();
- }
- private void btnQuery_Click(object sender, EventArgs e)
- {
- IActiveView pActiveView;
- pActiveView = (IActiveView)pMap;
- pMap.ClearSelection();
- pActiveView.Refresh();
- IQueryFilter pQueryFilter = new QueryFilterClass();
- IFeatureLayer pFeatureLayer;
- pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex);
- IFields pFields;
- pFields = pFeatureLayer.FeatureClass.Fields;
- IField pField;
- pField=pFields.get_Field(iFieldIndex);
- switch(pField.Type)
- {
- case esriFieldType.esriFieldTypeString:
- pQueryFilter.WhereClause=cmbFields.Text + " = '" + txtValue.Text + "'";
- break;
- case esriFieldType.esriFieldTypeDouble:
- case esriFieldType.esriFieldTypeInteger:
- case esriFieldType.esriFieldTypeSingle:
- case esriFieldType.esriFieldTypeSmallInteger:
- pQueryFilter.WhereClause = cmbFields.Text + " = " + txtValue.Text ;
- break;
- }
- IFeatureCursor pFeatureCursor;
- pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
- IFeature pFeature;
- pFeature = pFeatureCursor.NextFeature();
- while (pFeature!=null)
- {
- pMap.SelectFeature(pFeatureLayer, pFeature);
- pFeature = pFeatureCursor.NextFeature();
- }
- pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
- }
- private void btnTable_Click(object sender, EventArgs e)
- {
- frmTable fTable = new frmTable(pMapControl, cmbLayers.Text);
- fTable.Show();
- }
- }
- }