Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ---------------------------------------------------------------------------
- # Final.py
- # Created on: 5/12/2014
- # Created by: Noah C. Huntington
- # Copyright: Furman Land Surveyors, Inc. 2014 - (806)374-4246
- # Description: Calculates Multiple Least Cost Paths Between Substations
- # ---------------------------------------------------------------------------
- # Import modules
- import arcpy
- import os
- from arcpy import env
- arcpy.env.overwriteOutput = 1
- from arcpy.sa import *
- import math
- # Check out any necessary licenses
- arcpy.CheckOutExtension("Spatial")
- # Declare variables for tool parameters
- subs = arcpy.GetParameterAsText(0)
- Field = arcpy.GetParameterAsText(1)
- originValue = arcpy.GetParameterAsText(2)
- destValue = arcpy.GetParameterAsText(3)
- lines = arcpy.GetParameterAsText(4)
- Dem = arcpy.GetParameterAsText(5)
- landuse = arcpy.GetParameterAsText(6)
- wells = arcpy.GetParameterAsText(7)
- savepath = arcpy.GetParameterAsText(8)
- # Weights applied to criteria
- slope_Weight = 10
- landuse_weight = 90
- count = 0
- # Set Geoprocessing environments
- arcpy.env.cellSize = 90
- ws = arcpy.env.workspace = savepath + '\\Scratch.gdb'
- sr = arcpy.SpatialReference(2275)
- '''
- subs = r"G:\Xcel\Route Tool\Southwest\Data.gdb\Subs_4201"
- Field = "Name"
- originValue = "Hillside"
- destValue = "Coulter"
- lines = r"G:\Xcel\Route Tool\Southwest\Data.gdb\OLS_Lines_Proj"
- Dem =r"G:\Xcel\Route Tool\Southwest\Data.gdb\Dem_4201"
- landuse = r"G:\Xcel\Route Tool\Southwest\Data.gdb\lu_4201"
- wells = r"G:\Xcel\Route Tool\Southwest\Data.gdb\wells_4201"
- savepath = r"G:\Xcel\Route Tool\Southwest\Hillside"
- '''
- # --------------------------------------------------------------------------------------
- # Functions and variables for savepaths are declared in this section
- # Dynamic path for out polylines
- # --------------------------------------------------------------------------------------
- Output_polyline = os.path.join(savepath + "\\Results.gdb" + "\\LCP_" + chr(count + 65))
- def get_backlink(count):
- return os.path.join(savepath + "\\Scratch.gdb" + "\\backlink_" + str(count))
- def get_LCP(count):
- return os.path.join(savepath + "\\Scratch.gdb" + "\\LCP_" + chr(count + 65))
- def get_costRaster(count):
- return os.path.join(savepath + "\\Scratch.gdb" + "\\cost_Raster_" + str(count))
- def get_weighted_Raster(count):
- return os.path.join(savepath + "\\Scratch.gdb" + "\\weighted_Raster_" + str(count))
- # -----------------------------------------------------------------------------------
- # This function retrieves the coordinates of the endpoints
- # It is called for during the while loop while running extractbypoints
- # -----------------------------------------------------------------------------------
- def get_Coordinates():
- #Create SQL statement
- where_clause_envelope = "\"{}\" = '{}'" "or " "\"{}\" = '{}'".format(Field,originValue,Field,destValue) #produces: "Name" = 'Amarillo 34th St'or "Name" = 'Coulter
- #Create temp layer for origin and destination
- Ends = os.path.join(savepath + "\\Scratch.gdb" + "\\Ends_" + str(count))
- Ends_fl = arcpy.MakeFeatureLayer_management(subs, Ends, where_clause_envelope)
- fields = ["SHAPE@X","SHAPE@Y"]
- cursor = arcpy.da.SearchCursor(Ends_fl, fields)
- record1 = next(cursor)
- record2 = next(cursor)
- x1 = record1[0]
- x2 = record2[0]
- y1 = record1[1]
- y2 = record2[1]
- pointList = [arcpy.Point(x1, y1),
- arcpy.Point(x2,y2)]
- return pointList
- def get_buffer_Distance():
- # This function determines the buffer distance
- # which is performed in order to determine study area before undergoing raster processing
- #Create SQL Statement
- where_clause_envelope = "\"{}\" = '{}'" "or " "\"{}\" = '{}'".format(Field,originValue,Field,destValue)#produces: "Name" = 'Amarillo 34th St'or "Name" = 'Coulter
- #Create temp layer for origin and destination
- Points = arcpy.MakeFeatureLayer_management(subs, "Subs_Selection", where_clause_envelope)
- Line = arcpy.PointsToLine_management(Points, arcpy.Geometry(),"","","NO_CLOSE")
- length = 0
- for geometry in Line:
- length += geometry.length
- miles = length/5280
- if miles > 10:
- Buffer = 20*5280
- else:
- Buffer = length*2
- return Buffer
- # --------------------------------------------------------------------------------------
- # This is the main section of the tool
- #
- # --------------------------------------------------------------------------------------
- def main():
- count = 0
- arcpy.CreateFileGDB_management(savepath, "Scratch.gdb")
- arcpy.CreateFileGDB_management(savepath, "Results.gdb")
- arcpy.AddMessage("Data will be saved to: {0}" .format(ws))
- #Create SQL statement
- where_clause_envelope = "\"{}\" = '{}'" "or " "\"{}\" = '{}'".format(Field,originValue,Field,destValue)#produces: "Name" = 'Amarillo 34th St'or "Name" = 'Coulter
- #Create temp layer for origin and destination
- subset = arcpy.MakeFeatureLayer_management(subs, "Subs_Selection", where_clause_envelope)
- #Create extent polygon from selected subs
- arcpy.AddMessage("Computing Extents...")
- arcpy.MinimumBoundingGeometry_management(subset, "Subs_Env", "", "ALL")
- #Buffer the envelope
- arcpy.AddMessage("Buffering Extent Polygon...")
- Buffer = get_buffer_Distance()
- arcpy.Buffer_analysis("Subs_Env", "Envelope_Buffer", str(Buffer) + " Feet", "FULL", "ROUND", "ALL", "")
- ....
Add Comment
Please, Sign In to add comment