I have created a Geoprocessing Service that creates a Heat Map using the Kernel Density Tool. The service works well, and quickly when a feature selection is given to it. However, the tool fails when the feature layer selection returns no records and a null Raster Layer is passed back to the AGS Dynamic Map Service Layer.
Geoprocssing Overview: - create a Feature Layer from a sql expression - generate Kernel Density Layer - set Layer into resulting Dynamic Map Service Layer as a Raster Layer
The task fails when a null Raster Layer does not exist and is passed back to the out Layer using. arcpy.SetParameterAsText(6,outRaster)
The task succeeds when the heatMap is created from > 1 features in the selection.
Setting arcpy.SetSeverityLevel(0) ensures the task completes.
I think the problem occurs at the map services level because the task completes.
Question: How can I pass a null Layer back to a Raster Layer in a AGS Dynmaic Map Service Layer from a Geoprocessing Result?
You can modify the code for output paramter so there is no result map service returning when the selections result is zero. Here are two options:
(1) If the selections result is zero, set the outputpath of the kernel density path to blank and do not execute the kernel density function. Also, set theoutput parameter as a derived output in the script tool.
When you run your service with the query set to zero, did you see your "***set The Null Output" wriiten out? If not, can you try the approach in the code that I posted regarding to get count see if you get the message?