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.
Any suggestions?
Solved! Go to Solution.
Hi David,
reproject function was added only in V1.8.3. Please check if you are using an older version.
You can also try using out_spatial_reference env variable
Don't do the * import thing until you check
import arcgis.raster.functions as arf
dir(arf)
[... 'reproject', ...]
# ---- then arf.reproject(....
Hi David,
reproject function was added only in V1.8.3. Please check if you are using an older version.
You can also try using out_spatial_reference env variable
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
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!