Skip to content

Commit

Permalink
For now, clip anglingXwater events to exclude lakes outside the conti…
Browse files Browse the repository at this point in the history
…nental US.

Later, this should probably happen in spatialjoin.r
See Issue #5.
  • Loading branch information
woodsp committed Mar 8, 2019
1 parent fd20302 commit 237f89d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions code/spatialjoin_fixer.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###
### Clip the current anglingXwater.csv events to ones from continental US
### someday this should happen in spatialjoin.r. see issue #5.
### for now, we'll just export a US-clipped version of anglingXwater for further analyses
###

library(rgdal)
# library(raster)
# library(rgeos)
library(sf)

## Import angling x water data (output of spatialjoin.r)
## and create spatial data frame
axw_raw <- read.csv("analysis/anglingXwater.csv")
axw <- SpatialPointsDataFrame(axw_raw[ ,c("longitude_cent","latitude_cent")], axw_raw, proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))


## Import US border shape
## representing the continental US plus the great lakes
## created by merging and dissolving the US census border with border of great lakes
usa <- readOGR("data", "cb_2017_us_state_20m_N_hydro_p_diss")
usa_wgs <- spTransform(usa, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))

## Join angling events to continental USA shape
angusa <- over(axw, usa_wgs)

## Drop records that aren't in USA
axw_usa <- axw_raw[!is.na(angusa), ]

## Write an updated anglingXwater for events in USA (and great lakes)
write.csv(axw_usa, "./analysis/anglingXwater_usa.csv", row.names=F)

## QAQC
plot(usa_wgs)
plot(axw, add=T)
plot(axw[which(is.na(angusa)), ], add=T, col="red")

0 comments on commit 237f89d

Please sign in to comment.