The potential package provides functions to compute potential models as defined by John Q. Stewart. Several options are available to customize the models, for example it is possible to refine the distance friction functions or to use custom distance matrices. Some functions use parallelization to improve their efficiency.
The aim of potential is to replace potential-related functions of the SpatialPosition package. SpatialPosition was built to compute 3 spatial position models (Stewart potentials, Reilly catchment areas, Huff catchment areas) in a time where sf was not published yet (May 2015). potential functions use a simplified interface and are more efficient than their counterpart in SpatialPostion. My recommendation to SpatialPositon users is thus to switch to potential for the computation of potentials.
A didactic vignette describing the methodology and functions is provided as well as a website.
maptiles gives access to a lot of tiles servers, but it is possible to add others. The following example demonstrates the setting of a map tiles server and how to cache the original tiles for future use:
The following figure shows mini maps for most of the tiles providers available:
Attribution of map tiles
All maps available through maptiles are offered freely by various providers. The only counterpart from the user is to properly display an attribution text on the maps. get_credit() displays a short credit text to add on each map using the downloaded tiles.
Most of maptilescode comes from getTiles() and tilesLayer() functions in cartography. It appears useful to me to have a package focused on the download and display of map tiles only. On the technical side, it uses terra instead of raster for managing raster data.
There are many alternative packages that pursue the same objective as maptiles. Some focus on a specific map tiles provider (e.g. mapbox, google, OpenStreetMap) or on a specific graphics device (ggplot2). The goal of maptiles is to be flexible enough to allow the use of different providers and to have a minimal number of robust and modern dependencies. However, depending on the use case, one of following packages may better suit your needs:
These 3 functions are well described by their creator, Diego Hernangómez, on his blog.
getTiles()gets map tiles from various tile servers.
The function has gained caching capacities (through cachedir and forceDownload arguments). Users can now cache tiles in a folder and reuse them across R sessions.
More than 50 tile servers have been included and other can be added by users.
It is possible to use Thunderforest tiles with an API key.
The barscale() function plots a scale bar on a map, a new unit argument has been added to plot the scale bar in meters, kilometers or miles.
Under the Hood
cartography does not use rosm anymore to import map tiles. The package is working great but its maintainer, Dewey Dunnington, suggests that it will not evolve much and that other package will appear to replace it. Thus we have decided to use slippymath and internal code to download tiles. A (positive) side effect of this replacement is a decrease in the indirect dependancies of cartography.
cartography appears to be robust to the changes introduced by the last sf version (v0.9). This version takes into account the new representation of coordinate reference systems proposed by GDAL and PROJ. More information on this here.
In cartography several functions have a pos or legend.pos argument. These arguments can take the following values: « topleft », « top », « topright », « right », « bottomright », « bottom », « bottomleft », « bottomleftextra », « left » or a vector of two coordinates in map units (c(x, y)).
The osrm package is an interface between R and the OSRM API. OSRM is a routing service based on OpenStreetMap data. This package allows computing shortest paths, travel time and travel distance matrices between points.
The osrm package functions are:
osrmTable(): travel time and travel distance matrices between points.
osrmRoute(): shortest path between two points.
osrmTrip(): shortest trip between multiple unordered points.
osrmIsochrone(): polygons of isochrones
This package relies on the use of an OSRM server (tested with version 5.22.0 of OSRM). By default the package uses the OSRM demo server (API usage policy). It is possible to use a different server if you want to make intensive use of the API. You can run your own instance of OSRM following guidelines provided on the OSRM GitHub repository. The simplest solution is the one based on docker containers.
The main change introduced by this update is the support of sf objects as input and output in all functions: using the argument returnclass = "sf" in osrmRoute(), osrmIsochrone() and osrmTrip() allows to output sf objects.
The algorithm for isochrones has been changed to a more robust one that uses isoband package.
In the following example more than 800 shortest paths to the useR2019 conference in Toulouse are displayed:
In the next example isochrones around Toulouse are displayed:
The popcircle package has been released on GitHub. This one-function package computes circles with areas scaled to a variable and displays them using a compact layout (higher values in the center, lower values at the periphery). Original polygons are scaled to fit inside these circles (size are roughly proportional, not strictly).
The circles creation relies on packcircles, spatial data manipulation relies on sf.
The next example was a bit more difficult to design. We had to work on some multipolygons countries (e.g. France, USA or Russia) in order to keep only the largest polygon.
As popcircle produces sf objects it is possible to display them interactively:
popcircle changes the position of spatial units. It will work better with regions already well known to the target audience. Chances are that the first figure on Martinique municipalities will be more appropriate and effective for the inhabitants of Martinique.
The tanaka package has been released on CRAN. This package is a simplified implementation of the Tanaka method. Also called « relief contours method », « illuminated contour method » or « shaded contour lines method », the Tanaka method enhances the representation of topography on a map using shaded contour lines. North-west white contours represent illuminated topography and south-east black contours represent shaded topography.
The contour lines creation relies on isoband, spatial data manipulation and display rely on sf.
tanaka is a small package with only two functions:
tanaka() uses a raster object and displays the map directly;
tanaka_contour() builds the isopleth polygon layer.
This is a typical example of the package usage based on the dataset shipped with the package.
In the second example, the elevatr package is used to download an elevation raster on a specific area. Then the tanaka_contour() function is used to create an isopleth layer and finally the tanaka()function is used to to display the map with a custom color palette.
# use elevatr to get elevation data
ras <- get_elev_raster(
locations = data.frame(
x = c(6.7, 7), y = c(45.8,46)
z = 10, prj = "+init=epsg:4326",
clip = "locations"
# create the isopleth layer
iso <- tanaka_contour(
x = ras,
breaks = seq(500,4800,250)
# display the isopleth layer
# create a custom color palette
pal <- colorRampPalette(colors = c("#F9D3A1", "#1E315B"))
# display the map
tanaka(iso, col = pal(nrow(iso)))
This post shows how to build a colored pencil map with R.
The cartography package (in its development version) has gained a getPencilLayer() function that transforms a POLYGON or MULTIPOLYGON layer into a MULTILINESTRING layer mimicking a pencil drawing pattern.
This post exposes some cartographic explorations of the OpenStreetMap (OSM) database with R.
These explorations begin with the downloading and the cleaning of OSM data. Then I propose a set of map visualizations of the spatial distributions of bars and restaurants in Paris. Of course, these examples could be adapted to other spatial contexts and thematics (e.g. pharmacies in Roma, bike parkings in Dublin…).
cartography allows various cartographic representations such as proportional symbols, chroropleth, typology, flows or discontinuities maps. It also offers several features enhancing the graphic presentation of maps like cartographic palettes, layout elements (scale, north arrow, title…), labels, legends or access to some cartographic APIs.
Up to version 1.4.2 cartography was mainly based on sp and rgeos for its spatial data management and geoprocessing operations. These dependencies have been as much as possible replaced by sf functions since version 2.0.0.
Most functions are kept unchanged except for the addition of an x argument used to take sf objects as inputs.
See the NEWS file for the full list of changes and see sf README in case of installation problems with sf. Continuer la lecture de New version of the cartography package→