Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Although I love slinging some python to create geoprocessing scripts/services, I was under the impression that using ArcObjects to do the equivalent operation(s) will have better performance.

I've made one (or two) posts over the past couple of days regarding my woes with getting geoprocessing scripts that use Spatial Analyst tools to work as geoprocessing services. My deadline is fast approaching, so I have decided to go the SOE route to achieve the desired functionality.

Getting a cost path analysis in ArcObjects was relatively straight-forward using the .NET ESRI.ArcGIS.SpatialAnalyst.RasterDistanceOpClass, specifically the CostDistanceFull() and CostPath() Methods.

UPDATE: Some code snippets of how I am doing things:


# Get Cost Path Origin and Destination Points
inputPointsShp = 'D:/RasterStuff/test_points.shp'
arcpy.MakeFeatureLayer_management(inputPointsShp,"origin",' "TYPE" = \'ORIGIN\' ')
arcpy.MakeFeatureLayer_management(inputPointsShp,"destination",' "TYPE" = \'DESTINATION\' ')

# Check out the ArcGIS Spatial Analyst extension license

# Execute CostDistance
outCostDistance = CostDistance("origin",SOURCE_RASTER,"#","backlink")

# Execute CostPath
outCostPath = CostPath("destination", outCostDistance,"backlink")

# Convert Result to Polyline
arcpy.RasterToPolyline_conversion(outCostPath, "leastCostPath")
featSet = arcpy.FeatureSet("leastCostPath")


IDistanceOp distanceOp = new RasterDistanceOpClass();
IRasterBandCollection costDistanceRaster = (IRasterBandCollection)distanceOp.CostDistanceFull((IGeoDataset)sourceFc, (IGeoDataset)raster, true, true, false);
IRasterBand distanceRaster = costDistanceRaster.Item(0);
IRasterBand backLinkRaster = costDistanceRaster.Item(1);

IGeoDataset costPath = distanceOp.CostPath((IGeoDataset)destFc, (IGeoDataset)distanceRaster, (IGeoDataset)backLinkRaster, ESRI.ArcGIS.SpatialAnalyst.esriGeoAnalysisPathEnum.esriGeoAnalysisPathForEachCell);

A cost path analysis in ArcPy (using sa.CostDistance and sa.CostPath) takes approx 15-20 sec. Using the exact same inputs, the ArcObjects based routine takes 55-60 sec. Even using the .NET Geoprocessor is significantly slower than arcpy.

So, I guess my questions here are:

  1. Are the ArcPy and ArcObjects implementations pointing at the same code base (through their Python and .NET wrappers)?
  2. Any tips to optimize ArcObject based Cost Path analysis?
share|improve this question
have you profiled your code to find iut exactly which call is taking the longest? Can you show a code snippet? – Ragi Yaser Burhum Jul 8 '12 at 0:46
My understanding was ArcPy just a wrapper around ArcObjects so that is curious. I dont know if this is relevant but one answer here :… .. Notes that GeoProcessing tools need to load, as compared to GUI tools. So, if ArcPy instantiates the relevant code in advance or wraps a GUI function instead of the ToolBox function, it might skip some set up time. Easy enough to check by seeing if the speed gap reduces with larger datasets. – AnserGIS Mar 29 at 9:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.