5/12/2015© 2009 raymond p. jefferis iii lect 07 - 1 geographic information processing data analysis...
TRANSCRIPT
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 1
Geographic Information Processing
Data Analysis• Watersheds• Gradient path
- Valleys- Ridges
• Flow analysis• Contours
Chester County, PA Watersheds, Chester County Board of Commissioners
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 2
Computing Watersheds
• Gradient-following– Locating valleys – Locating ridges
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 3
Gradient-Following Methods
• Spatial derivatives computed in both x- and y-directions
• Vector addition of derivatives produces gradient vectors
• Negative gradients point “down”
• Positive gradients point “up”
• Follow gradients to valleys or peaks
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 4
Data Preparation
• Gradient-following methods become “stuck” at local minima
• DTED Level 2 data has had pockets filled [filled DEM data]
• Use digital filtering to smooth contours before computing gradients. Gaussian filtering is best for band-limited random noise.
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 5
Following the Gradient
• Perform Gaussian filtering of data
• Compute gradient at all points, using Savitsky and Golay (or other) filter
• Start at any point
• Move in direction of desired gradient• Stop when gradient is zero
(This can be minimum or maximum point)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 6
Notes
• Two derivatives computed for each point– x-direction derivative– y-direction derivative
• Gradient is vector sum of x- and y-derivative at each point(Result will have Magnitude and Direction)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 7
Gradient Computation
• For data field, f(x,y), the gradient vector is a vector of spatial derivatives defined as:
G[ f (x, y)] =∂f / ∂x∂f / ∂y⎡
⎣⎢
⎤
⎦⎥
Where,Gx =∂f / ∂x= lim
Δx→ o[ f(x,y)− f(x+ Δx,y)]
Gy =∂f / ∂y= limΔy→ o
[ f(x,y)− f(x,y+ Δy)]
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 8
Note
Geographic pixels are of finite extent (not infinitesimal), thus the gradients must be computed by finite difference methods that only approximate the derivative definitions above.
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 9
Computational Notes
• Gx can be computed by convolution, using a kernel that gives the x-gradient
• Gy can be computed by convolution, using a kernel that gives the y-gradient
• The actual gradient is vector sum of these(See next slide for polar coordinate vector)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 10
Derivative Magnitude and Direction
G = Gx2 +Gy
2
ΘG = tan−1[Gy / Gx ]
Can produce gradient vector at each point.
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 11
Computing Gradients
• Nearest neighbor differencing– Follows the finite approximation– Amplifies data noise (no smoothing)
• Convolution– Uses special kernels– Can do smoothing of entire image– Rapid computations (parallel processing)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 12
Problems with Gradient Methods
• Local minima– Gradient gets “stuck” in a local minimum– Level 2 DTED data should eliminate this– Filter data for smooth contours
• Data resolution limits– Resolution of 1 meter makes valleys flat– Adds Uniform random noise– Results in big “puddles” (See following:)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 13
Altitude Resolution Problem• Gradient-following
result
• Filtering: 7x7 Gaussian convolute
• Altitude resolution: 1 meter
• Note flat areas where gradient cannot be resolved (black)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 14
Solutions
• More smoothing (15x15 convolute)[use Gaussian convolution kernel]
• Use 11x11 convolute for derivatives
• More complex descent algorithms
• Using surveyed stream/river data and connecting descending flows to these streams/rivers
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 15
Malvern Gradient Vectors
Heights convolution filteredGaussian filter15 x 15 kernel
Gradients by convolutionSavitsky & Golay11 x 11 kernels
Gradients shown at every 7th point
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 16
Note
Inspect Savitsky & Golay derivative convolution kernels at this point.
(Handout)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 17
Savitsky & Golay Kernels• Polynomial based• User selects polynomial type
– Quadratic,Cubic, Quartic, Quintic, etc.
• User selects number of terms– Number of data points used in filter calculation– Varies degree of smoothing (more points means
more smoothing - more information used from surrounding points for each point at which derivative is calculated)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 18
15x15 Gaussian Filter KernelArray[c, 16, 16]; n = 15; sm = 4661.0;
c = {{1, 2, 3, 5, 6, 7, 8, 9, 8, 7, 6, 5, 3, 2, 1}, {2, 3, 5, 8, 10, 13, 14, 15, 14, 13, 10, 8, 5, 3, 2}, {3, 5, 8, 12, 16, 20, 22, 23, 22, 20, 16, 12, 8, 5, 3}, {5, 8, 12, 18, 23, 29, 32, 34, 32, 29, 23, 18, 12, 8, 5}, {6, 10, 16, 23, 31, 38, 43, 45, 43, 38, 31, 23, 16, 10, 6}, {7, 13, 20, 29, 38, 47, 53, 55, 53, 47, 38, 29, 20, 13, 7}, {8, 14, 22, 32, 43, 53, 60, 62, 60, 53, 43, 32, 22, 14, 8}, {9, 15, 23, 34, 45, 55, 62, 65, 62, 55, 45, 34, 23, 15, 9}, {8, 14, 22, 32, 43, 53, 60, 62, 60, 53, 43, 32, 22, 14, 8}, {7, 13, 20, 29, 38, 47, 53, 55, 53, 47, 38, 29, 20, 13, 7}, {6, 10, 16, 23, 31, 38, 43, 45, 43, 38, 31, 23, 16, 10, 6}, {5, 8, 12, 18, 23, 29, 32, 34, 32, 29, 23, 18, 12, 8, 5}, {3, 5, 8, 12, 16, 20, 22, 23, 22, 20, 16, 12, 8, 5, 3}, {2, 3, 5, 8, 10, 13, 14, 15, 14, 13, 10, 8, 5, 3, 2}, {1, 2, 3, 5, 6, 7, 8, 9, 8, 7, 6, 5, 3, 2, 1}}/sm;
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 19
Derivative Kernels (S & G)Array[cx, 12, 12]; n = 11; sm = 110.0;
Array[cy, 12, 12]; n = 11; sm = 110.0;cy = {{0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0}}/sm;cx = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}/sm;
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 20
Finding Valleys
• Smooth data, using Gaussian convolution filtering
• Compute gradient at all points, using Savitsky & Golay derivative kernel
• Select starting points
• Follow gradient downward
• Stop when gradient is zero or path reverses
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 21
Malvern Flow TracksHeights convolution filtered
Gaussian filter15 x 15 kernel
Gradients by convolutionSavitsky & Golay11 x 11 kernel
Tracks follow gradients, starting from every 8th pixel
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 22
Gradient-Following CodeFor[jx = 7, jx < nx - 10, jx += 5,{ For[jy = 7, jy < ny - 10, jy += 5, {kx = jx; ky = jy; exit = False;While[zr = gx[[kx - 6, ky - 6]]; zi = gy[[kx - 6, ky - 6]]; zc = 1.0*RandomInteger[{-1, 1}] + ArcTan[zi, zr]/Degree;If[zc < 0.0, zc = 360.0 + zc];rzc = 1 + Mod[(Round[zc/22.5](*+RandomInteger[{-1,1}]*)), 16]; vec = dxy[[rzc]];kx = kx +vec[[1]]; ky = ky + vec[[2]]; If[((kx < 1) || (ky < 1) || y[[ kx, ky]] < 0.0), exit = True]; ]; }] }]
y[[ kx, ky]] = -1.0; sd[[ kx + 7, ky + 7]] = -1.0; kx > 6 && ky > 6 && kx < (nx - 10) && ky < (ny - 10) && ! Exit,
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 23
Possible Applications
• Watershed analysis
• Finding wetlands
• Predicting path of HAZMAT spill
• Back-tracing contaminants to source(s)
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 24
Visualization
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 25
Flow Analysis
• Gradients direct flow to adjacent cells• Flows merge and add (volumetric flow)• Show on plot when flow volume exceeds a given
threshold
Note - Possible improvement:
Add to altitude as flow volume increases
May require re-computation of gradients
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 26
Merging Flows
Set starting point flow to unityMove one pixel along gradientMerge, adding flowsPlot when flow > threshhold
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 27
Finding Ridge Lines
• Smooth data, using Gaussian convolution kernel
• Compute gradients at all points, using Savitsky & Golay derivative kernel
• Select starting points
• Follow against gradient to ridge line
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 28
Malvern Ridge Lines• Ridge lines found
by following gradient backward to maximum
• Starting point every 5 pixels.
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 29
Gradient-Following CodeFor[jx = 7, jx < nx - 10, jx += 5, {If[zc < 0.0, zc = 360.0 + zc]; ]; }] }]
rzc = 1 + Mod[(Round[zc/22.5](*+RandomInteger[{-1,1}]*)), 16]; vec = dxy[[rzc]];kx = kx - vec[[1]]; ky = ky - vec[[2]];If[((kx < 1) || (ky < 1) || y[[ kx, ky]] < 0.0), exit = True];y[[ kx, ky]] = -1.0; sd[[ kx + 7, ky + 7]] = -1.0;For[jy = 7, jy < ny - 10, jy += 5, {kx = jx; ky = jy; exit = False;While[ kx > 6 && ky > 6 && kx < (nx - 10) && ky < (ny - 10) && ! exit,zr = gx[[kx - 6, ky - 6]]; zi = gy[[kx - 6, ky - 6]];zc = 1.0*RandomInteger[{-1, 1}] + ArcTan[zi, zr]/Degree;
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 30
Possible Application
• Locating watershed ridge lines
• Locating source of contamination
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 31
Max., Min., and Curvature
Gradient minimum and maximum points - Filter: S&G 15-point - Point selection; Gradient < 0.4 Curvature > 240
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 32
Contours
Contour map after Gaussian filteringMalvern QuadrangleUSGS DEM Data
• Contours appear as horizontal slices through topography. • Contour spacing can be controlled by software.
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 33
Data Preparation
• Bad data points are removed
• Data is smoothed (Gaussian filter)
• Contour interval is selected(or specific contour set is selected)
• Color scheme is selected
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 34
Plotting Contours
ListContourPlot[y, AspectRatio -> 13.8793/10.6742,
Contours -> {40, 80, 120, 160, 200, 240, 280, 320},
ColorFunction -> "Topographic"]
Notes: Contours produced at indicated heights (meters).Aspect ratio corrects image for latitudeOther color functions possible
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 35
Contour Plot Problems
• Digital filtering required to insure smooth contours
• BEWARE! Contour plots require a LOT of memory in computer.
04/18/23 © 2009 Raymond P. Jefferis III Lect 07 - 36
Discussion