create swath profiles in grass gis
TRANSCRIPT
This and more at my website: https://sites.google.com/site/sorsbysj/ LinkedIn: https://www.linkedin.com/in/skylersorsby
Swath profiles in GRASS gis
Author: Skyler Sorsby
While traditional A-A’ line profiling can produce meaningful 2-D snapshots of topography, visuals of this
type fail to capture the broader morphometric regime. Enter swath profiles (Fig. 1). As the data is
collected for each point in the profile line, the region perpendicular to the profile line is statistically
surveyed (max/mean/min, etc). Thus, the product is a statistically relevant 2-D rendition of a 3-D surface
(Fig. 2). Some have proposed that swath profiles may
be approximated by the superimposition of many
single profiles. However, viewing multiple profiles
superimposed is neither visually appealing nor
representative—the values plotted only describe a
set of finite lines, not a regional average. Other
researchers write high-level algorithms in computing
languages to accomplish the task, yet the visually
powerful effects of a swath profile may be easily
derived with simple tools within the GRASS gis
interface. With this guide, I intend to clearly
illustrate how GRASS may be used to this purpose.
Geospatially, the idea is to order a set of vector
points into a line, and tell each point to collect
statistics of a raster DEM for a set interval
perpendicular to the line. Practically, this may be
accomplished with three tools: v.mkgrid, v.rast.stats,
and v.to.points.
1) v.mkgrid This GRASS tool allows for the creation of a nxn grid of vector areas at a user-defined orientation. Each grid square has a topological feature known as a centroid. The centroid is the weighted center of the polygon; thus, for a perfectly symmetrical shape (like a grid square), each centroid appears halfway between the square’s edges. For a 1xn (columns x rows) matrix, this generates a single-column array of n user-defined rows, with each centroid falling upon
a common straight line. Consequently, if the rows are broad and short, sampling elevation values (mean/min/max/etc) nwithin the bounds of each row can proxy “looking off to the side” for each centroid. The trick lies within distillation of these values, computed for each polygonal cell, to the centroid. 2) v.rast.stats Once the oriented 1xn grid is created with v.mkgrid, an underlying DEM may be sampled using
v.rast.stats. You’ll need to add a column to your swath grid shapefile first, with v.db.addcol (the syntax
elev double precision works for me)—you’ll need to add a column prior, anytime you wish to upload
values to a vector with v.rast.stats.
Figure 1. Shaded relief map of the Yakima fold-and-thrust belt. The black dashed line is a standard topographic line profile. The white box is a swath.
N
A
A’
This and more at my website: https://sites.google.com/site/sorsbysj/ LinkedIn: https://www.linkedin.com/in/skylersorsby
Figure 2. Elevation profiles from the map in figure 1. The black and gray are the swath profile; the white dashed line is a line profile.
3) v.to.points
When statistics have been assigned to each cell in the vector grid, these values may be distilled to the
centroid, creating a new vector point file in the process. This is accomplished by using v.to.points—
although documentation hints that this tool is meant for generating points along a line (not the case for
us). This problem may be circumnavigated by checking the “centroids” box under the “feature type”
heading. The result will be a shapefile of points, each point containing the max/mean/min/etc statistics
for elevation of the topography immediately adjacent. Now, the only missing attribute is distance along
the profile. Since each grid square was the same height and each centroid was centered vertically within
each grid square, the distance between the points is simply the height of each grid square. Accordingly,
distance will be a column of linearly-progressing values, easily auto-generated in Excel.
4) v.out.ogr
The final step is to export your point shapefile to Excel as a .csv file, for auto-generation of a distance
column and plotting. This tool may be finicky at times, sometimes requiring an entire file pathway to
save to, others requiring only a name with which to label the containing folder (which will be placed in
your ‘Users’ folder on the C:// drive).
5) Once you’ve exported your elevation graph of min/mean/max elevation from Excel as a pdf, you may
easily augment it in a vector editing program like Inkscape (freeware) or Adobe Illustrator (certainly not
freeware). In Inkscape, I’ve found that the easiest way to create a “filled” min/max envelope (see Fig. 2)
is to make the min/max lines very narrow, connect them with two short vertical segments of the same
color (to close the area), and use the paint bucket tool to give the area some pale color. In Illustrator,
this task is much easier, as closing the area with two vertical lines automatically registers the shape as a
polygon, whose interior “fill” may be set to any color you wish (no paint bucket tool involved-you get
what you pay for!).
6) In the event that you’re working with data in a different coordinate system (say, you have a file of
vector points along the course of a stream, with distance calculated for each point along the length of
the stream—a curvy path), and you need to place your elevation swath profile into those coordinates.
A A’
This and more at my website: https://sites.google.com/site/sorsbysj/ LinkedIn: https://www.linkedin.com/in/skylersorsby
The workflow is the same as above, but involves creation of a second grid, the same height and corner
coordinates, but with much longer rows (to “reach out” orthogonal to the profile line and capture the
values of the other point shapefile whose coordinates you’re attempting to reach into). Here is a
simplified workflow for placing the swath profile into the coorinates of an adjacent river, for example, to
compare the long profile with topographic relief:
1) Have a raster of river points, each point containing distance along the river (you may get a
raster of river lines with the r.watershed, convert the raster to vector lines with r.to.vect, get rid
of everything except your main channel with the digitizer tool, convert to raster points with
v.to.rast (make sure it’s binary—river has a value of 1, else=NULL), multiply by the output of
r.stream.distance to get a raster image of distance along the stream).
2) Create, as before a 1xn grid polygon for the swath profile with v.mkgrid (n is the number of
rows you want)
3) Create another 1xn grid, VERY WIDE, such that the rows line up exactly vertically , but extend
laterally completely across any river points with v.mkgrid
4) Convert the river points to a raster, if you haven’t done this already each cell containing
distance values, with v.to.rast
5) Use v.rast.stats to get the mean distance for each row of the extended polygon (may have to
use the Tk/Tcl GUI for GRASS—my python GUI seems buggy for this tool).
6) Use v.rast.stats to get the elevation statistics for each row of your swath polygon (as you did
before).
7) Distill the swath rows to points with v.to.points, as you did before.
8) Use v.to.rast to convert the extended polygon to a raster with mean distance values (still by
row)
9) Use v.what.rast to sample the extended polygon’s raster and obtain the mean river distance
values for each row in the normal swath polygon.
The basic premise is this: After creating your swath profile, you want to attach a “distance along the
river” coordinate to each elevation—say, to compare structural relief of a linear set of features with a
river’s long profile (and geometry), which certainly ISN’T linear. To do this, you’ll rasterize the river
distance column of your river shapefile (points, I’m assuming), such that a new one column/many row
grid oriented the same way as your swath grid but extending far beyond, can capture the mean values
orthogonal to the swath. The extended grid, having captured the mean river distance, is now rasterized.
The key is that the rasterization has now deposited this orthogonal mean river distance beneath the
centroids of the original swath—effectively “reaching out and pulling in orthogonal river distance”.
Using some sort of out-of-the-box spatial joining technique will not work as a substitute.
This and more at my website: https://sites.google.com/site/sorsbysj/ LinkedIn: https://www.linkedin.com/in/skylersorsby
Figure 3. Map showing the original swath (the narrow grid), the wider swath (whose sole purpose is to sample river distances, to relaty to the original swath). When the river distances are used, rather than the straight-line profile distance, the original swath will align with river-parallel features (useful for contrasting with changes in planform and geometry as topographic features are crossed).
Figure 4. A pseudo “swath profile”, made from superimposing adjacent line profiles. Needless to say, it’s messier and less statistically relevant than a real swath.
,
,
River points containing
downstream distance
Centroids
to which
swath values
are distilled
Large swath grid, to capture river distances for profile Original swath
This and more at my website: https://sites.google.com/site/sorsbysj/ LinkedIn: https://www.linkedin.com/in/skylersorsby