Dear ESRI developers,
We are developing a simple AddIn for arcMap for the first time using arcObjects in java. The application consists basically on the following steps:
We are asking for your help because we have computation time problems with the step 5. There are more than 27000 lines or edges. To update the color of the lines representing edges we have tried the following strategies:
The process A takes almost 3 minutes and the process B takes almost 2 minutes. This is without using any type of parallelization.
Measuring the computation time for the method A the slow action is to update the rows of the FeatureClass (6 milliseconds per feature). I tried the update cursor and the search cursor with similar results.
Measuring the computation time for the method B the slow action is to assign the symbol to the Line element (5 milliseconds per element).
We think the problem is that there are many communications with the arcMap framework. So if you have any idea how this process can be speeded up it would be very helpful. We’d like this refreshing process can be performed as fast as possible… Maybe 10 seconds? Do you think it is possible?
Thank you very much for your help.
For option A make sure to use a feature buffer when creating a feature class. Look for any ArcObjects Java documentation on IFeatureBuffer (com.esri.arcgis.geodatabase.IFeatureBuffer).
I have not done this in Java but in .Net it is orders of magnitude faster. The 3 minute process will probably take several seconds using a feature buffer.
Thank you for your help. Currently I'm deleting all the features and inserting them again using a feature buffer, like this:
lines.deleteSearchedRows(null);
IFeatureClass featureClass = lines.getFeatureClass();
IFeatureCursor cursor = featureClass.IFeatureClass_insert(true);
int costIndex = featureClass.findField("Distance");
IFeatureBuffer featureBuffer = featureClass.createFeatureBuffer();
for(LineInfo lineInfo:coords) {
Coord cF = lineInfo.cF;
Coord cT = lineInfo.cT;
double fCost = cF.equals(c)?0:algo.getCost(cF);
double tCost = cT.equals(c)?0:algo.getCost(cT);
double cost = (fCost+tCost)/2;
featureBuffer.setShapeByRef(lineInfo.p);
featureBuffer.setValue(costIndex, cost);
cursor.insertFeature(featureBuffer);
}
cursor.flush();
Cleaner.release(cursor);
Where "lines" is the Feature Layer. Do you see a problem with this code? should it be faster? Thank you again
One thing that I can see is that you should flush the feature buffer at regular intervals. You code is adding all of the features to the feature buffer and then writing them only once at the end of the function.
Try flushing the buffer at regular intervals for example (pseudo code only as I am not too familiar with Java):
int i = 0;
...
for(LineInfo lineInfo:coords) {
...
cursor.insertFeature(featureBuffer);
c += 1;
if (c == 100){
// flush cursor and reset counter
cursor.flush();
c = 0;
}
}
// final flush for remaining features
cursor.flush();
...
Hope this helps.
Thank you!
I tested flushing the cursor at different intervals without changes in the total time:
int num = 0;
JOptionPane.showMessageDialog(jPanel, coords.size()+" links to update");
for(LineInfo lineInfo:coords) {
Coord cF = lineInfo.cF;
Coord cT = lineInfo.cT;
double fCost = cF.equals(c)?0:algo.getCost(cF);
double tCost = cT.equals(c)?0:algo.getCost(cT);
double cost = (fCost+tCost)/2;
featureBuffer.setShapeByRef(lineInfo.p);
featureBuffer.setValue(costIndex, cost);
cursor.insertFeature(featureBuffer);
if(++num%100==0)
cursor.flush();
}
cursor.flush();
Cleaner.release(cursor);
Did you end up getting a reduction in your total processing time?
No... I've not gotten any reduction in the processing time... it seems the implementation of the FeatureBuffer in java is not optimized, or it has not been implemented yet?
I haven't used ArcObjects via Java but I would be very surprised if the FeatureBuffer had not been implemented.