Skip to content
Jamie Drisdelle edited this page Jul 6, 2018 · 12 revisions

Python raster function deployment

Deploying and distributing custom raster functions can now be performed seamlessly by placing any Python raster functions (.py) and their associated raster function templates (.rft.xml) in the well-known home folder. This folder exists on all ArcGIS products, including ArcGIS Pro. As a developer, you will need to set up this folder once and replicate it in the respective ArcGIS installation directories. Then all your custom functions that exist in these folders will be recognized across the platform. When a user applies or publishes a custom function template, the software will automatically look in this location for the associated Python script.

Prior to deploying custom Python raster functions, the developer should ensure that all third-party Python libraries are installed. These associated libraries and the correct version of Python also needs to be installed with ArcGIS Pro. The Python version can be determined by typing the following into the Python window: sys.version_info.

At this point, you can start preparing your raster function templates. Open a template using a text editor or XML editor. Locate the path to the Python file in the XML editor. Change the path to the Python script it is referencing using the well-known home folder path. To do so, use the following syntax: [functions]Custom\subfolder\script1.py.

ArcGIS Desktop

Distributing Python raster functions to other ArcGIS desktop users requires that they install any 3rd party Python libraries used by that particular function. Make sure you install the library associated with the proper python version. For any ArcGIS 10.x version the Python version is 2.7.

Two methods can be used when referencing a Python raster function from a raster function template (.rft) in ArcGIS desktop.

  1. Reference python scripts using relative paths names in the associated rft. For example: …\functions\templates\template.rft.xml ...\functions\scripts\script.py Relative paths do not work when raster function template pointing to a python file is attached to a mosaic dataset. In this case you will need to change the path using the repair mosaic dataset paths geoprocessing tool.

  2. Reference python scripts using the ‘well known home folder’. This requires the developer to reference Python scripts using the following syntax in the associated rft: [functions]Custom\custom1\script.py

As a user, you will need to copy the Python script and the associated rft and place them into the “well-known home folder” in your ArcGIS Desktop install location. When a user opens the rft, the software will automatically look in this location for the associated Python script. The “well-known home folder” is located at:

\Program Files(x86)\ArcGIS\Desktop10.5\Resources\Raster\Functions

Do not install your custom functions into the system folder within the “well-known home folder”. This is reserved for system functions. You will need to create a sibling folder. For example:

\Program Files(x86)\ArcGIS\Desktop10.5\Resources\Raster\Functions\Custom\custom1 This second method is recommended in lieu of using relative paths since it will work for both ArcGIS Server and Pro deployment as well.

ArcGIS Pro

Distributing Python raster functions to other ArcGIS Pro users requires that they install any 3rd party Python libraries used by that particular function. Make sure you install the library associated with the proper python version. For ArcGIS Pro the Python version is 3.4.

If you are referencing a Python raster function from a raster function template (.rft), you need to ensure that the Python file is being referenced using the well the ‘well known home folder’. This requires the developer to reference Python scripts using the following syntax in the associated rft:

[functions]Custom\custom1\script.py

As a user you will need to place the Python script associated with the template into the “well-known home folder” in your ArcGIS desktop install location. When a user opens uses the rft, the software will automatically look in this location for the associated Python script. The “well-known home folder” is located at:

\Program Files\ArcGIS\Pro\Resources\Raster\Functions

Do not install your custom functions into the system folder within the “well-known home folder”. This is reserved for system functions. You will need to create a sibling folder. For example:

\Program Files\ArcGIS\Pro\Resources\Raster\Functions\Custom\custom1

If the raster function template and python file are both placed in the custom folder they will automatically show up in the Raster Functions pane. The subfolder after \Custom will be used as the sub category in the function pane. For example: If you use the following folder structure

\Program Files\ArcGIS\Pro\Resources\Raster\Functions\Custom\custom1

The Custom category of the Raster Functions pane will look like this:

pro pane)

Custom function folders will be denoted with [ ] square brackets in the function pane. These folders are not editable in the Pro application. They are only manageable through windows explorer. If changes are made to these folders, you will need to restart Pro in order to refresh the function pane.

ArcGIS Server

Deploying a Python raster Function with an image service on ArcGIS server requires similar setup to that of ArcGIS desktop. When installing the libraries associated with a particular Python Raster function the Python version will be the same (2.7), however, you will need to ensure that you install the 64 bit version of the libraries.
Prior to publishing the service with the associated Python raster you need to make sure that the user that is logged into your ArcGIS service has access to folder containing the Python files. This service can be accessed through ‘control panel > administrative tools > services’.

If a Python raster function is being pushed to the server from the client side as a standalone raster function template or a template attached to a mosaic dataset the Python script will not be sent with it. This was done in order to prevent potentially malicious code from being published to a server. As a server administrator you will need to acquire the Python script associated with the template and place it into the “well-known home folder” on the server. When the template is published ArcGIS server will automatically look in this location for the associated Python script. The “well-known home folder” is located at:

installdir\Program Files\ArcGIS\Server\Resources\Raster\Functions

Do not install your custom functions into the system folder within the “well-known home folder”. This is reserved for system functions. You will need to create a sibling folder. For example:

installdir\Program Files\ArcGIS\Server\Resources\Raster\Functions\MyCustomFunctions

Raster Analytics

Raster analytics is a flexible raster processing, storage, and sharing system that employs distributed computing and storage technology. It can be used to distribute the processing performed by custom Python Raster Functions across multiple servers. In order for the Python Raster Function to be used with raster analytics, the python file (.py) and Raster Function Template (.rft) must be accessible to every machine in the RA cluster. This is can be achieved by maintaining the python file and RFT in a shared folder that is visible to each machine in the RA cluster.

You can run your custom Ptyhon Raster Function through raster analytics following the same instructions that you would use to run the Slope function through raster anlytics. The key here is that raster analytics run when the Output Layer Type is set to Web Image Layer before applying the raster function in ArcGIS Pro.