Pull in data via API for Survey data This script uses the NASS API to query the NASS Quickstats service for historic acres harvested of primary crop groups in Willamette basin counties in Oregon from 1969-2013. An example of using the NASS Quickstats API to pull in and examine crop data in Willamette basin.
library(dplyr) ## Warning: package 'dplyr' was built under R version 3.5.2 library(tibble) library(tidyr) library(rnassqs) library(lubridate) library(readr) years <- seq(as.
[Read More]
Adding WMS basemap in R with mapview
Recently I wanted to be able to add a custom basemap of NHDPlus features to mapview leaflet maps. It’s not straitforward out of the box in mapview, but I found the helpful tips to do it here and here.
Below I add the WMS service from EPA Waters along with USGS StreamGage stations in Benton County, OR using the dataRetrieval package.
library(dataRetrieval) library(mapview) library(sf) library(leaflet) Stations <- readNWISdata(stateCd="Oregon", countyCd="Benton") # DataRetrival returns objects as 'attributes' - things like the url used, site metadata, site info, etc - just use attributes(Durham_Stations) to examine siteInfo <- attr(Stations , "siteInfo") stations_sf = st_as_sf(siteInfo, coords = c("dec_lon_va", "dec_lat_va"), crs = 4269,agr = "constant") m <- mapview(stations_sf) m@map = m@map %>% addWMSTiles(group = 'NHDPlus', "https://watersgeo.
[Read More]
R Spatial Tutorial
Just finished putting together and running a half-day R Spatial Workshop covering some cool new R spatial things using packages such as sf
, DataRetrieval
, mapview
, and combining dplyr
chained operations with sf
among other things. And I finally, after a year, got Disqus to start working on my blog! All I did was update blogdown
and rebuild - if only everything were so simple…
Testing the simple features R package
Load and look at basics of simple features package library(devtools) # install_github("edzer/sfr") library(sf) ## Linking to GEOS 3.5.0, GDAL 2.1.1, proj.4 4.9.3 nc <- st_read(system.file("shape/nc.shp", package="sf")) ## Reading layer `nc' from data source `C:\Users\mweber\R\library\sf\shape\nc.shp' using driver `ESRI Shapefile' ## converted into: MULTIPOLYGON ## Simple feature collection with 100 features and 14 fields ## geometry type: MULTIPOLYGON ## dimension: XY ## bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.
[Read More]
Read PostGIS in R
Working with Postgres / PostGIS more now and playing with reading and writing from R and Python. Here’s snippet showing read in of PostGIS in R:
R lookup
Using match and indexing to create a lookup in R
This code takes a lookup table and applies it to a data frame, updating only values for records that occur in the lookup table using indexing and match: