Last active
May 6, 2018 18:03
-
-
Save ryan-hill/120d9ad34a7ab64a13c9c641b2390a93 to your computer and use it in GitHub Desktop.
Gist used to create hidden answers for challenge questions in Intro to GIS in R course (https://ryan-hill.github.io/sfs-r-gis-2018/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Read in gages data and convert to spatial points data frame | |
#Give it the **pts** CRS and reproject to **pts2** CRS | |
#Select out Portland and use `gBuffer` from `rgeos` package with width = 50,000 meters. | |
#Use `over` function from `sp` package to identify overlapping points with 50 km buffer. | |
library(sp); library(rgeos) | |
gages <- read.csv('./data/StreamGages.csv') | |
gages <- SpatialPointsDataFrame(gages[c('LON_SITE','LAT_SITE')], gages) | |
gages@proj4string <- pts@proj4string | |
gages <- spTransform(gages, proj4string(pts2)) | |
portland <- pts2[pts2$cities == 'Portland', ] | |
buff_pdx <- gBuffer(portland, byid = T, width = 50000) | |
pdx_gages <- over(buff_pdx, gages, returnList = T) | |
pdx_gages <- data.frame(pdx_gages) | |
nrow(pdx_gages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment