Esri ArcObjects Snippets - Series
Print values of attributes in Feature Class
//Access values of attributes in fields
static void printDistinctFieldValueNames(IFeatureClass featureClass, String Condition)
throws Exception {
QueryFilter queryFilter = new QueryFilter();
#queryFilter.setWhereClause("Name='Ahmed'");
queryFilter.setWhereClause(Condition);
IFeatureCursor featureCursor = featureClass.search(queryFilter, true);
IFields fields = featureCursor.getFields();
int fieldCount = fields.getFieldCount();
for (int i = 0; i < fieldCount; i++) {
IField fieldI = fields.getField(i);
String fieldName = fieldI.getName();
System.out.print(fieldName + "\t");
}
System.out.println();
IFeature feature = featureCursor.nextFeature();
while (feature != null) {
StringBuffer row = new StringBuffer();
for (int i = 0; i < fieldCount; i++) {
int fieldType = feature.getFields().getField(i).getType();
switch (fieldType) {
case esriFieldType.esriFieldTypeDate:
case esriFieldType.esriFieldTypeDouble:
case esriFieldType.esriFieldTypeGlobalID:
case esriFieldType.esriFieldTypeGUID:
case esriFieldType.esriFieldTypeInteger:
case esriFieldType.esriFieldTypeOID:
case esriFieldType.esriFieldTypeSingle:
case esriFieldType.esriFieldTypeSmallInteger:
case esriFieldType.esriFieldTypeString:
row.append(feature.getValue(i) + "\t");
break;
case esriFieldType.esriFieldTypeBlob:
row.append("(blob)" + "\t");
break;
case esriFieldType.esriFieldTypeGeometry:
row.append("(geometry)" + "\t");
break;
case esriFieldType.esriFieldTypeRaster:
row.append("(raster)" + "\t");
break;
}
}
if (row.length() > 0) {
System.out.println(row);
}
feature = featureCursor.nextFeature();
}
}
This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.
No comments:
Post a Comment