Composing raster functions with parameters for the input raster(s)

853
2
Jump to solution
04-12-2017 12:02 PM
DavidJohnson5
Esri Contributor

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

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

David we are working on a similar concept internally for the next release. With that you can access raster functions as Python functions and greatly simplifies how you use and chain them.

Meanwhile, checkout the extract_bands funciton in https://developers.arcgis.com/python/guide/using-imagery-layers/#Composing-raster-functions which talks about chaining raster functions and writing a method around it. You can use that as a starting point.

View solution in original post

2 Replies
by Anonymous User
Not applicable

David we are working on a similar concept internally for the next release. With that you can access raster functions as Python functions and greatly simplifies how you use and chain them.

Meanwhile, checkout the extract_bands funciton in https://developers.arcgis.com/python/guide/using-imagery-layers/#Composing-raster-functions which talks about chaining raster functions and writing a method around it. You can use that as a starting point.

DavidJohnson5
Esri Contributor

Atma, that sounds very cool to be able to access raster functions as python functions.  I look forward to getting my hands on that capability!   It's good to know your team is already working on it. Thanks for the tip.  That link you provided actually was my starting point for trying out this idea.  Thanks again!

0 Kudos