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:
So, I guess my questions here are:
أكثر...
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:
Python
# Get Cost Path Origin and Destination PointsinputPointsShp = '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 licensearcpy.CheckOutExtension("Spatial")# Execute CostDistanceoutCostDistance = CostDistance("origin",SOURCE_RASTER,"#","backlink")# Execute CostPathoutCostPath = CostPath("destination", outCostDistance,"backlink")# Convert Result to Polylinearcpy.RasterToPolyline_conversion(outCostPath, "leastCostPath")featSet = arcpy.FeatureSet("leastCostPath")
C#
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:
- Are the ArcPy and ArcObjects implementations pointing at the same code base (through their Python and .NET wrappers)?
- Any tips to optimize ArcObject based Cost Path analysis?
أكثر...