Raster analysis - advanced concepts¶
Raster functions are lightweight and process only the pixels visible on your screen, in memory, without creating intermediate files. They are powerful because you can chain them together and apply them on huge rasters and mosaics on the fly. This guide will introduce you to the different capabilities of Imagery Layers and how to apply raster functions. As a sample, it uses Landsat imagery data.
Note: This guide requires bokeh python plotting library. Install it in your conda environment using the command below. This command should be typed in the terminal, not in the notebook
conda install bokeh
Table of contents
- Access Landsat imagery
- Interactive raster processing in Jupyter notebook
- Setting an area of interest
- Exporting images from Imagery Layer
- Exporting images from an imagery layer to which a raster function has been applied
- Vegetation index
- Custom bands
- Image attributes
- Spectral profile from the sampled values at a location
- Clipping to an area of interest
- Select images by where clause, geometry and the time range
- Resolving overlapping pixels in selected rasters
- Change detection
- Persisting your analysis for visualization or analysis
Access Landsat imagery¶
ArcGIS Online provides multispectral landsat imagery layer, that we'll be using for this tutorial. Let's connect to ArcGIS Online and query for the "Landsat Multispectral" imagery layer:
from arcgis.gis import GIS
gis = GIS('https://pythonapi.playground.esri.com/portal', 'arcgis_python', 'amazing_arcgis_123')
landsat_item = gis.content.search('Multispectral Landsat', 'Imagery Layer', outside_org=True)[0]
landsat_item
View Landsat imagery layer item description¶
from IPython.display import HTML
HTML(landsat_item.description)
Access the layers available with the Landsat Imagery Layer item¶
This imagery layer item contains the imagery layer that we'll be using for this tutorial. Let's save a reference to the layer in the landsat
variable. Querying the variable will in the Jupyter notebook will quickly render it as an image
landsat = landsat_item.layers[0]
landsat
Explore different wavelength bands¶
import pandas as pd
pd.DataFrame(landsat.key_properties()['BandProperties'])
Visualize the layer in the map widget¶
Let's visualize the layer by creating a map widget around our area of interest and adding the Landsat Imagery layer to it:
m = gis.map('Redlands, CA')
m
m.add_layer(landsat)
Apply built-in raster functions¶
The multispectral imagery layer can be rendered using several different raster functions (also known as raster function templates). Each raster function template incorporates different satellite bands to highlight different land cover features. Obtain list of predefined raster function templates defined by the service backing the imagery layer:
for rasterfunc in landsat.properties.rasterFunctionInfos:
print(rasterfunc.name)
Let's apply the 'Color Infrared with DRA' raster function to visualize the color infrared view. This can be done using the apply
function in the arcgis.raster.functions
module. This function applies a server defined raster function template, given it's name, to the Imagery layer.
from arcgis.raster.functions import apply
color_infrared = apply(landsat, 'Color Infrared with DRA')
m = gis.map('Redlands, CA')
m.add_layer(color_infrared)
m
A true-color image uses red, green and blue satellite bands to create an image that looks like a photograph. The color infrared view, on the other hand, uses the near infrared, red and green satellite bands to create an image. As a result, vegetation appears bright red in the image above.
Interactive raster processing in Jupyter Notebook¶
Imagery layers can be queried in the Jupyter Notebok. This displays a raster representation of the layer as an image:
color_infrared