IFeatureClass 获取字段值

//比如我们给出了确定的图层名,我们要获取到该图层具体有哪些字段?并取出来
//先获取所有图层及其名字
    IMap pMap=axMapControl.Map;
    ILayer pLayer=null;
    for(int i=0;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    {
        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    {
        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    {
        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;
    }

转载于:https://www.cnblogs.com/henyihanwobushi/archive/2013/03/05/2944128.html

你可能感兴趣的:(c#)