Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compass-based aspect #5

Open
raymondben opened this issue Jul 1, 2021 · 1 comment
Open

Compass-based aspect #5

raymondben opened this issue Jul 1, 2021 · 1 comment

Comments

@raymondben
Copy link
Member

This will convert aspect-relative-to-grid (i.e. the current aspect tifs) to aspect-relative-to-compass, which is probably what most users will want:

aspect_to_compass <- function(x) {
    crds <- coordinates(x)
    ## calculate longitude of each grid cell in radians
    gridlon <- pi/2 - atan2(crds[, 2], crds[, 1])
    angle_normalise <- function(x) (x + pi) %% (2 * pi) - pi ## normalize angle in radians to range [-pi,pi)
    temp <- angle_normalise(values(x) / 180 * pi) ## convert aspect to radians and normalise to -pi,pi
    temp <- temp - gridlon ## adjust aspect for longitude
    temp <- angle_normalise(temp) / pi * 180 ## normalize again and back to degrees
    values(x) <- temp
    x
}

I've run it for the 1km and 200m single-tif files (see *_aspect_compass.tif). Probably worth pre-computing at 100m as well, but then bundling this little helper into raadtools for users to apply on the fly to 8m? (Would be wise to add a check to it, to ensure that the input x is in zero-centred polar stereo, otherwise it willna work)

@mdsumner
Copy link
Member

look at this

https://gis.stackexchange.com/a/203109/1204

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants