Select to view content in your preferred language

Get feature value for the selected feature - Java

3034
2
08-16-2014 10:22 PM
NajdALHanahnah
Occasional Contributor

Dear All

 

I am working now to develop application by using Arcgis Engine 10.1 / Arcobject (Java) , i have connect to personal Geodabase (Mdb)  and i retrieve fields name layer name , fields properties (Geometry , type...) but when i try to retrieve information for the values (attribute value) i got null value .... i need your help to get the value in the fields ?

 

for example if i have (USA.mdb) personal geodatabase , layer name is : country , (fields : county name , country name , area) ....

 

what i need exactly to retrieve the county value from the county field  (California , Colorado... ...)

 

the below the code what i use it ....

 

and what is the different if i read the feature through (MXD file) or direct connect to MDB (personal Geo-database) the code will change or what i need you clarification please ....

 

Thanks

 

IFeatureClass featureClass = featureLayer.getFeatureClass();

System.out.println(">>>+>>>>>"+featureClass.getAliasName());

 

// System.out.println(">>>+>>>>>"+featureClass.getFeatureClassID());

// System.out.println(">>>+>>>>>"+featureClass.getFeatureType());

 

IFields fields = featureClass.getFields();

System.out.print("+++++++++count  " +fields.getFieldCount());

// for (int i =0 ; i< fields.getFieldCount() ;i++){

// System.out.println(fields.getField(i).getName() + " - " + fields.getField(i).getDefaultValue());

// }

//

 

for (int index = 0; index < fields.getFieldCount(); index++) {

//Get the field at the specified index

Field field = (Field) fields.getField(index);

 

if (field == null) {

System.out.println("Field is null ");

continue;

}

 

//Print out some metadata information

System.out.println("\tPhysical Name : " + field.getName());

System.out.println("\tAlias Name    : " + field.getAliasName());

System.out.println("\tType          : " + getFieldTypeDescription(field.getType()));

System.out.println("\tLength        : " + field.getLength());

System.out.println("\tPrecision     : " + field.getPrecision());

System.out.println("\tEditable      : " + field.isEditable());

 

//Default Value

Object defaultValue = field.getDefaultValue();

if (defaultValue == null) {

System.out.println("\tDefault Value : <Unspecified>");

}

else {

System.out.println("\tDefault Value : " + defaultValue);

}

 

System.out.println();

}

0 Kudos
2 Replies
NajdALHanahnah
Occasional Contributor

plz I need your support urgent ....

B.R

0 Kudos
OwenEarley
Frequent Contributor

I have only worked with .Net ArcObjects but this page has some information on working with fields using Java: ArcObjects Help for Java developers

The main difference I can see with your code is that field is declared as Field and not IField:

for (int index = 0; index < fields.getFieldCount(); index++) {

//Get the field at the specified index

Field field = (Field) fields.getField(index);

if (field == null) {

System.out.println("Field is null ");

continue;

}

The ESRI sample on the help page declares field as IField (it is also declared before the for loop):

     // get the Fields collection from the feature class

     IFields fields = featureClass.getFields();

     IField field;

     // on a zero based index iterate through the fields in the collection

     for (int i = 0; i < fields.getFieldCount(); i++){

        // get the field at the given index

       field = fields.getField(i);

       if (!field.getName().equals(field.getAliasName())){

            System.out.println(field.getName() + ":" + field.getAliasName());

       }

     }