AnsweredAssumed Answered

looping through shapefile attribute table - java

Question asked by bvarela on Aug 8, 2012
Latest reply on Aug 14, 2012 by bvarela
I am new to arcobjects and GIS in general so excuse my noobness.  I'm trying to create a console based application that eventually will raster some polygons then do some stats on the rasters but right now I just want to be able to list all the features?(a single attribute from a layer's attribute table) from a given layer/shapefile in an existing mxd.  Right now, I can initialize the arc engine, open an mxd, list all the layers within that mxd and open a shapefile from a layer within the mxd.

What I need help with is being able to loop through the attribute table for the shapefile I opened from the mxd.

Here is the code I have so far:

public class EngineTest {     @SuppressWarnings("deprecation")  public static void main(String[] args)     {         try         {             //Step 1: Initialize the Java Componet Object Model (COM) Interop.             EngineInitializer.initializeEngine();              //Step 2: Initialize a valid license.             new AoInitialize().initialize                 (esriLicenseProductCode.esriLicenseProductCodeEngine);              //Step 3 : Invoke ArcObjects.             MapDocument mapDocument = new MapDocument();              if (mapDocument.isPresent("D:\\Tellus_Sedimentary_Basin.mxd"))             {  "D:\\Tellus_Sedimentary_Basin.mxd","");            mapDocument.setAuthor("Brian Varela");            IMap main_map = mapDocument.getMap(0);            IFeatureLayer layer = (IFeatureLayer) main_map.getLayer(0);            IFeatureClass classLayer = layer.getFeatureClass();            IDataLayer2 dataLayer = (IDataLayer2) layer;            IDatasetName name = (IDatasetName) dataLayer.getDataSourceName();            IWorkspaceName workspace = name.getWorkspaceName();            ListLayers((Map)mapDocument.getMap(0));            System.out.println("Layer "+layer.getName()+" located at "+workspace.getPathName()+" "+layer.getDisplayField());             }           }         catch (IOException ex)         {             System.out.println(ex.getMessage());             System.out.println("App failed.");         }         finally         {             try             {                 //Step 4: Release the license.                 new AoInitialize().shutdown();                 System.out.println("License released!");             }             catch (IOException ex)             {                 ex.printStackTrace();             }         }     } //End of method main.  public static void ListLayers(com.esri.arcgis.carto.Map map) {  try{   for(int i=0; i<map.getLayerCount(); i++)   {    System.out.println("Layer "+i+". "+map.getLayer(i).getName());   }  }catch(AutomationException ae)  {   ae.printStackTrace();  }catch(IOException e)  {   e.printStackTrace();  } }  } //End of class