What I have:
- 1/3 Arc Second DEM for the extent of my AOI
- Feature class containing ~16 observers with fields for 'observer_offset,' 'outer_radius,' 'horizontal start angle,' and 'horizontal end angle'
What I am trying to accomplish:
- Create an individual single-band geodesic viewshed for each individual observer in the feature class in tif format.
What I am attempting to use:
- Viewshed2() in ArcGIS Pro 3.0.3
Code I am attempting to write:
import arcpy
from arcpy import env
from arcpy.sa import *
# set local variables
inRaster = r"phase_2\phase_2_dem"
inObservers = r"C:\Users\Austin\OneDrive\Documents\SynthosGIS\Geolinks\geolinks_fullrun\geolinks_fullrun\geolinks_fullrun.gdb\test_test_test"
var = None
analysisType = "FREQUENCY"
verticalError = "0 meters"
outAnalysisRelationTable = None
refractCoeff = 0.13
surfaceOffset = "0 meters"
observerElevation = None
observerOffset = "observer_off"
innerRadius = None
innerIs3D = "GROUND"
outerRadius = "Tower_Range_"
outerIs3D = "GROUND"
horizStartAngle = "hor_start_angle"
horizEndAngle = "hor_end_angle"
vertUpperAngle = 90
vertLowerAngle = -90
analysisMethod = "ALL_SIGHTLINES"
with arcpy.da.SearchCursor(inObservers, ['Account_Name']) as vwshd_itterator:
for row in vwshd_itterator:
account = str(row[0])
query = f"Account_Name = '{account}'"
arcpy.SelectLayerByAttribute_management(inObservers, "NEW_SELECTION", query)
out_raster = arcpy.sa.Viewshed2(inRaster, inObservers, var, analysisType,
verticalError, outAnalysisRelationTable, refractCoeff,
surfaceOffset, observerElevation, observerOffset,
innerRadius, innerIs3D, outerRadius, outerIs3D,
horizStartAngle, horizEndAngle, vertUpperAngle,
vertLowerAngle, analysisMethod)
out_raster.save(r"C:\Users\Austin\OneDrive\Documents\SynthosGIS\Geolinks\geolinks_fullrun\geolinks_fullrun\vwshd_" + account + ".tif")
What I Need:
- This is the first time that I have used both the Viewshed2 script and the DA SearchCursor function. I am not sure if I have integrated the two functions correctly, or what I will need to do make it run. As I type, I won't be able to try out any scripts for a couple days as I am away from my workstation. Any input to this script, so that I can hit the ground running when I get back?
Update 1: RESOLVED
- I have updated the code to what is currently showing. I am currently running into an issue with the query for the selection in the for loop. Am I implementing the f-string incorrectly?
Update 2: UNRESOLVED
- I have achieved a function that will run. However, the select by attribute function does not appear to be looping through features individually. Instead it selects all features on the layer at once and is creating a separately named file reprocessing the same viewshed over and over again.
input_feature_class
inside the loop at all.oidList = [r[0] for arcpy.da.SearchCursor(inObservers, ['OID@'])]
... The OID column is different by source datatype, so it might be""""FID" = {:d}""".format(s)