Sie sind auf Seite 1von 2

#!

/user/local/bin/python

# ---------------------------------------------------------------------------
# best_route_guide.py
# Created on: 2018-12-26 22:08:21.00000
# (Created by: Gustavo Colmenares)
# Description:
# ---------------------------------------------------------------------------
# import modules
import arcpy
import os
from arcpy.sa import *

# set Geoproccesing environments


arcpy.env.workspace = r"C:\Users\ Documents\ GIS_PCC\GEO 266-GIS Analysis\Stowe_copy.gdb"
arcpy.env.overwriteOutput = True
out_path = r"C:\Users\ Documents \GIS_PCC\GEO 266-GIS Analysis \Scratch_copy.gdb"
arcpy.env.extent = "elevation"
arcpy.env.cellSize = "30"

# check (3d & spatial) extensions for spatial analysis


arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("spatial")

# Reclassify variables
slope = os.path.join(out_path, "Slope_out")
remap_slope = RemapRange([[0, 4.779894, 1],
[4.779894, 9.559789, 2],
[9.559789, 14.339683, 3],
[14.339683, 19.119577, 4],
[19.119577, 23.899471, 5],
[23.899471, 28.679366, 6],
[28.679366, 33.459260, 7],
[33.459260, 38.239154, 8],
[38.239154, 43.019048, 9],
[43.019048, 47.798943, 10]
])

reclassed_slope = os.path.join(out_path, "Reclassed_slope")

# WeightedOverlay variables
landuse = "landuse"
weighted_remap_slope = RemapValue([[1, 1],
[2, 2],
[3, 3],
[4, 4],
[5, 5],
[6, 6],
[7, 7],
[8, 8],
[9, 9],
[10, 10],
["NODATA", "NODATA"]
])

weighted_remap_landuse = RemapValue([['Brush/transitional', 5],


['Water', 10],
['Barren land', 2],
['Built up', 9],
['Agriculture', 4],
['Forest', 8],
['Wetlands', 10],
["NODATA", "NODATA"]
])
eva_scl = [1, 10, 1]
cost_surface = os.path.join(out_path, "Cost_Surface")

# Cost distance variables


final_site = os.path.join(out_path, "final_site")
out_backlink_raster = os.path.join(out_path, "cost_bklink")
cost_distance_final = os.path.join(out_path, "CostDis_final")
# Cost path variables
destination = "destination"
out_cost_path = os.path.join(out_path, "Out_CostPath")
dest_field = "ID"

# Raster to polyline variables


new_route = os.path.join(out_path, "New_Route")

#-*-------------------*-------------
print(""" Starting process to find best route... """)
#
## Reclassification Process
out_reclass_slope = Reclassify(slope, "value", remap_slope)
out_reclass_slope.save(reclassed_slope)
print("reclass slope completed")
#
# Weighted Overlay process
"""
The WeightedOverlay() tool is returning message > Failed to execute. Parameters are not valid. ERROR 010531: The sum of % Influence Weights must equal
100.
to overcome to this error I decided to run the tool on Arc and use the resulting layer (Cost_Surface) in the script to continue...
"""
# WoTable
# try:
# myWOTable = WOTable([[reclassed_slope, 50, "VALUE", weighted_remap_slope],
# [landuse, 50, "VALUE", weighted_remap_landuse]],
# [eva_scl])
#
# print("myWOTable created")
# print(myWOTable)
# # Process: Weighted Overlay
# weighted_overlay = WeightedOverlay(myWOTable)
# weighted_overlay.save(cost_surface)
# except:
# print(arcpy.GetMessages())

# Cost Distance process


cost_distance = CostDistance(final_site, cost_surface, "", out_backlink_raster)
cost_distance.save(cost_distance_final)
print("Cost distance completed")
#
# Cost path process
cost_path = CostPath(destination, cost_distance_final, out_backlink_raster, "EACH_CELL", "ID")
cost_path.save(out_cost_path)
print("Cost path completed")

# Raster to Polyline process


raster_polyline = arcpy.RasterToPolyline_conversion(out_cost_path, new_route, "ZERO", 0, "SIMPLIFY", "VALUE")

print("completed new route ")

Das könnte Ihnen auch gefallen