Title: Geospatial Analysis I: map algebra, neighborhood operations
1Geospatial Analysis Imap algebra, neighborhood
operations
- Geospatial Analysis and Modeling
- Lecture notes
- Helena Mitasova, NCSU MEAS
2Outline
- summary statistics global and zonal operations
- neighborhood (focal) operations
- map algebra and local operations
- expressions, operators, functions and variables
- basic calculations, integer and floating point
data - "if" conditions, handling NULLs, creating masks
- special operators
- patching, mosaicking and overlay
3 Summary statistics
- Continuous raster data stored numbers are values
quantifying the phenomenon - univariate statistics min, max, mean, standard
deviation, - histogram requires discretization into bins
4 Summary statistics
- Continuous raster data stored numbers are values
quantifying the phenomenon - univariate statistics min, max, mean, standard
deviation, - histogram requires discretization into bins
- Discrete raster data stored numbers can be
values (quantitative data) or category numbers
(qualitative data) - univariate statistics can be applied only to
quantitative attributes - mode (most frequent cat), diversity (number of
different cats) apply to category data - Can be applied as global, zonal, or focal
operations
5Global statistics continuous data
Mean and standard deviation for elevation raster
maps m res. N mean stdv 1m 525000
120.769 6.619 10m 5250 120.935 6.600
Same source (lidar elevation), different
interpolation and resolution except 30m SRTM
6Global statistics continuous data
Mean and standard deviation for elevation raster
maps m res. N mean stdv 1m 525000
120.769 6.619 10m 5250 120.935 6.600
Histograms
Number of cells
1m 10m
elevationm
Same source (lidar elevation), different
interpolation and resolution except 30m SRTM
7Global statistics continuous data
Histograms
Mean and standard deviation for elevation raster
maps m res. N mean stdv 1m 525000
120.769 6.619 10m 5250 120.935
6.600 30m 624 120.284 6.981
1m 10m 30m
Same source (lidar elevation), different
interpolation and resolution except 30m SRTM
8Global statistics continuous data
Histograms
Mean and standard deviation for elevation raster
maps m res. N mean stdv 1m 525000
120.769 6.619 10m 5250 120.935
6.600 30m 624 120.284 6.698 SR30m 624
121.991 6.424 500m 1.7 116.845 2.436
1m 10m 30m 30m SRTM
Same source (lidar elevation), different
interpolation and resolution except 30m SRTM
9Global statistics discrete objects
- Works for soil erodibility factor Does not
apply to soil ID - Mean 0.248 stdv 0.028 Mean
29379.2 stdv 349.302 - but not for erodibility classes
10Zonal statistics continuous data
- Zonal summary statistics for continuous data
- Raster 1 rasterized polygon (zipcodes)
11Zonal statistics continuous data
- Zonal summary statistics for continuous data
- Raster 1 rasterized polygon (zipcodes)
- Raster 2 continuous field (elevation)
12Zonal statistics continuous data
- Zonal summary statistics for continuous data
- Raster 1 rasterized polygon (zipcodes)
- Raster 2 continuous field (elevation)
- Resulting raster 3 mean elevation value for
each zipcode
zonal statistics applicable to continuous data
min, max, mean, stdv, median
13Zonal statistics category data
- Zonal statistics for category data
- Raster 1 rasterized polygon (zipcodes)
- Raster 2 category map (land use 1996 with 24
classes)
HI developed LI developed South. pine Bott.
hardwoods Mixed hardwoods Cultivated Herbaceous
14Zonal statistics category data
- Zonal statistics for category data
- Raster 1 rasterized polygon (zipcodes)
- Raster 2 category map (land use 1996 with 24
classes) - Resulting raster 3 most frequent land use for
each zipcode - Guess the categories in the result below
HI developed LI developed South. pine Bott.
hardwoods Mixed hardwoods Cultivated Herbaceous
15Neighborhood operations
- Focal operations value at a grid cell is
function of its neighborhood values. - Grid cell neighborhood moving window, square or
circular - Same handling of continuous and discrete data as
for global and zonal operations
16Neighborhood operations
- Functions
- mean, stdv,max, min, median, sum, variance
- mode, diversity, interspersion most frequent
cell value, number of different cell values - filters
- fluxes
- Implemented as modules or in map algebra
- Image processing applications
17Neighborhood operations
- Continuous data
- smoothing
- SRTM DEM
- focal mean operator
- 5x5 window
18Neighborhood operations
- Continuous data
- smoothing
- SRTM DEM
- focal mean operator
- 5x5 window
19Neighborhood operations
- Discrete data
- land use 1996
- focal diversity
- 7x7 window
number of land use classes in the cell 7x7
neighborhood
20Neighborhood operations
- Discrete data
- land use 1996
- focal diversity
- 7x7 window
number of land use classes in the cell 7x7
neighborhood
21Raster map algebra
- Computes a new raster map using expression built
by applying logical and/or arithmetic operators,
mathematical functions to existing raster maps
representing variables - newmap expression (map1, map2, ...map3)
- Local Expression is applied on per-cell basis
- Focal moving window calculations apply
expression to the given cell and its neighboring
cells
22Raster map algebra
- Each software has its own syntax and set of
operators and functions, examples - Logical ?
- Arithm. Operators ?
- Math. Functions ?
- Special operators ?
23Raster map algebra
- Each software has its own syntax and set of
operators and functions, examples - Logical operators and functions
- less than, equal,
- and, or, not, ...
- if(x), if(x,a,b)
- Arithm. Operators
- , -, , /
- Math. Functions
- exp(x,y),sin(x),log(x)
- min(x1,x2,..), max(), median()
24Map algebra int and fp rules
- Integer and floating point matters for arithmetic
expressions - F(map1_int, map2_int) -gt map_int
- F(map1_int, map2_fp) -gt map_fp
- Example compute ndvi index from landsat integer
maps - ndvi(tm4-tm3)/(tm4tm3)
- ndvifloat(tm4-tm3)/float(tm4tm3)
- ndvi1.(tm4-tm3)/(tm4tm3)
25Map algebra int and fp rules
tm3 1-255
?
tm4 1-255
26Map algebra int and fp rules
tm3 1-255
0
tm4 1-255
27Map algebra int and fp rules
ndvi1.(tm4-tm3)/(tm4tm3)
tm4 1-255
28Map algebra int and fp rules
ndvi1.(tm4-tm3)/(tm4tm3)
tm4 1-255
29Map algebra if conditions
- logical expressions apply to both continuous
and discrete (category) data and their
combination - use for complex reclassification, masking and
overlays - Example find all forested areas with elevation gt
120m
highforestif(landclass965 elevation gt 120.,
elevation, 0)
30Map algebra if conditions
- logical expressions apply to both continuous
and discrete (category) data and their
combination - use for complex reclassification, masking and
overlays - Example find all forested areas with elevation gt
120m
highforestif(landclass965 elevation gt 120.,
elevation, 0)
31Map algebra null data handling
- Raster maps can include NULL data (no-data), each
software has its own rules how to handle them in
map algebra operations - General rule If a cell is null in at least one
map (variable) then it is null in the resulting
map - If statements can test for null and/or assign
a cell null value based on the if condition - Special operators can be implemented to extend
the rules applied to nulls
32Map algebra null data handling
- Compute average elevation from 30m SRTM and one
tile of 6m NCFlood DEM, - elev_avg(elev_srtm_30melevlid_D782_6m)/2.
NULL
?
zero
102m
Use if statement to limit the computation to
no-NULL areas
33Map algebra null data handling
- Compute average elevation from 30m SRTM and one
tile of 6m NCFlood DEM, cells that do not have
NCFlood tile values are NULL - elev_avg(elev_srtm_30melevlid_D782_6m)/2.
NULL
NULL
zero
102m
51m
Use if statement to limit the computation to
no-NULL areas
34Map algebra relative coordinates
- Focal operations - moving window - operations
- filters or simulations slower than C modules
but more flexible, - edge cell problem
- Operations on raster map subset, creating new
maps - Replacing values in a subregion of a raster map
- Generating tilted plane
- Modeling dynamic processes
- Fluxes and diffusion
35Map algebra relative coordinates
- Example for applying operation to subset of a
given region - For an area where
- x lt 637033. and y lt 225552. and
- x gt 633985. and y gt222504.
- use lidar-based DEM elevlid_D783_6m
- everywhere else within the define region
- use SRTM-based elev_srtm_30m
36Map algebra relative coordinates
- Examples generating tilted plane (e.g.
geological fault) - zaxbyc,
- zxy100 plane dipping to NW starting at 100m
- planerow()col()98
Enough map algebra for now, more comes along later
37Raster maps patching and overlay
- Merging several neighboring raster maps into a
single raster - Filling-in nulls in base raster map with values
from additional raster maps - Order of maps matters
- Issues resolution, extension that is not
aligned, no-data slivers due to projection
38Raster maps patching
- Merging several neighboring raster maps into a
single raster - example patch DEM tiles A, B, C, D into map E
A B C D
39Raster maps patching and overlay
Filling-in nulls combine roads, lakes,
building footprint and elevation map into a
single raster
40Reclassification and rescaling
- Reclassification / recoding transformation rules
used to convert between raster value types and
classes - general form
- change interval or list of values ltwi, wjgt to a
new value vk or interval of values ltvk,vlgt - Rescaling
- applies to continuous data or values associated
with discrete data - wnew kwold for each cell
- histogram equalized values are distributed
according to a cumulative histogram
41Reclassification examples
- Reclassification examples
- How is this handled in DBMS? When do you want to
do this?
INT zipcodes to INT cities 27511 27513 1 Cary
42Reclassification examples
- Reclassification examples
Zipcodes to cities 27511 27513 1 Cary
FP aspect to INT cardinal directions
0- 45 4 East 45-135 1 North 135-225 2
West 225-315 3 South 315-360 4 East
43Rescaling examples
44Rescaling examples
- Slope equal interval
hist. equalized
45Summary and references
- summary statistics (global, zonal, focal)
- Neteler ch. 5, Bolstad ch. 10
- map algebra
- Neteler ch. 5.2 , Bolstad ch. 10
- patching, rescaling, reclassification