How to display field properties for a feature class


Summary
The how to display field properties for a feature class article suggests a possible workflow for accessing and viewing the properties of each field in a feature class. This process is broken into three steps; Reading the properties of the feature class itself, looping through each of the fields in the feature class, and lastly outputting the properties of the individual fields.


Displaying field properties for a feature class

The task of displaying field properties for a feature class has been divided into the following three functions. All three functions must be implemented for the code to work correctly:
The end result will be the properties for the feature class and then each field being printed to the console similar to the following:
Dataset Name : MyFeatureClass
Alias Name : My FeatureClass
Feature Type : Simple
Geometry Type : Polyline
See the following code example:
[Java]
static void displayFieldInfo(IFeatureClass featureClass)throws Exception{
    IDataset dataset = (IDataset)featureClass;
    System.out.println("Datatset Name : " + dataset.getName());
    //Alias name.
    System.out.println("Alias Name : " + featureClass.getAliasName());
    String value = "";
    switch (featureClass.getFeatureType()){
        case esriFeatureType.esriFTSimple:
            value = "Simple";
            break;
        case esriFeatureType.esriFTSimpleJunction:
            value = "Simple Junction";
            break;
        case esriFeatureType.esriFTSimpleEdge:
            value = "Simple Edge";
            break;
        case esriFeatureType.esriFTComplexJunction:
            value = "Complex Junction";
            break;
        case esriFeatureType.esriFTComplexEdge:
            value = "Complex Edge";
            break;
        case esriFeatureType.esriFTAnnotation:
            value = "Annotation";
            break;
        case esriFeatureType.esriFTCoverageAnnotation:
            value = "Coverage Annotation";
            break;
        case esriFeatureType.esriFTDimension:
            value = "Dimension";
            break;
        case esriFeatureType.esriFTRasterCatalogItem:
            value = "Raster Catalog Item";
            break;
    }
    System.out.println("Feature Type : " + value);
    // Display the geometry type.
    int shapeFieldIndex = featureClass.findField(featureClass.getShapeFieldName());
    IField field = featureClass.getFields().getField(shapeFieldIndex);
    value = "";
    IGeometryDef geometryDef = field.getGeometryDef();
    switch (geometryDef.getGeometryType()){
        case esriGeometryType.esriGeometryPoint:
            value = "Point";
            break;
        case esriGeometryType.esriGeometryMultipoint:
            value = "Multipoint";
            break;
        case esriGeometryType.esriGeometryPolyline:
            value = "Polyline";
            break;
        case esriGeometryType.esriGeometryPolygon:
            value = "Polygon";
            break;
        case esriGeometryType.esriGeometryMultiPatch:
            value = "MultiPatch";
            break;
    }
    System.out.println("Geometry type : " + value);
    System.out.println("");
    displayFields(featureClass);
}
The DisplayFields function gets the Fields collection from the supplied feature class. The IFields.FieldCount is used in a "for" loop to iterate over all the fields in the collection. Each IField in the collection is then passed into the DisplayFieldInformation function. No information is output from within this function. See the following code example:
[Java]
static void displayFields(IFeatureClass featureClass)throws Exception{
    IFields fields = featureClass.getFields();
    IField field;
    for (int i = 0; i < fields.getFieldCount(); i++){
        field = fields.getField(i);
        displayFieldInformation(field);
    }
}
The last function displayFieldInformation accepts an IField as the argument. The field is then interrogated for its properties. If the GeometryDef returned by the field is not empty, then the GeometryDef's properties are also displayed.
Sample output for a text field would be:
Name : myText
Alias Name : My Text Field
Type : Character string
Length : 50
Precision : 0
Scale : 0
Editable : True
Default Value : HowTo
See the following code example:
A similar approach could be used for the fields domain, however, remember that domains and default values can be applied at the subtype level.
[Java]
static void displayFieldInformation(IField field)throws Exception{
    //Physical name.
    System.out.println("Name : " + field.getName());
    //Alias name.
    System.out.println("Alias Name : " + field.getAliasName());
    //Field type.
    String value = "";
    switch (field.getType()){
        case esriFieldType.esriFieldTypeSmallInteger:
            value = "Small Integer";
            break;
        case esriFieldType.esriFieldTypeInteger:
            value = "Long Integer";
            break;
        case esriFieldType.esriFieldTypeSingle:
            value = "Single-precision floating-point number";
            break;
        case esriFieldType.esriFieldTypeDouble:
            value = "Double-precision floating-point number";
            break;
        case esriFieldType.esriFieldTypeString:
            value = "Character string";
            break;
        case esriFieldType.esriFieldTypeDate:
            value = "Date";
            break;
        case esriFieldType.esriFieldTypeOID:
            value = "Long Integer representing an object identifier";
            break;
        case esriFieldType.esriFieldTypeGeometry:
            value = "Geometry";
            break;
        case esriFieldType.esriFieldTypeBlob:
            value = "Binary Large Object, Blob Storage";
            break;
        case esriFieldType.esriFieldTypeRaster:
            value = "Raster";
            break;
        case esriFieldType.esriFieldTypeGUID:
            value = "Globally Unique Identifier";
            break;
        case esriFieldType.esriFieldTypeGlobalID:
            value = "ESRI Global ID";
            break;
        case esriFieldType.esriFieldTypeXML:
            value = "XML Document";
            break;
    }
    System.out.println("Type : " + value);
    //Field length—this is only valid for fields of Type esriFieldTypeString.
    System.out.println("Length : " + field.getLength());
    //Field precision.
    System.out.println("Precision : " + field.getPrecision());
    //Field scale.
    System.out.println("Scale : " + field.getScale());
    //Editable.
    System.out.println("Editable : " + field.isEditable());
    //Default value.
    System.out.println("Default Value : " + field.getDefaultValue());

    IGeometryDef geomDef = field.getGeometryDef();
    if (geomDef != null){
        System.out.println("GeometryDef Properties");
        System.out.println("AvgNumPoints : " + geomDef.getAvgNumPoints());
        System.out.println("Grid Count : " + geomDef.getGridCount());
        for (int i = 0; i < geomDef.getGridCount(); i++){
            System.out.println("Grid Size[" + i + "]=" + geomDef.getGridSize(i));
        }
        System.out.println("Has Measures : " + geomDef.isHasM());
        System.out.println("Has Z : " + geomDef.isHasZ());
        System.out.println("Spatial Ref : " + geomDef.getSpatialReference().getName()
            );
    }

    System.out.println("");
}


See Also:

How to work with fields




Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine