I'm trying to figure out how to wrap a raster function chain into a python function that has parameters for the input raster(s) of the function chain. I also need to display the output in the map widget.
My eventual goal is to create wrappers for function chains which have multiple input branches. But for now, here is a very simple example I have tried which requires only one input raster parameter.
# code for context.
type(dem_item)
arcgis.gis.item
dem_item.layers
<ImageryLayer url:"http://dev004545.esri.com/arcgis/rest/services/Hosted/NED_1r3_CONUS_Albers_30m/ImageServer">
# python wrapper function
def slope_template(in_ras):
return
{
"rasterFunction" : "Slope",
"rasterFunctionArguments" : {
"DEM" : in_ras
}
}
# Add the output of the function to the map widget
map.add_layer(slope_template(dem_item.layers[0]))
Running this code produces the following error.
---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-26-4095d219143b> in <module>()----> 1 map1.add_layer(slope_template(dem_item.layers[0])) C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\widgets\__init__.py in add_layer(self, item, options) 142 143 self._addlayer = json.dumps(js_layer)--> 144 elif 'layers' in item: # items as well as services 145 if item.layers is None: 146 raise RuntimeError('No layers accessible/available in this item or service') TypeError: argument of type 'NoneType' is not iterable