IEumFeatureSetup.AllFields Property
今天在ESRI中国论坛里看到一个关于IEumFeatureSetup接口的问题,值得log下来。
有个网友在使用IEnumFeature时老出错,在下面代码红线处。
try
{
IMap pMap = new MapClass();
pMap = axMapControl1.Map;
IPoint pPt = new PointClass();
pPt.PutCoords(e.mapX, e.mapY);
IActiveView pActiveView = pMap as IActiveView;
ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass();
pMap.SelectByShape(pPt, pSelectionEnv, false);
IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
IFeature pFeature = pEnumFeature.Next();
while (pFeature != null)
{
string value = pFeature.get_Value(3).ToString();
textBox1.Text = value;
pFeature = pEnumFeature.Next();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
{
IMap pMap = new MapClass();
pMap = axMapControl1.Map;
IPoint pPt = new PointClass();
pPt.PutCoords(e.mapX, e.mapY);
IActiveView pActiveView = pMap as IActiveView;
ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass();
pMap.SelectByShape(pPt, pSelectionEnv, false);
IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
IFeature pFeature = pEnumFeature.Next();
while (pFeature != null)
{
string value = pFeature.get_Value(3).ToString();
textBox1.Text = value;
pFeature = pEnumFeature.Next();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
提示“未能将对象引用设置到对象的实例”, value的值总是为null。索引为3的字段确实存在,可以查询到这个字段的名称。
而用FeatureCursor游标做的查询就没有问题,因此问题应该是处在IEnumFeature, 可能不是全部fields都返回。这里就可以
用上IEnumFeatureSetup.AllFields来设置让IEnumFeature返回全部字段.以下是代码:
IEnumFeature pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature;
//********************************************************
IEnumFeatureSetup DD = pEnumFeature as IEnumFeatureSetup;
DD.AllFields = true;
//*******************************************************
pFeature = pEnumFeature.Next();
//********************************************************
IEnumFeatureSetup DD = pEnumFeature as IEnumFeatureSetup;
DD.AllFields = true;
//*******************************************************
pFeature = pEnumFeature.Next();
-----------------------------------------------------------
佛对我说:你心里有尘。我用力的拭擦。