1

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 3, 2018 at 18:31
6
  • 1
    Look at the error message, this is not a valid path .\Optimity_Temp.gdb\Viewshe_DSM_25c1.tif Commented Feb 3, 2018 at 19:44
  • But I have no idea where that path comes from. The bit 'Viewshe_DSM_25c1.tif' is not mine. Commented Feb 3, 2018 at 20:27
  • Try printing the value of VS2_agl_raster before using it in Viewshed2 which is complaining about the value it is being given. Commented Feb 3, 2018 at 21:58
  • I have actually done this before I raised the issue here. I have now done it again and this is what it shows => "C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\DATA\Optimity_Temp.gdb\test_Viewshed_AGL_Raster", which is exactly what it's meant to be. Commented Feb 3, 2018 at 22:14
  • 1
    Try setting arcpy.env.scratchWorkspace to a folder. Commented Feb 3, 2018 at 23:10

1 Answer 1

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.

answered Feb 4, 2018 at 1:09
2
  • 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" Commented Feb 4, 2018 at 13:02
  • @PitrakoJunior, not sure. But script_folder = sys.path[0] is not a good idea. You should use os.path.dirname(__file__) or os.path.dirname(sys.argv[0]) instead. Commented Feb 4, 2018 at 20:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.