On using R as a geographic information system.
Robin Lovelace, Jakub Nowosad and Jannes Muenchow’s free textbook, Geocomputation with R, seems to be the most up-to-date resource. Slightly more recently updated but with less promotion, Edzer Pebesma and Roger Bivand’s Spatial Data Science seems like it might be good. Manuel Gimond’s lecture notes are good: Intro to GIS and Spatial Analysis.
For theory see spatial statistics.
Technical details go here.
There are some standards to be aware of.
The classic R format for spatial data information is sp, which is some kind of convention for encoding spatial data in something similar to, but not totally like, a dataframe.
Much spatial code in R uses
sf has become the hotness. This is several things.
Firstly there is a standard (Simple features / simple feature access) which is nothing to do with R.
This has a formal ISO standard number and reams of documentation about how computers can handle the spatial geometry and informatics.
This standard now underlies ESRI ArcGIS), GDAL and the GeoJSON standard.
For now, you need to know both standards exist and convert between them accordingly.
Conversion is apparently simple according to the
as_Spatial()allows to convert
spcompatibility. You can also use
as(x, "Spatial")To transform
Did you follow that?
R will happily plot a map if you give it some mapping polygons. However, often you want something with more of the affordances of modern interactive web maps. Fancy map tiles with streets and terrain and such are available from map providers such as google maps or stamen. But how to use them in R? Many options.
leafletR interfaces with leaflet.js. It is independently useful to have also because it has a GeoJSON export function, toGeoJSON which is small, light and fast via the ogre service. For complicated or big projects it falls back to rgdal.
GDAL library dependencies
rgdal is an interface to the classic geodata infrastructure GDAL.
rgdal is notoriously fiddly to install and has many system dependencies, but it can do everything, I think.
On an ubuntu system, I needed to install
devtools and get the packages installed by forcing the tippy-top latest version to install:
install.packages("rgeos", repos="http://R-Forge.R-project.org", type="source") install.packages("rgdal", repos="http://R-Forge.R-project.org", type="source") install.packages("devtools") devtools::install_github("r-spatial/sf")