read data
rgdal::ogrListLayers(fn)
## [1] "ne_10m_airports"
## attr(,"driver")
## [1] "ESRI Shapefile"
## attr(,"nlayers")
## [1] 1
data <- rgdal::readOGR(fn, layer = "ne_10m_airports")
## OGR data source with driver: ESRI Shapefile
## Source: "../FOSSGIS-workshop/data/ne_10m_airports/ne_10m_airports.shp", layer: "ne_10m_airports"
## with 891 features
## It has 10 fields
sp data structures
my_quakes <- quakes
head(my_quakes)
## lat long depth mag stations
## 1 -20.42 181.62 562 4.8 41
## 2 -20.62 181.03 650 4.2 15
## 3 -26.00 184.10 42 5.4 43
## 4 -17.97 181.66 626 4.1 19
## 5 -20.42 181.96 649 4.0 11
## 6 -19.68 184.31 195 4.0 12
class(quakes)
## [1] "data.frame"
sp::coordinates(my_quakes) = ~ long + lat
class(my_quakes)
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
my_quakes@bbox
## min max
## long 165.67 188.13
## lat -38.59 -10.72
my_quakes@proj4string
## CRS arguments: NA
my_quakes@proj4string <- sp::CRS("+proj=longlat +datum=WGS84")
library(leaflet)
leaflet(width = "100%") %>% addProviderTiles("CartoDB") %>%
addCircleMarkers(
data = my_quakes[1:20, ],
radius = ~ sqrt(mag) * 10
)
write data
rgdal::writeOGR(
my_quakes,
"../FOSSGIS-workshop/data/sp_quakes.geojson",
layer = "my_quakes",
driver = "GeoJSON"
)