[R-sig-Geo] Plotting direction vectors from an aspect map
Carson Farmer
carson.farmer at gmail.com
Fri Sep 16 12:48:51 CEST 2011
I've done something similar for my own work (based on polygon
centroids, but the idea is the same). The following (messy) code
should do what you want using base graphics. The inputs are the
coordinates of your cell centers, the angles of your arrows, and then
a few additional parameters which control size and shape etc.
Hope it can be of some use?
Carson
point.arrows <- function (coords, angles, size = 0.08, arrow = FALSE,
length=0.05, point = FALSE, point.col=NULL, ...)
{
is.xy <- (is.list(coords) && all(c("x", "y") %in% names(coords)))
xy <- if (is.xy) {
coords
}
else xy.coords(coords[,1], coords[,2])
x <- xy$x
y <- xy$y
n <- length(x)
if (point) points(x, y, col=point.col, ...)
ppin <- par("pin")
pusr <- par("usr")
if (length(size) == n)
sizes <- size/max(size)
else
sizes <- size[1]
xr <- sizes * abs(pusr[2L] - pusr[1L])/ppin[1L]
yr <- sizes * abs(pusr[4L] - pusr[3L])/ppin[2L]
z <- numeric()
deg <- angles
if (arrow)
arrows(x, y, x + xr * sin(deg), y + yr * cos(deg), length, ...)
else
segments(x, y, x + xr * sin(deg), y + yr * cos(deg), ...)
}
On Fri, Sep 16, 2011 at 2:17 AM, Jonathan Greenberg
<greenberg at ucdavis.edu> wrote:
> R-sig-geo'ers:
>
> Given an aspect raster (GDAL-readable), is there a way to plot the
> aspect image using arrows representing each cell's direction? I'm
> assuming I have to convert the raster to a set of points -- are there
> arrow symbols and, if so, can you rotate them based on some parameter?
>
> Thanks!
>
> --j
>
> --
> Jonathan A. Greenberg, PhD
> Assistant Project Scientist
> Center for Spatial Technologies and Remote Sensing (CSTARS)
> Department of Land, Air and Water Resources
> University of California, Davis
> One Shields Avenue
> Davis, CA 95616
> Phone: 415-763-5476
> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Carson J. Q. Farmer
ISSP Doctoral Fellow
National Centre for Geocomputation
National University of Ireland, Maynooth,
http://www.carsonfarmer.com/
More information about the R-sig-Geo
mailing list