ArcGIS Enterprise at 10.5 provides you with the ability to perform large raster data analytics using distributed computing using raster analytics tools. This analytics capability is provided in the arcgis.raster.analytics
module and includes functionality to summarize data, analyze patterns, images, terrain and manage data. This sample show the capabilities of imagery layers and raster analytics.
import arcgis
from arcgis.gis import GIS
from IPython.display import display
gis = GIS()
Here we're searchcing for multispectral landsat imagery layer:
items = gis.content.search("Landsat 8 Views", max_items=2)
for item in items:
display(item)
landast_item = items[1]
imglyr = landast_item.layers[0]
This layer has been published with several Raster Functions, that the code below is cycling through, and listing out:
for fn in imglyr.properties['rasterFunctionInfos']:
print (fn['name'])
Agriculture with DRA Bathymetric with DRA Color Infrared with DRA Natural Color with DRA Short-wave Infrared with DRA Geology with DRA Agriculture Bathymetric Color Infrared Geology Natural Color Short-wave Infrared NDVI Colorized Normalized Difference Moisture Index Colorized NDVI Raw NBR Raw None
Let us create a map widget and load this layer
map1 = gis.map("Pallikaranai", zoomlevel = 13)
map1
map1.add_layer(imglyr)
The utility of raster functions is better seen when we interactively cycle through these raster functions and apply them to the map, like the code below does. This is using on-the-fly image processing at display resolution to cycle through the various raster functions, and showing how the layer can be visualized using these different raster functions published with the layer.
import time
for fn in imglyr.properties['rasterFunctionInfos'][:6]:
print(fn['name'])
map1.remove_layers()
map1.add_layer(imglyr, {"imageServiceParameters" :{ "renderingRule": { "rasterFunction": fn['name']}}})
time.sleep(2)
Agriculture with DRA Bathymetric with DRA Color Infrared with DRA Natural Color with DRA Short-wave Infrared with DRA Geology with DRA
Developers can create their own raster functions, by chaining different raster functions. For instance, the code below is doing an Extract Band and extracting out the [4,5,3] band combination, and applying a Stretch to get the land-water boundary visualization that makes it easy to see where land is and where water is. Its worth noting that the raster function is applied at display resolution and only for the visible extent using on the fly image processing.
# A raster function is created as a python dictionary as shown below:
def extract_bands(bands):
return {
"rasterFunction": "Stretch",
"rasterFunctionArguments":{
"Raster":{
"rasterFunction": "ExtractBand",
"rasterFunctionArguments":{"BandIds": bands}
},
"StretchType": 6,
"DRA": True,
"Gamma": [1,1,1],
"UseGamma": True
},
"outputPixelType":"U8"
}
Let us apply this raster function to the image layer to visualize the results.
map2 = gis.map("Pallikaranai", zoomlevel=13)
map2
map2.add_layer(imglyr, {"imageServiceParameters" : { "renderingRule": extract_bands([4, 5, 3]) }})
This part of the notebook shows how Raster Analytics (in ArcGIS Enterprise 10.5) can be used to generate a raster information product, by applying the same raster function across the extent of an image service on the portal. The raster function is applied at source resolution and creates an Information Product, that can be used for further analysis and visualization.
portal = GIS("https://yourportal.domain.com/webcontext", "username","password")
montana_landsat = portal.content.search("ImgSrv_Landast_Montana2015")[0]
montana_landsat
We can use the arcgis.raster.analytics.generate_raster()
tool to apply the raster function across the entire extext of the input image layer at source resolution, and presist the result in another output image layer. This creates a raster product similar that can be used for further analysis and visualization.
In the code below, we use a raster function that extracts the [7, 5, 2] band combination. This improves visibility of fire and burn scars by pushing further into the SWIR range of the electromagnetic spectrum, as there is less susceptibility to smoke and haze generated by a burning fire.
from arcgis.raster.analytics import generate_raster
montana_fires = generate_raster(extract_bands([7, 5, 2]), montana_landsat)
Submitted. Executing... Executing (GenerateRaster): GenerateRaster {"rasterFunctionArguments":{"StretchType":6,"DRA":true,"UseGamma":true,"Raster":{"rasterFunctionArguments":{"BandIds":[7,5,2]},"rasterFunction":"ExtractBand"},"Gamma":[1,1,1]},"outputPixelType":"U8","rasterFunction":"Stretch"} {"serviceProperties":{"serviceUrl":"http://dev003248.esri.com/rax/rest/services/Hosted/GeneratedRasterProduct_XFFOFL/ImageServer","name":"GeneratedRasterProduct_XFFOFL"},"itemProperties":{"itemId":"eb92462703d74a28b5044541b931e574"}} {"Raster":{"itemId":"8c921ea4373c4238b77d526abe3838f5"}} # # Start Time: Wed Dec 14 17:23:08 2016 Running script GenerateRaster... Image service GeneratedRasterProduct_XFFOFL already existed. GetPrivateUrl returns: https://yourserver.domain.com:6443/arcgis/rest/services/Hosted/GeneratedRasterProduct_XFFOFL/ImageServer The service got from item ID is: https://yourserver.domain.com:6443/arcgis/rest/services/Hosted/GeneratedRasterProduct_XFFOFL/ImageServer Output item id is: eb92462703d74a28b5044541b931e574 Output image service url is: https://yourserver.domain.com:6443/arcgis/rest/services/Hosted/GeneratedRasterProduct_XFFOFL/ImageServer Output cloud raster name is: Hosted_GeneratedRasterProduct_XFFOFL GetPrivateUrl returns: https://yourserver.domain.com:6443/arcgis/rest/services/ImgSrv_Landast_Montana2015/ImageServer The service got from item ID is: https://yourserver.domain.com:6443/arcgis/rest/services/ImgSrv_Landast_Montana2015/ImageServer Using input dataset's spatial reference. Using full extent of input dataset. Use default resampling method. Output raster will be the same resolution as input. Updating service with data store URI. Updating service: https://yourserver.domain.com:6443/arcgis/admin/services/Hosted/GeneratedRasterProduct_XFFOFL.ImageServer/edit Completed script GenerateRaster... Succeeded at Wed Dec 14 17:23:17 2016 (Elapsed Time: 9.31 seconds)
montana_fires
location = arcgis.geocoding.geocode("Marthas Basin, Montana")[0]
base_map = portal.map(location, 12)
natural_color_map = portal.map(location, 12)
natural_color_map.add_layer(montana_landsat)
false_color_map = portal.map(location, 12)
false_color_map.add_layer(montana_fires)
We can compare the natural color and false color images uaing a tabbed widget.
In the false color image the red and brownish pixels correspond to burn scars of the fire:
import ipywidgets as widgets
tab = widgets.Tab([base_map, natural_color_map, false_color_map])
tab.set_title(0, 'Basemap')
tab.set_title(1, 'Natural Color')
tab.set_title(2, 'False Color')
tab
Thus using the same raster function, we were able to both visualize on the fly (in the case of Pallikaranai marsh example) and also derive a persisted image service (in the case of Montana example) with the power of raster analytics.