Select to view content in your preferred language

Crashing on arcpy.sa.PathAllocation

806
2
10-01-2012 05:31 AM
DanRosauer
Deactivated User
Hi

I hope one of you can help me...

In a for loop, my code selects in turn, a different set of points in a layer.

It then runs PathAllocation for the selected points, as follows:

    if Distance_method == "model-cost": 
        ## calculates the least cost distance to the nearest lineage point
        ## the result is written directly to lineage_dist_gridname
        temp = arcpy.sa.PathAllocation(in_source_data="lin_lyr", in_cost_raster=maxent_model, out_distance_raster=lineage_dist_gridname)    
        lin_dist = arcpy.sa.Raster(lineage_dist_gridname)
        layers_to_delete.append(lineage_dist_gridname)


The problem is that it always fails the second time the loop hits the PathAllocation line.  The message is: python.exe has stopped working.

This behavior is independent of the particular data selected on that iteration - I've tried changing the dataset, and the order, and it still fails on the second pass through the loop.

The filename defined in lineage_dist_gridname is different on each iteration, so it is not a problem of overwriting the raster created on the first iteration.

Has anyone hit a similar crash or has some idea about the cause?

many thanks
Dan
Tags (2)
0 Kudos
2 Replies
curtvprice
MVP Alum
I think it's safer to use positional parameters like they do in the help, instead of names.
The arcpy.sa functions return a raster object. So, maybe something like this using PathDistance will work better?

from arcpy.sa import *
    if Distance_method == "model-cost": 
        ## calculates the least cost distance to the nearest lineage point
        ## the result is written directly to lineage_dist_gridname
        distRaster = PathDistance(Raster("lin_lyr"),maxent_model)
        distRaster.save(lineage_dist_gridname)
0 Kudos
DanRosauer
Deactivated User
Thanks Curtis, that worked nicely.   I thought that pathdistance wouldn't do what I needed, but it does, it's simpler, and it works 🙂
0 Kudos