Select to view content in your preferred language

Pass a null result back to a dynamic map Service from a geoprocessing task

2033
18
10-02-2012 10:23 PM
SusanJones
Frequent Contributor
Howzit All,

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?

Susan

North South GIS
Auckland, New Zealand
0 Kudos
18 Replies
SusanJones
Frequent Contributor
Just checked the arcpy.SetParameter(6,"") using your recommendations. The output still generates an invalid return value back to the AGS Dynamic Map Service Layer. Pretty sure that the Geoprocessing serivce is successfully execution as it fails after the task has finished.

esriJobMessageTypeInformative: 0:00:02.254000
esriJobMessageTypeInformative: Completed script MEDKDInterpolatePOCwithparameters...
esriJobMessageTypeInformative: Succeeded at Wed Oct 17 16:45:28 2012 (Elapsed Time: 3.00 seconds)
esriJobMessageTypeInformative: Succeeded at Wed Oct 17 16:45:28 2012 (Elapsed Time: 3.00 seconds)
esriJobMessageTypeError: Invalid return value:
0 Kudos
SusanJones
Frequent Contributor
Calling Script

--start Here --
arcpy.AddMessage(sqlQuery)

outRaster=arcpy.env.scratchGDB+os.path.sep+"heatMap"
#outRaster=arcpy.GetParameterAsText(3)
arcpy.MakeFeatureLayer_management(inFeatures,"inFeatures1",sqlQuery)
arcpy.AddMessage("feature Count:"+str(arcpy.GetCount_management("inFeatures1")))
descFeatures=arcpy.Describe("inFeatures1")
result=arcpy.GetCount_management("inFeatures1")
count = int(result.getOutput(0))
arcpy.env.mask=descFeatures.extent
arcpy.AddMessage(str(count))

#TODO: test For Selection
if count==0:
    arcpy.AddMessage("Error")
    arcpy.SetParameter(6,"")
else:
    arcpy.AddMessage("Continue")

    #TODO: process Kerenl Density
    processStart=datetime.datetime.now()
    arcpy.AddMessage("***generate Kernel Density Surface")
    arcpy.gp.KernelDensity_sa("inFeatures1", modelFld, outRaster, "", searchReadius, "SQUARE_MAP_UNITS")
    arcpy.AddMessage(str(datetime.datetime.now()-processStart))

    #TODO: check In License
    arcpy.AddMessage("***check In Spatial Analyst")
    arcpy.CheckInExtension("spatial")

    #TODO: set Output
    arcpy.AddMessage("***set The Output Layer")       
    arcpy.SetParameter(6,outRaster)




Complete Messaging
Job Messages:
esriJobMessageTypeInformative: Submitted.
esriJobMessageTypeInformative: Executing...
esriJobMessageTypeInformative: Executing (MED_KDInterpolate_POC_withparameters): MEDKDInterpolatePOCwithparameters "Corinthian,Philip V" hok # # # Estimated_catch__gwt_ C:\Users\services\AppData\Local\Temp\med\medkdinterpolatepoc_demo_gpserver\je2f1a43da2ef49bc9585d464cf91e4c4\scratch\scratch.gdb\heatMap
esriJobMessageTypeInformative: Start Time: Thu Oct 18 08:44:54 2012
esriJobMessageTypeInformative: Executing (MEDKDInterpolatePOCwithparameters): MEDKDInterpolatePOCwithparameters "Corinthian,Philip V" hok # # # Estimated_catch__gwt_ C:\Users\services\AppData\Local\Temp\med\medkdinterpolatepoc_demo_gpserver\je2f1a43da2ef49bc9585d464cf91e4c4\scratch\scratch.gdb\heatMap
esriJobMessageTypeInformative: Start Time: Thu Oct 18 08:44:54 2012
esriJobMessageTypeInformative: Running script MEDKDInterpolatePOCwithparameters...
esriJobMessageTypeInformative: *** Kernel Density Generator with Parameters ***
esriJobMessageTypeInformative: ***check Out Spatial Analyst
esriJobMessageTypeInformative: "Vessel_Name" IN ('Corinthian', 'Philip V') AND "Species" IN ('hok')
esriJobMessageTypeInformative: feature Count:0
esriJobMessageTypeInformative: 0
esriJobMessageTypeInformative: Error
esriJobMessageTypeInformative: completed
esriJobMessageTypeInformative: 0:00:04.962000
esriJobMessageTypeInformative: Completed script MEDKDInterpolatePOCwithparameters...
esriJobMessageTypeInformative: Succeeded at Thu Oct 18 08:45:00 2012 (Elapsed Time: 6.00 seconds)
esriJobMessageTypeInformative: Succeeded at Thu Oct 18 08:45:00 2012 (Elapsed Time: 6.00 seconds)
esriJobMessageTypeError: Invalid return value: C:\Users\services\AppData\Local\Temp\med\medkdinterpolatepoc_demo_gpserver\je2f1a43da2ef49bc9585d464cf91e4c4\scratch\scratch.gdb\heatMap
esriJobMessageTypeError: Failed.
0 Kudos
SusanJones
Frequent Contributor
Hi
perhaps the best workaround is to put some error trapping in to check for the failed task by the calling applicaton, in this case the javascript API.

It doesn't appear the GP Dynamic Map services can handle a null return.
The tool works fine when it is not a Geoprocessing Service, even when a null output is returned. It fails with Geoprocessing Service.
0 Kudos
ShingLin
Esri Contributor
Only run the kernel density function when the get count is greater than zero. The map service is generated based on the result of gp service. When there is no input/output of gp service, the map service is destined to be failing. This is as designed for now. So the work around is not to call the function and set the blank in your output parameter. Not the best way, but at least won't fail when you run the service.
0 Kudos
SusanJones
Frequent Contributor
HI,

The issue is in setting the null derived output in a Geoprocessing Service. Neither ArcMap, or the AGS Map Service Layer knows about the null part of it and fails.

The issue is not recreatable as a standalone tool (one that is not a service). It is just present in the Geoprocesing Service behaviour.

Susan
0 Kudos
ShingLin
Esri Contributor
In the code u provided, are the following code executed when count = 0? It should not be. But the error message you sent seems showing this part of code was executed. If it does, it will fail because the output is overwritten outraster which is invalid.



#TODO: process Kerenl Density
processStart=datetime.datetime.now()
arcpy.AddMessage("***generate Kernel Density Surface")
arcpy.gp.KernelDensity_sa("inFeatures1", modelFld, outRaster, "", searchReadius, "SQUARE_MAP_UNITS")
arcpy.AddMessage(str(datetime.datetime.now()-processStart))

#TODO: check In License
arcpy.AddMessage("***check In Spatial Analyst")
arcpy.CheckInExtension("spatial")

#TODO: set Output
arcpy.AddMessage("***set The Output Layer")
arcpy.SetParameter(6,outRaster)
0 Kudos
SusanJones
Frequent Contributor
That's correct. If the number of selected features is 0, Kernel Density will not run. Instead a null output is specified and the application bails when a null raster layer is being set as AGS Dynamic Map Service Layer.

It is almost as if the default setting from the publsihing mxd is overriding the null output passed back to the AGS Dynamc Map Service Layer.

I understand we are trialing the heat map sample using the javascript api and html5 framework. http://blogs.esri.com/esri/arcgis/2012/09/26/heat-up-your-webmaps/ This quite a big difference from the Geoprocessing Service. It is custom code with a mix of open source and ESRI technologies. It is very much a R&D exercise because we exhausted the Proof of Concept funding for the work. 

It's kind of scary resorting to a non-tested, non-supported solution though.

Susan
0 Kudos
SusanJones
Frequent Contributor
Hi,

We picked up on this yesterday again and made some further progress.

We will have tio first initialize the outRaster as a none before with start with the Surface Generation function. After this, we can include a status variable

#TODO: THIS IS Important part �?? setting outRaster to None initially
outRaster=None
�?�
�?�
#TODO: Check Count
If cnt>0:
     #run The hotspot
   outRaster=�?�
   Status=�?�true�?�
Else:
     Status=�?�false
#assign Parameters
If Status=�?�true�?�:
    arcpy.SetParameter(6,outRaster)
else:
    arcpy.SetParameter(6,outRaster)


Susan
0 Kudos
ShingLin
Esri Contributor
Thanks for updating. Is this part of your code correct? It seems there is no need of 'if .. else' statement since both logic condition executes the same function and parameter  arcpy.SetParameter(6,outRaster).

If Status=�?�true�?�:
arcpy.SetParameter(6,outRaster)
else:
arcpy.SetParameter(6,outRaster)
0 Kudos