The following script uses the function viewshed2 and works without problems:
import arcpy
from arcpy.sa import *
import os
import datetime
#Input parameters
location = arcpy.GetParameterAsText(0)
antenna_height = arcpy.GetParameterAsText(1)
maximum_reach = arcpy.GetParameterAsText(2)
#Folder where the script is
script_folder = sys.path[0]
working_folder = os.path.normpath(os.path.join(sys.path[0], '..'))
#Input variables
fc_Opt_Prospect = os.path.join(working_folder, 'Optimity_Equipment.gdb', 'Optimity_Prospect')
fc_London_Bldngs = os.path.join(working_folder, 'London_Building.gdb', 'London_Buildings')
DSM_model = os.path.join(working_folder, 'Data4Optimimty\ESRI_UK_Bluesky_DSM\ESRI_UK_Bluesky_DSM.gdb', 'DSM_25cm_2015')
fc_Market_Data_2017 = os.path.join(working_folder, 'Data4Optimimty\ESRI_UK_Market_Location_11_2017\Esri_UK_Market_Location_Addresses_11_2017.gdb', 'Market_Location_Addresses_11_2017')
#Selecting new prospect
arcpy.MakeFeatureLayer_management(fc_Opt_Prospect, 'fl_Opt_Prospect')
#Adding default values to fields
arcpy.CalculateField_management ('fl_Opt_Prospect', 'OFFSETA', antenna_height)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'OFFSETB', 0)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'AZIMUTH1', 0)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'AZIMUTH2', 360)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'VERT1', 1)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'VERT2', -16)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'RADIUS1', 0)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'RADIUS2', maximum_reach)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'ESTATE', "\"Prospect\"")
arcpy.AddSurfaceInformation_3d('fl_Opt_Prospect', DSM_model, 'Z', 'BILINEAR')
arcpy.CalculateField_management ('fl_Opt_Prospect', 'OFFSETC', "!Z! + !OFFSETA!")
#Calculating viewshed
VS2_agl_raster = os.path.join(working_folder, 'Optimity_Temp.gdb', location + '_Viewshed_AGL_Raster')
VS2 = Viewshed2(in_raster=DSM_model, in_observer_features='fl_Opt_Prospect', out_agl_raster=VS2_agl_raster, analysis_type='FREQUENCY', refractivity_coefficient=0.13, surface_offset=0, observer_offset='OFFSETA', inner_radius='RADIUS1', outer_radius='RADIUS2', outer_radius_is_3d='3D', horizontal_start_angle='AZIMUTH1', horizontal_end_angle='AZIMUTH2', vertical_upper_angle='VERT1', vertical_lower_angle='VERT2', analysis_method="PERIMETER_SIGHTLINES")
However, when I place the geodatabase 'Optimity_Temp' within a folder (the reason I'm doing this is because I intend to move all my geodatabases to a folder called 'DATA'), the script stops working:
#Import geoprocessing.
import arcpy
from arcpy.sa import *
import os
import datetime
#Input parameters
location = arcpy.GetParameterAsText(0)
antenna_height = arcpy.GetParameterAsText(1)
maximum_reach = arcpy.GetParameterAsText(2)
#Folder where the script is
script_folder = sys.path[0]
working_folder = os.path.normpath(os.path.join(sys.path[0], '..'))
#Input variables
fc_Opt_Prospect = os.path.join(working_folder, 'DATA\Optimity_Equipment.gdb', 'Optimity_Prospect')
fc_London_Bldngs = os.path.join(working_folder, 'DATA\London_Building.gdb', 'London_Buildings')
DSM_model = os.path.join(working_folder, 'DATA\Data4Optimimty\ESRI_UK_Bluesky_DSM\ESRI_UK_Bluesky_DSM.gdb', 'DSM_25cm_2015')
fc_Market_Data_2017 = os.path.join(working_folder, 'DATA\Data4Optimimty\ESRI_UK_Market_Location_11_2017\Esri_UK_Market_Location_Addresses_11_2017.gdb', 'Market_Location_Addresses_11_2017')
#Selecting new prospect
arcpy.MakeFeatureLayer_management(fc_Opt_Prospect, 'fl_Opt_Prospect')
#Adding default values to fields
arcpy.CalculateField_management ('fl_Opt_Prospect', 'OFFSETA', antenna_height)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'OFFSETB', 0)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'AZIMUTH1', 0)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'AZIMUTH2', 360)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'VERT1', 1)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'VERT2', -16)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'RADIUS1', 0)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'RADIUS2', maximum_reach)
arcpy.CalculateField_management ('fl_Opt_Prospect', 'ESTATE', "\"Prospect\"")
arcpy.AddSurfaceInformation_3d('fl_Opt_Prospect', DSM_model, 'Z', 'BILINEAR')
arcpy.CalculateField_management ('fl_Opt_Prospect', 'OFFSETC', "!Z! + !OFFSETA!")
#Calculating viewshed
VS2_agl_raster = os.path.join(working_folder, 'DATA\Optimity_Temp.gdb', location + '_Viewshed_AGL_Raster')
VS2 = Viewshed2(in_raster=DSM_model, in_observer_features='fl_Opt_Prospect', out_agl_raster=VS2_agl_raster, analysis_type='FREQUENCY', refractivity_coefficient=0.13, surface_offset=0, observer_offset='OFFSETA', inner_radius='RADIUS1', outer_radius='RADIUS2', outer_radius_is_3d='3D', horizontal_start_angle='AZIMUTH1', horizontal_end_angle='AZIMUTH2', vertical_upper_angle='VERT1', vertical_lower_angle='VERT2', analysis_method="PERIMETER_SIGHTLINES")
It throws the following error:
Traceback (most recent call last):
File "C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\Arcpy_Scripts\Viewshed_MarketData.py", line 45, in <module>
VS2 = Viewshed2(in_raster=DSM_model, in_observer_features='fl_Opt_Prospect', out_agl_raster=VS2_agl_raster, analysis_type='FREQUENCY', refractivity_coefficient=0.13, surface_offset=0, observer_offset='OFFSETA', inner_radius='RADIUS1', outer_radius='RADIUS2', outer_radius_is_3d='3D', horizontal_start_angle='AZIMUTH1', horizontal_end_angle='AZIMUTH2', vertical_upper_angle='VERT1', vertical_lower_angle='VERT2', analysis_method="PERIMETER_SIGHTLINES")
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 7615, in Viewshed2
analysis_method)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\Functions.py", line 7594, in Wrapper
analysis_method)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000875: Output raster: .\Optimity_Temp.gdb\Viewshe_DSM_25c1.tif's workspace is an invalid output workspace.
ERROR 000581: Invalid parameters.
Failed to execute (Viewshed2).
Failed to execute (ViewshedManyPointsCombinedMarketData).
I find this really odd. Any ideas what could be causing the error?
.\Optimity_Temp.gdb\Viewshe_DSM_25c1.tif
VS2_agl_raster
before using it in Viewshed2 which is complaining about the value it is being given.arcpy.env.scratchWorkspace
to a folder.