IFeatureClass 获取字段值

 IMap pMap=axMapControl.Map;
    ILayer pLayer=null;
    for(int i=0;i<pMap.Layercount;i++)
    {
        pLayer=pMap.get_layer(i);
        if (pLayer is IFeatureLayer)
        comboBoxEdit1.Properties.Items.Add(layer.Name);
    

//根据需要获取指定图层layer

string layerName="";
    ILayer layer=null;
    for(int i=0;i<pMap.Layercount;i++)
    {
        if(pMap.get_layer(i).Name==layerName)
        {
            layer=pMap.get_layer(i);
        }
    }

//获取指定图层的所有字段名

 IFeatureLayer featureLayer=layer as IFeatureLayer;
    IfeatureClass featureclass=featureLayer.FeatureClass;
    IFields fields=featureclass.fields;
    for(int i=0;i<featureclass.fields.fieldcount;i++)
    {
        IField field=fields.get_field(i);
        listBoxControl1.Items.Add(field.Name);
        listBoxControl1.SelectedIndex = 0;
    }

//获取某个特定字段的所有值

IFeatureClass featureclass=featureLayer.FeatureClass;

//设定筛选条件获得满足要求的所有Feature

 IQueryFilter queryFilter = new QueryFilterClass();
    queryFilter.WhereClause = "";
    IFeatureCursor featurecursor=featureClass.search(queryFilter,false);
    IFeature feature=featureCursor.NextFeature;

//获取想要获取的字段值的fieldName的id号

string name="";
    int index=0;
    for(int i=0;i<fields.fieldcount;i++)
    {
        IField field=fields.get_field(i);
        if(field.Name==name)
        {
            indesx=i;
        }
    }
    while(feature!=null)
    {
        listBoxControl2.Items.Add(feature.get_Value(index).ToString());
        feature=featureCursor.NextFeature;
    }

  

posted @ 2015-10-16 15:49  JaneAi  阅读(1159)  评论(0编辑  收藏  举报