Select to view content in your preferred language

geoprocessor.execute() AutomationException, Java Arcobjects

3700
14
Jump to solution
07-06-2013 01:35 PM
AbdoMel
New Contributor II
Hello everyone, I'm trying to use the "Near" analysis tool and "Map to KML" conversion tools in java but both bring out the same error
AutomationException: 0x80004005 - Unspecified error
at com.esri.arcgis.geoprocessing.GeoProcessor.execute(Unknown Source)

here's the method for the Near analysis tool:-

public void executeNearTool()
   {
    
     try {
      System.out.print("\n**Creating GeoProcessor object...");
     
    GP = new GeoProcessor();
    gpu=new GPUtilities();
    GP.setOverwriteOutput(true);
    System.out.println("done.");
     
  

      System.out.print("\n**Executing GP tool...");
      IFeatureClass infeature=gpu.openFeatureClassFromString("D:/#GP/Construct Shapefile/Construct.shp");
   IFeatureClass innearfeature=gpu.openFeatureClassFromString("D:/#GP/Egypt Power Plant/carma_egypt_power_plant_emissions_egypt_20002007future.shp");
   nearanalysis=new Near(infeature,innearfeature);
  
   GP.execute(nearanalysis,null);    
   System.out.println("done.");
  
  } catch (AutomationException e) {
  
   e.printStackTrace();
  } catch (IOException e) {
  
   e.printStackTrace();
  }

   }

the exception interrputs at the GP.execute() line, can anyone please help me with this?
0 Kudos
14 Replies
LeoDonahue
Regular Contributor
Checking some of my desktop apps, when I use the Append geoprocessing tool, I use FeatureLayer objects as inputs and targets.
0 Kudos
AbdoMel
New Contributor II
Checking some of my desktop apps, when I use the Append geoprocessing tool, I use FeatureLayer objects as inputs and targets.


I can try that, but can you provide me with a sample? when I'm trying to initialize an IFeatureLayer file it calls another automationexception
0 Kudos
LeoDonahue
Regular Contributor
very easy to get a FeatureLayer...

FeatureLayer layer = (FeatureLayer) map.getLayer(i); 

"i" is the layer index position in the map.

ESRI wrote a nice sample method to get layers by name. You pass a layer name string and a map object and you get a FeatureLayer back.


    public FeatureLayer getLayerByName(String layerName, com.esri.arcgis.carto.Map map) {
        FeatureLayer layer = null;
        try {
            for (int i = 0; i < map.getLayerCount(); i++) {
                if (map.getLayer(i).getName().equalsIgnoreCase(layerName)) {
                    layer = (FeatureLayer) map.getLayer(i);
                    break;
                }
            }
        } catch (AutomationException ae) {
            ae.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return layer;
    }


You would call this method like this:

FeatureLayer iparcelFeatureLayer = getLayerByName("Parcels", your-map-variable-here);
0 Kudos
AbdoMel
New Contributor II
I tried it and it can read the layers correctly but still the same error with gp.execute(nearanalysis null);
is there a possibility that the "near" class itself just doesn't work out with geoprocessor? maybe because it adds to the feature's data so I have to make the layer editable first before execution or something
0 Kudos
AbdoMel
New Contributor II
Finally worked after throwing the path to both set methods right away
//
nearanalysis=new Near();
nearanalysis.setInFeatures("D:/#GP/Construct Shapefile/Construct.shp");
nearanalysis.setNearFeatures("D:/#GP/Egypt Power Plant/carma_egypt_power_plant_emissions_egypt_20002007future.shp");
//

I can't thank you enough for your time and help, thank you I was starting to doubt this will ever work
0 Kudos