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?
1 Answer 1
You need to set arcpy.env.scratchWorkspace to a folder.
From the usage notes for scratch workspace:
- If neither the scratch or current workspace is set, the autogenerated output path will be the workspace of one of the inputs.
It seems like the Viewshed2
tool is outputting intermediate temporary rasters in GeoTIFF format and your scratch workspace is defaulting to your input FGDB.
-
Could you please point me to what would be the input FGSB in my script? I still fail to see why it works with => " "C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\Optimity_Temp.gdb\test_Viewshed_AGL_Raster" but not with => "C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\DATA\Optimity_Temp.gdb\test_Viewshed_AGL_Raster"Pitrako Junior– Pitrako Junior2018年02月04日 13:02:18 +00:00Commented Feb 4, 2018 at 13:02
-
@PitrakoJunior, not sure. But
script_folder = sys.path[0]
is not a good idea. You should useos.path.dirname(__file__)
oros.path.dirname(sys.argv[0])
instead.user2856– user28562018年02月04日 20:11:32 +00:00Commented Feb 4, 2018 at 20:11
Explore related questions
See similar questions with these tags.
.\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.