I have working Java code for an intersect:

gp = new GeoProcessor();    
Intersect newintersect = new Intersect();
String in = "(" + srcShapefilePath + "\\polygon.shp; " + srcShapefilePath + "\\lines.shp)";
newintersect.setOutFeatureClass(srcShapefilePath + "\\result2.shp");

How can I pass Geometry or feature class instead of shapefile. I want to use gp.execute instead of gp.executeASync.

executeASync creates an output shapefile, but I don't want to create a shapefile, I want to make some analysis on the result. Any ideas?

  • Running the Intersect tool as execute or executeASync makes no difference the output of the tool is a Feature Class. If you look at the Help file and the Syntax table of this tool it states the output is a Feature Class data type. – Hornbydd Feb 4 '15 at 10:36
  • Yes i saw that but when i tried "executeASync" i got the output shape file in the path,, but with "execute" no shape file as output,, any way i want to catch the resut feature class,, how can i do that? – mashhour darweish Feb 4 '15 at 10:50
  • The GeoProcessor returns an object called IGeoProcessorResult, you can use that to interrogate the output. – Hornbydd Feb 4 '15 at 11:19
  • thanks for your time @Hornbydd . i use the IGeoProcessorResult and i get a String as the Return Object. maybe cause i pass shape file as output parameter, and here my point i want to intersect a shapefile with fetaureclass and get as result a fetaureclass object,, or geometry.. my problem in the Input and the output,, my code works only for shape files – mashhour darweish Feb 4 '15 at 11:34

Geoprocessing tasks by definition generates a new shapefile or feature class. That's why you always give them a "out" parameter. They run mostly as blackboxes, without letting you to interfere in the middle.

As other people suggested in the comments, one of the approaches is to open the feature class that was generated, after your command returns (if async) or right after it's execution (sync). I'll need to open your feature class and make queries around it.

Depending on the task that's being carried out, I really really prefer to not use geoprocessing tasks for this type of work.

For instance, you can calculate a intersection between two geometries with ArcObjects (since I never developed ArcObjects with Java, I'm not sure if it's available - but my guess is that it is):


IPolygon poly = CreatePolygonFunction() // imagine that this function creates a polygon that starts on 0,0 and follows to 0,1, 1,1, 1,0 and closes at 0,0
IPoint point = new PointClass();

ITopologicalOperator op = (ITopologicalOperator)poly;
IGeometry intersection = op.Intersect(point, esriGeometryDimension.esriGeometry0Dimension);

The last line of the code will give you an intersection between a polygon and a point. I specified 0 dimension on the second parameter because an intersection between a point and a polygon is always a point.


If these interfaces are not available on Java, I suggest that you take the simple approach, open up the result of your intersect geoprocessing task, and investigate it accordingly.

  • i did it as you adviced me, and it works, Thanks Alot – mashhour darweish Feb 5 '15 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.