110,533
社区成员
发帖
与我相关
我的任务
分享
IArray pIDArray;
IFeatureIdentifyObj pFeatIdObj;
IIdentifyObj pIdObj;
//实际地图中图层第6层是信号机层
IFeatureLayer pLayer = axMapControl1.get_Layer(5) as IFeatureLayer;
IIdentify pIdentify = (IIdentify)axMapControl1.get_Layer(5);
IActiveView pActiveView = axMapControl1.ActiveView;
IMap pMap = axMapControl1.Map;
IEnvelope pEnv = axMapControl1.TrackRectangle();
IFeatureClass pFC = pLayer.FeatureClass;
pLayer.Name = pFC.AliasName;
ILayerFields pLayerFields = pLayer as ILayerFields;
if (pEnv.IsEmpty == true)
{
tagRECT r;
r.bottom = e.y + 5;
r.top = e.y - 5;
r.left = e.x - 5;
r.right = e.x + 5;
pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4);
pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference;
}
pMap.SelectByShape(pEnv, null, false);
pActiveView.Refresh();
//用于显示到datagridview各个中间过程
DataSet ds = new DataSet("dsAttribute");
DataTable dt = new DataTable(pLayer.Name);
DataColumn dc = null;
//属性查询
pIDArray = pIdentify.Identify(pEnv);
if (pIDArray != null)
{
DataRow dr = dt.NewRow();
for (int i = 0; i <= pIDArray.Count; i++)
{
pFeatIdObj = (IFeatureIdentifyObj)pIDArray.get_Element(i);
pIdObj = (IIdentifyObj)pFeatIdObj;
IRowIdentifyObject pRowObj = pFeatIdObj as IRowIdentifyObject;
IFeature pFeature = pRowObj.Row as IFeature;
if (pFeature != null)
{
//表头
for (int k = 0; k < pFeature.Table.Fields.FieldCount; k++)
{
dc = new DataColumn(pFeature.Table.Fields.get_Field(k).Name.ToString());
dt.Columns.Add(dc);
dc = null;
}
//各个column的值
for (int j = 0; j < pFeature.Table.Fields.FieldCount; j++)
{
dr[j] = pFeature.get_Value(j).ToString();
}
dt.Rows.Add(dr);
ds.Tables.Add(dt);
dataGridView1.DataSource = ds.Tables[pLayer.Name];
//显示dataGridView(用以显示监控点属性)
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].Visible = false;
dataGridView1.Show();
}
}
}