library(rgdal)
## Loading required package: sp
## rgdal: version: 1.0-7, (SVN revision 559)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.3, released 2015/09/16
## Path to GDAL shared files: /usr/local/Cellar/gdal/1.11.3/share/gdal
## Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
## Path to PROJ.4 shared files: (autodetected)
## Linking to sp version: 1.1-1
library(leaflet)
library(scales)
library(htmltools)
URL <- "http://pubs.usgs.gov/ds/817/downloads/USGSWind_Turbine_03_2014.zip"
fil <- basename(URL)
if (!file.exists(fil)) download.file(URL, fil)
fils <- unzip(fil)
shp <- grep("shp$", fils, value=TRUE)
wind <- readOGR(shp, ogrListLayers(shp)[1], stringsAsFactors=FALSE)
## OGR data source with driver: ESRI Shapefile
## Source: "./Onshore_Industrial_Wind_Turbine_Locations_for_the_United_States_to_March_2014.shp", layer: "Onshore_Industrial_Wind_Turbine_Locations_for_the_United_States_to_March_2014"
## with 48976 features
## It has 31 fields
wind_wgs <- spTransform(wind, CRS("+proj=longlat +datum=WGS84"))
wind_pts <- setNames(as.data.frame(coordinates(wind_wgs)), c("lng", "lat"))
wind_popups <- with(wind@data, sprintf("<b>%s</b><hr noshade size='1'/>
Capacity: %s<br/>
On-line year: %s<br/>
Tower type: %s<br/>
Blade Length: %s m<br/>
Rotor Swept Area: %s m<sup>2</sup><br/>
Total Height: %s m<br/>
Attribution Confidence: %s",
htmlEscape(site_name),
htmlEscape(total_cpcy),
htmlEscape(on_year),
htmlEscape(type_tower),
htmlEscape(blade_l),
htmlEscape(comma(rotor_s_a)),
htmlEscape(total_ht),
htmlEscape(conf_attr))
)
leaflet(wind_pts) %>%
addTiles() %>%
addMarkers(lng=~lng, lat=~lat, popup=wind_popups,
clusterOptions=markerClusterOptions())