How to set the spatial reference when saving raster function output?

1057
5
Jump to solution
12-29-2020 03:47 PM
DavidJohnson5
Esri Contributor

Can I reproject the output of a raster function before saving it to a GIS?

For example, this code applies an agricultural mask to a burnt area.

burnt_areas_masked = colormap(set_null(rasters=[ag_mask, burnt_areas]),
colormap=[[4, 115, 76, 0],
[3, 168, 112, 0],
[2, 230, 152, 0],
[1, 255, 170, 0]])

The inputs 'ag_mask' and 'burnt_areas' are in-memory rasters generated by raster functions applied to imagery layer items in the GIS.  The output 'burnt_areas_mask' inherits the spatial reference of 'ag_mask'.  I guess this makes sense since 'ag_mask' is the first raster in the list of inputs.  But 'ag_mask' is only a boolean layer and not actual the input data.  So I need a way to set the spatial reference of the output 'burnt_areas_mask' to the spatial reference of 'burnt_areas'.

The "reproject" function looks like a possible solution.

https://developers.arcgis.com/python/api-reference/arcgis.raster.functions.html#reproject

But I get a "name error" when I try to call it.  

reproject.PNG

Any suggestions?

1 Solution

Accepted Solutions
Rhea_Jackson
New Contributor

Hi David,

reproject function was added only in V1.8.3. Please check if you are using an older version.

method1.JPG

You can also try using out_spatial_reference env variable

method2.JPG

View solution in original post

5 Replies
DanPatterson
MVP Esteemed Contributor

Don't do the * import thing until you check

import arcgis.raster.functions as arf
dir(arf)
[... 'reproject', ...]

# ---- then arf.reproject(....

... sort of retired...
Rhea_Jackson
New Contributor

Hi David,

reproject function was added only in V1.8.3. Please check if you are using an older version.

method1.JPG

You can also try using out_spatial_reference env variable

method2.JPG

DanPatterson
MVP Esteemed Contributor

Which probably means you arent using Pro 2.7 or didn't do a

> conda update arcgis

through conda or the package manager.

More details...

ArcGIS API For Python | ArcGIS for Developers


... sort of retired...
DavidJohnson5
Esri Contributor

I should have mentioned that I'm using ArcGIS Online Notebooks.  I'm not sure what version of the API it uses.  But it must be an earlier version since reproject is not available.  I tried your second suggestion Rhea to set the out_spatial_reference property and that worked.  Thanks Dan and Rhea for the quick responses!

0 Kudos
DanPatterson
MVP Esteemed Contributor

@DavidJohnson5 

import arcgis
arcgis.__version__
'1.8.3'

for version number


... sort of retired...
0 Kudos