katbm

How to add iteration loops to model builder python export.

Discussion created by katbm on Oct 18, 2013
Latest reply on Oct 18, 2013 by LDanzinger-esristaff
Embedded below is my model builder output that needs to be modified.
I am trying to calculate the least cost path for 34 sites to every other site so that I can compile a distance matrix.
The first time I put this model together it calculated the least cost path of each site to itself, consequently I need to add an iteration loop (or two) so that it calculates a least cost path for every site to every other site.
I'm assuming this will need to be done by row, as each site's info is stored with a unique name in each row.
The loop that is in there now isn't doing it correctly. Also model builder won't let me use two iteration loops, hence having to do it in python.
I have never used python, and this is time sensitive so I turn to you friendly GIS community.
Any help at this point is greatly appreciated.
Kat

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# least cost path route py.py
# Created on: 2013-10-16 14:27:53.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Load required toolboxes
arcpy.ImportToolbox("Model Functions")

# Set Geoprocessing environments
arcpy.env.scratchWorkspace = "C:\\Users\\Toshiba\\Documents\\ArcGIS\\ScratchDefault.gdb"
arcpy.env.snapRaster = "MAD_outline_PolygonToRaster1"
arcpy.env.extent = "DEFAULT"
arcpy.env.cellSize = "0.05"
arcpy.env.mask = "MAD_outline"
arcpy.env.workspace = "C:\\Users\\Toshiba\\Documents\\ArcGIS\\Default.gdb"


# Local variables:
glwd_3_mad = "glwd_3_mad"
v10kbuffer_Dest = "10kbuffer_Dest"
v10kbuffer_Orig__2_ = "10kbuffer_Orig"
MDG_msk_alt_vrt = "MDG_msk_alt.vrt"
Reclass_Water = "C:\\Users\\Toshiba\\Desktop\\Dissertation GIS\\Madagascar\\reclglwd3mad"
Weighted_Water = "C:\\Users\\Toshiba\\Desktop\\Dissertation GIS\\Madagascar\\WeightMad"
output_costdistance = "C:\\Users\\Toshiba\\Desktop\\Dissertation GIS\\Madagascar\\MadCostDis"
output_backlink = "C:\\Users\\Toshiba\\Desktop\\Dissertation GIS\\Madagascar\\costbacklink"
leastcostpath = "C:\\Users\\Toshiba\\Desktop\\Dissertation GIS\\Madagascar\\MadCostPath"
DEM_Slope = "C:\\Users\\Toshiba\\Desktop\\Dissertation GIS\\Madagascar\\SlopeMDGms1"
Reclass_Slope = "C:\\Users\\Toshiba\\Documents\\ArcGIS\\Default.gdb\\Reclass_Slop1"

# Process: Reclassify Barriers
arcpy.gp.Reclassify_sa(glwd_3_mad, "VALUE", "1 1.8888888888888888 10;1.8888888888888888 2.7777777777777777 10;2.7777777777777777 3.6666666666666665 10;3.6666666666666665 4.5555555555555554 0;4.5555555555555554 5.4444444444444446 0;5.4444444444444446 6.3333333333333339 0;6.3333333333333339 7.2222222222222232 0;7.2222222222222232 8.1111111111111125 0;8.1111111111111125 9 0", Reclass_Water, "DATA")

# Process: Slope
arcpy.gp.Slope_sa(MDG_msk_alt_vrt, DEM_Slope, "DEGREE", "1")

# Process: Reclassify Slope
arcpy.gp.Reclassify_sa(DEM_Slope, "Value", "0 17.999148559570312 1;17.999148559570312 35.998297119140624 2;35.998297119140624 53.997445678710932 3;53.997445678710932 71.996594238281247 4;71.996594238281247 89.995742797851563 5", Reclass_Slope, "DATA")

# Process: Weighted Overlay
arcpy.gp.WeightedOverlay_sa("('C:\\Users\\Toshiba\\Desktop\\Dissertation GIS\\Madagascar\\reclglwd3mad' 66 'VALUE' (0 1; 10 10;NODATA NODATA); 'C:\\Users\\Toshiba\\Documents\\ArcGIS\\Default.gdb\\Reclass_Slop1' 34 'VALUE' (1 1; 2 2; 3 3; 4 4; 5 5;NODATA NODATA));1 10 1", Weighted_Water)

# Process: Cost Distance
arcpy.gp.CostDistance_sa(v10kbuffer_Orig__2_, Weighted_Water, output_costdistance, "", output_backlink)

# Process: Cost Path
arcpy.gp.CostPath_sa(v10kbuffer_Dest, output_costdistance, output_backlink, leastcostpath, "EACH_CELL", "POINTID")

# Process: Iterate Field Values
arcpy.IterateFieldValues_mb(v10kbuffer_Orig__2_, "POINTID", "String", "true", "false", "1")

Outcomes