本人刚做了有关属性查询的一些功能的实现,在这总结一下。
有错误之处和不专业之处还希望GIS和AE开发的高手们给以指点。
//******其中第二部分发生了点错误,现在已更改***********//
①:据FeatureLayer得到Feature的方法:
代码如下:
ILayer pLayer;
pLayer = frm1.axMapControl1.Map.get_Layer(LayerBoxEdit.SelectedIndex) as ILayer;//frm1和LayerBoxEdit.SelectedIndex都是变量
IFeatureLayer pFeatureLayer;
pFeatureLayer = pLayer as IFeatureLayer;
if (pFeatureLayer == null)
{
return;
}
IFeatureCursor pFeatureCursor;
pFeatureCursor = pFeatureLayer.Search(null, false);
IFeature pFeature;
pFeature = pFeatureCursor.NextFeature();
②:据FeatureClass得到Feature的方法:
IFeatureLayer pFeatureLayer;
pFeatureLayer = frm1.axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureClass pFeatureClass;
pFeatureClass = pFeatureLayer.FeatureClass;
IQueryFilter pQueryFilter;
pQueryFilter = new QueryFilterClass();
// pQueryFilter.WhereClause = "";
IFeature pFeature;
for(int j=0;j< pFeatureClass.FeatureCount(pQueryFilter); j++)
{
pFeature = pFeatureClass.GetFeature(j);
}
③:在TreeList中点击子节点得到Feature的方法:
if (e.Node.HasChildren)
{
return;
}
if (!(e.Node.HasChildren)) //***********//这个存在bug,若节点超过两级则出错
{
for (int i = 0; i < this.axMapControl1.LayerCount; i++)
{
//如果父节点名称和图层名相同,获取索引
if (e.Node.ParentNode.GetValue(0).ToString() == this.axMapControl1.get_Layer(i).Name)
{
layerIndex = i;
IFeature pFeature;
pFeature = (this.axMapControl1.get_Layer(layerIndex) as IFeatureLayer).FeatureClass.GetFeature(int.Parse(this.treeList1.FocusedNode.GetValue(0).ToString())); ;
}
}