geoprocessor.execute() AutomationException, Java Arcobjects

3439
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
1 Solution

Accepted Solutions
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

View solution in original post

0 Kudos
14 Replies
LeoDonahue
Occasional Contributor III
That error means that you are not referencing your infeature and innearfeature correctly.

If you are using Java, for starters you should be using the backslash character and two of them, such as: c:\\test.shp
0 Kudos
AbdoMel
New Contributor II
ldonahue, thanks for your reply.
Unfortunately I modified the code as so and it still brings out the same error

//
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");
//

I couldn't find online anyone trying to implement the near toolbox in a java application and my entire graduation project is dependent on it :confused:
0 Kudos
LeoDonahue
Occasional Contributor III
Two things.

What is the reason for the # character in your path?

Are shapefiles really featureclasses?  Are they meant to be used by "openFeatureClassFromString()" ?

edit:  you would have to use a ShapefileWorkspaceFactory and Workspace to get the shapefile into a featureclass.
0 Kudos
AbdoMel
New Contributor II
the # is just a symbol i'm used to name with to put a folder at the top

also I couldn't understand completely the difference between a feature class and a dataset, the folder "construct shapefile" for example has not only construct.shp, there is a .dbf , .prj, .sbn, .sbx, .xml and a .shx file with the same name "construct"
0 Kudos
LeoDonahue
Occasional Contributor III
What if you take off the .shp extension in your code?

Not really related to what you are doing, but does point out the extension is not needed.

From the online help

Open a shapefile In the following code example, the .shp file extension is not used when specifying the name of the shapefile to open: 
ShapefileWorkspaceFactory wsf = new ShapefileWorkspaceFactory(); 
Workspace work = new Workspace(wsf.openFromFile(location, 0)); 
IFeatureClass featureClass = work.openFeatureClass("NameOfYourShapefile");       
0 Kudos
AbdoMel
New Contributor II
tried that and still the same error, I also tried changing the data type from IFeatureClass to IDataset and still the same error
0 Kudos
LeoDonahue
Occasional Contributor III
have you tried removing the # character from your directory path?
0 Kudos
AbdoMel
New Contributor II
I tried adding this

//
System.out.println(infeature.getBrowseName());
//

and at first it didn't show anything, I changed it back to the one slash / and it showed "Construct", so it is indeed reading the files from that directory correctly, I think the problem is with the geoprocessor object itself but I don't know
0 Kudos
LeoDonahue
Occasional Contributor III
Well, you can know for sure if you put a stop point on the line that is reading your inFeature and then in debug, step through the code.

This line may be the problem:  nearanalysis=new Near(infeature,innearfeature);

However, if the infeature and innearfeature are not anything valid, you are essentially passing junk to the geoprocessing Near tool.
0 Kudos