Stephen Lightfoote, blogdown.rmd=TRUE

4897 minute read

Motivation

USGS just came out with an awesome updated database of operating wind turbine locations in the United States. I wanted to show how you can extract and view this data yourself, using R.

https://eerscmap.usgs.gov/uswtdb/

Get Data

First download the data from USGS.

url<-'https://eerscmap.usgs.gov/uswtdb/assets/data/uswtdbCSV.zip'
tmp<-tempfile()
download.file(url,tmp)
unzip(tmp)
unlink(tmp)
usgs<-read_csv('uswtdb_v1_0_20180419.csv')

Tidy

I just want to tidy up a bit.

usgs<-na_if(usgs,-9999) # convert -9999 to NA

Map Spatially

I’m going to be using the leaflet library for the map. This will replicate much of the functionality of USGS’s Viewer. R-shiny is probably a better way to render the leaflet map because there’s much more control functionality that can be added. But for this example I think it’s fine just using what leaflet has out of the box. Note: the “marker” option has a bit of lag here when zooming around whereas the heatmap is likety-split.

# create labels for points
labels<-sprintf(
             "<strong>%s</strong><br/>TurbineID = %s<br/>capacity = %g MW<br/>COD = %s<br/>OEM = %s<br/>Model = %s<br/>Hub Height = %g<br/>Rotor Diameter= %g",
             usgs$p_name, usgs$case_id,usgs$t_cap,usgs$p_year,usgs$t_manu,usgs$t_model,usgs$t_hh,usgs$t_rd
           ) %>% lapply(htmltools::HTML)

# define a color scheme for different projects
pal <- colorFactor('viridis', usgs$p_name)

# render map
leaflet(usgs) %>%
  addProviderTiles(providers$CartoDB.Positron,group ='CartoDB.Positron') %>%
  addProviderTiles(providers$Esri.WorldImagery, group = "Esri.WorldImagery") %>%
  addHeatmap(lng = ~xlong, lat = ~ylat,blur = 20,radius = 10,cellSize = 2,group='heatmap') %>%
  addCircleMarkers(lng = ~xlong,lat = ~ylat,label=labels,group = 'markers',stroke = T,fillColor = ~pal(p_name),color= "#777777",fillOpacity=.8,clusterOptions = markerClusterOptions()) %>%
  addMeasure() %>%
  addLayersControl(
    baseGroups = c("CartoDB.Positron", "Esri.WorldImagery"),
    overlayGroups = c("heatmap", "markers"),
    options = layersControlOptions(collapsed = FALSE)
  ) %>% 
  hideGroup("markers")