Hello,
I wrote my own geoprocessing tool that performs Viewshed analysis. The tool works perfectly fine in the Pro environnment but once it's published (no errors when publishing from Pro 3.2.2), the raster output from arcpy.ddd.Viewshed2() returns the error 000732. No file is written.
I've tried using a scratch name for the result. I've tried using 'in-memory/raster_name'. I've tried without specifying a name in the viewshed tool when setting the workspace to the scratchGDB. I've written to os.path.join(arcpy.env.scratchGDB, 'raster_name') with no success. I've attempted to save the result as such
Here are my questions: Does the server need to have a specific running service (maybe utilitary) in order to handle the output? Is there a rule about using Viewshed outside of pro? Why doesn't the result write on disk?
I don't want to use the ready to use tools 'create viewshed' as I can't use my own raster image as input.
Thanks in advance.
Here is some of the code I'm using:
# Set workspace
arcpy.AddMessage(arcpy.env.scratchFolder)
arcpy.env.workspace = arcpy.env.scratchGDB
arcpy.AddMessage(arcpy.env.workspace)
# Env params
arcpy.env.overwriteOutput = True
# Raster URL
image_service_url = parameters[0].valueAsText
# Observer FC
observer_feature_layer = self.create_observer_fc(parameters[2].valueAsText)
arcpy.AddMessage(observer_feature_layer)
if parameters[1].valueAsText is not None: # view_extent
try:
arcpy.env.extent = parameters[1].valueAsText
except Exception as e:
arcpy.AddMessage(f'Extent was unable to be set. Making 1km buffer around point (dev)\n{e}')
arcpy.env.extent = self.create_extent_from_point(observer_feature_layer)
# Check creations
arcpy.AddMessage(arcpy.ListRasters()) # empty
arcpy.AddMessage(arcpy.ListFeatureClasses()) # ['ObserverFeatureClass']
# Viewshed
arcpy.AddMessage(f"Starting Viewshed2 operation...")
viewshed_raster = arcpy.ddd.Viewshed2(in_raster=image_service_url, in_observer_features=observer_feature_layer, out_raster=os.path.join(arcpy.env.workspace, 'Viewshed_Image'))
arcpy.AddMessage(f"Viewshed2 completed. Output raster path: {viewshed_raster}")
saved_viewshed_raster = arcpy.ListRasters()[-1] # Fails here!
# Check creation 2
arcpy.AddMessage(arcpy.ListRasters()) # should be ['Viewshed_Image'] but is empty
# Raster to polygon... fails since Viewshed not found
arcpy.management.CreateFeatureclass(arcpy.env.workspace, 'ViewshedFeatureClass', 'POLYGON', spatial_reference = arcpy.SpatialReference(3857))
viewshed_poly_path = os.path.join(arcpy.env.workspace, 'ViewshedFeatureClass')
arcpy.conversion.RasterToPolygon(saved_viewshed_raster, viewshed_poly_path, 'NO_SIMPLIFY')