Create a Basic Map with ElmerGeo Data
create-a-map-with-elmergeo-data.Rmd
With just two packages you can create an interactive map that displays layers constructed from feature classes in PSRC’s ElmerGeo database. This short article will show you how.
What is Leaflet?
Leaflet is a popular open-source JavaScript library for interactive maps. R has a package leaflet that makes it easy to integrate and control Leaflet maps in R. Leaflet maps can be made to display the spatial data in one or more simple-feature (or sf) layers.
What is sf?
SF stands for “simple features”, a standardized way of encoding spatial data. In R, spatial datasets are typically stored as sf objects.
So how do I make a map?
You can make a simple map in essentially two steps (three if you count loading the libraries). The example below create a layer of county polygons from the COUNTY_BACKGROUND feature class in ElmerGeo.
- Create the layer
Here we create an sf layer from the feature class in
ElmerGeo, using the st_read_elmergeo()
function:
my_county_layer <- st_read_elmergeo('COUNTY_BACKGROUND')
- Display our layer on a leaflet map.
This creates a map with very simple styling. You can learn how to enhance its aesthetics through the leaflet documentation.
If you are using RStudio this map should automatically be rendered in the viewer pane.
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(data = my_county_layer)