Comments (4)
Follow up from my previous, how does this look for the tree-level point patterns?
library(rFIA)
library(dplyr)
library(sf)
## Using the canned RI subset
data(fiaRI)
## Get spatial information for all of most recent plot visits
plts <- fiaRI %>%
clipFIA() %>%
area(byPlot = TRUE, returnSpatial = TRUE) %>%
## Albers equal area (meters)
st_transform(crs = 5070)
## Get coordinates of center subplot as a dataframe
c.coords <- st_coordinates(plts) %>%
as.data.frame() %>%
## Label the center SUBP appropriately
mutate(pltID = plts$pltID,
SUBP = 1)
## Imagine the non-center SUBP coordinates as the vertices of an
## equilateral triangle, where sides are of length sqrt(120^2 + 120^2) dt
## We can then compute the x and y coordinates of non-center SUBPs directly
side.length = sqrt(120^2 + 120^2) * 0.3048 # meters
## Compute coordinates of SUBP 2
t.coords <- c.coords %>%
## Shift X 120ft up
mutate(Y = Y + (120 * 0.3048)) %>%
mutate(SUBP = 2)
## Coordinates of bottom SUBPs
bl.coords <- c.coords %>%
## Some trig
mutate(Y = Y - (side.length / 2),
X = X - (side.length / 2)) %>%
mutate(SUBP = 3)
br.coords <- bl.coords %>%
## Some trig
mutate(X = X + side.length) %>%
mutate(SUBP = 4)
## Combine all coordinates
coords <- bind_rows(c.coords, t.coords, bl.coords, br.coords) %>%
rename(X.PLOT = X, Y.PLOT = Y)
## Use spatial buffers to make polygons subplots
subp <- coords %>%
st_as_sf(coords = c('X.PLOT', 'Y.PLOT')) %>%
st_buffer(dist = 24 * 0.3048)
## Now get the offsets in tree location from plot center
tree <- fiaRI %>%
clipFIA() %>%
tpa(grpBy = c(SUBP, TREE, DIST, AZIMUTH), byPlot = TRUE) %>%
## Subplot only
filter(TPA == 6.018046) %>%
## Convert degrees to radians
## Convert feet to meters
mutate(rad = AZIMUTH * (pi/180),
DIST = DIST * 0.3048) %>%
mutate(x = case_when(AZIMUTH %in% c(0, 180) ~ 0,
AZIMUTH %in% c(90, 270) ~ DIST,
AZIMUTH < 90 ~ sin(rad) * DIST,
AZIMUTH < 180 ~ sin(pi - rad) * DIST,
AZIMUTH < 270 ~ -sin(rad - pi) * DIST,
AZIMUTH < 360 ~ -sin(2*pi - rad) * DIST),
y = case_when(AZIMUTH %in% c(0, 180) ~ 0,
AZIMUTH %in% c(90, 270) ~ DIST,
AZIMUTH < 90 ~ cos(rad) * DIST,
AZIMUTH < 180 ~ -cos(pi - rad) * DIST,
AZIMUTH < 270 ~ -cos(rad - pi) * DIST,
AZIMUTH < 360 ~ cos(2*pi - rad) * DIST)) %>%
select(pltID,
SUBP,
X.TREE = x,
Y.TREE = y)
## Make tree coordinates absolute and make spatial
tree.coords <- coords %>%
left_join(tree, by = c('pltID', 'SUBP')) %>%
mutate(X = X.PLOT + X.TREE,
Y = Y.PLOT + Y.TREE) %>%
## Drop non-treed forested plots
filter(!is.na(X) | !is.na(Y)) %>%
st_as_sf(coords = c('X', 'Y'))
## Check it out for a single plot
library(ggplot2)
ggplot() +
geom_sf(data = filter(subp, pltID == '1_44_1_228')) +
geom_sf(data = filter(tree.coords, pltID == '1_44_1_228'))
from rfia.
Sorry for the (very) delayed reply here! I accidentally shut off my email notifications, and I'm just now seeing issues that were opened in August.
I haven't worked with ppp objects before, however I do have some code that will produce spatial polygons of FIA plot boundaries, and I will follow up with some code that will produce a point pattern (sf) of tree locations within plots.
For the plot boundaries, how does this look?
library(rFIA)
library(dplyr)
library(sf)
## Using the canned RI subset
data(fiaRI)
## Get spatial information for all of most recent plot visits
plts <- fiaRI %>%
clipFIA() %>%
area(byPlot = TRUE, returnSpatial = TRUE) %>%
## Albers equal area (meters)
st_transform(crs = 5070)
## Get coordinates of center subplot as a dataframe
c.coords <- st_coordinates(plts) %>%
as.data.frame() %>%
## Label the center subplot appropriately
mutate(plot = 1:n(),
subplot = 1)
## Imagine the non-center subplot coordinates as the vertices of an
## equilateral triangle, where sides are of length sqrt(120^2 + 120^2) dt
## We can then compute the x and y coordinates of non-center subplots directly
side.length = sqrt(120^2 + 120^2) * 0.3048 # meters
## Compute coordinates of subplot 2
t.coords <- c.coords %>%
## Shift X 120ft up
mutate(Y = Y + (120 * 0.3048)) %>%
mutate(subplot = 2)
## Coordinates of bottom subplots
bl.coords <- c.coords %>%
## Some trig
mutate(Y = Y - (side.length / 2),
X = X - (side.length / 2)) %>%
mutate(subplot = 3)
br.coords <- bl.coords %>%
## Some trig
mutate(X = X + side.length) %>%
mutate(subplot = 4)
## Combine all coordinates
coords <- bind_rows(c.coords, t.coords, bl.coords, br.coords)
## Use spatial buffers to make polygons delineating micro-, sub-, and macro-plots
# subplots
subp <- coords %>%
st_as_sf(coords = c('X', 'Y')) %>%
st_buffer(dist = 24 * 0.3048)
# microplots
micr <- coords %>%
mutate(X = X + (12 * 0.3048)) %>%
st_as_sf(coords = c('X', 'Y')) %>%
st_buffer(dist = 6.8 * 0.3048)
# macroplots
macr <- coords %>%
st_as_sf(coords = c('X', 'Y')) %>%
st_buffer(dist = 58.9 * 0.3048)
## Set projection appropriate prior to writing
st_crs(subp) <- 5070
st_crs(micr) <- 5070
st_crs(macr) <- 5070
## Make sure things look right
library(ggplot2)
ggplot() +
geom_sf(data = filter(macr, plot == 1)) +
geom_sf(data = filter(subp, plot == 1)) +
geom_sf(data = filter(micr, plot == 1))
from rfia.
Hunter, thanks a ton for looking into this -- stay tuned, I think we developed (independently) a workflow working and after I confirm, I can tweak into a functional form and send to you as a potential add-on to rFIA if you'd like!
from rfia.
That would be excellent - we're always open to extensions!
from rfia.
Related Issues (20)
- mergeSmallStrata(): 'buf' not 'buff' to id intensified PNW strata HOT 1
- readFIA issues HOT 2
- Issue with getFIA - url connects to 404 page HOT 6
- Difficulty using huc watersheds as polygons HOT 2
- Summarizing by subplot gives wrong values
- rFIA::tpa() removes trees with no measured DIA
- FIA databases appear to be inaccessible HOT 2
- Error in `dplyr::select()`: Column `geom` doesn't exist. HOT 1
- 'EVALID' not found error using 'readFIA' from file & using 'getFIA' for multiple states HOT 7
- df issue in udTreeDomain() within biomass()
- getFIA URL error HOT 2
- growMort bySizeClass missing removed stems
- Failure with dev dtplyr
- fa_mean doesn't exist HOT 5
- 'invasive' function not finding INVASIVE_SUBPLOT_SPP table HOT 1
- Newest version of R not compatible
- seemingly strange behavior from customPSE()
- 'DRYBIO_WDLD_SPP' and Column `CARBON_STANDING_DEAD` not found HOT 4
- Error when downloading tables for several states HOT 3
- growMort function won't run
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rfia.