Title: | Smartly Create Maps from R Objects |
---|---|
Description: | Preview spatial data as 'leaflet' maps with minimal effort. smartmap is optimized for interactive use and distinguishes itself from similar packages because it does not need real spatial ('sp' or 'sf') objects an input; instead, it tries to automatically coerce everything that looks like spatial data to sf objects or leaflet maps. It - for example - supports direct mapping of: a vector containing a single coordinate pair, a two column matrix, a data.frame with longitude and latitude columns, or the path or URL to a (possibly compressed) 'shapefile'. |
Authors: | Stefan Fleck [aut, cre] |
Maintainer: | Stefan Fleck <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1.9002 |
Built: | 2025-03-08 05:32:44 UTC |
Source: | https://github.com/s-fleck/smartmap |
A coord_matrix
is a matrix
with two columns named "lon"
and "lat"
to
represent spatial point data. They are used as an intermediary when
converting some R objects to sf::sf()
objects.
as_coord_matrix()
can smartly convert a range of R objects to
coord_matrix
. If you are a package developer and want to add support
for smartmap to your package without having to depend on the heavy sf
package, it is enough to provide an as_coord_matrix()
method.
as_coord_matrix(x, ...) ## Default S3 method: as_coord_matrix(x, ...) ## S3 method for class 'numeric' as_coord_matrix(x, ...) ## S3 method for class 'sf' as_coord_matrix(x, ...) ## S3 method for class 'sfc_POINT' as_coord_matrix(x, ...) ## S3 method for class 'matrix' as_coord_matrix(x, ..., loncol = guess_loncol(x), latcol = guess_latcol(x)) ## S3 method for class 'data.frame' as_coord_matrix(x, ..., loncol = guess_loncol(x), latcol = guess_latcol(x))
as_coord_matrix(x, ...) ## Default S3 method: as_coord_matrix(x, ...) ## S3 method for class 'numeric' as_coord_matrix(x, ...) ## S3 method for class 'sf' as_coord_matrix(x, ...) ## S3 method for class 'sfc_POINT' as_coord_matrix(x, ...) ## S3 method for class 'matrix' as_coord_matrix(x, ..., loncol = guess_loncol(x), latcol = guess_latcol(x)) ## S3 method for class 'data.frame' as_coord_matrix(x, ..., loncol = guess_loncol(x), latcol = guess_latcol(x))
x |
any of the following:
|
... |
passed on to methods |
loncol , latcol
|
|
as_coord_matrix()
returns a coord_matrix
object: A numeric
matrix
with the columns "lon"
and "lat"
(in that order)
https://stackoverflow.com/questions/7309121/preferred-order-of-writing-latitude-longitude-tuples
Can be used to preview spatial R objects
smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'leaflet' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'sf' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## Default S3 method: smap( x, labels = NULL, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'sfc' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'sfg' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'matrix' smap( x, labels = NULL, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") )
smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'leaflet' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'sf' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## Default S3 method: smap( x, labels = NULL, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'sfc' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'sfg' smap( x, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") ) ## S3 method for class 'matrix' smap( x, labels = NULL, ..., tools = TRUE, provider = getOption("smap.providers", "OpenStreetMap") )
x |
any input supported by
|
... |
passed on to methods. |
tools |
|
provider |
|
labels |
an optional |
a leaflet::leaflet object
wp <- matrix( c(16.419684, 48.186065, 16.373894, 48.207853, 16.285887, 48.083053), byrow = TRUE, ncol = 2 ) smap(wp) smap(c(16.419684, 48.186065))
wp <- matrix( c(16.419684, 48.186065, 16.373894, 48.207853, 16.285887, 48.083053), byrow = TRUE, ncol = 2 ) smap(wp) smap(c(16.419684, 48.186065))
Converts R objects to sf::sf objects, but supports a wider range of input data than sf::st_as_sf.
smart_as_sf(x, ...) ## Default S3 method: smart_as_sf(x, ...) ## S3 method for class 'data.frame' smart_as_sf(x, ...) ## S3 method for class 'character' smart_as_sf(x, ...)
smart_as_sf(x, ...) ## Default S3 method: smart_as_sf(x, ...) ## S3 method for class 'data.frame' smart_as_sf(x, ...) ## S3 method for class 'character' smart_as_sf(x, ...)
x |
any of the following:
|
... |
ignored |
an sf::sf data.frame
smart_as_sf.default()
looks if an sf::st_as_sf()
,
sf::st_as_sfc()
or as_coord_matrix()
method exists for x
(in
that order). If you are a package developer and want to support smartmap
for a custom S3 class in your package, it is enough to provide one of these
methods.
smart_as_sf(data.frame(lat = c(1,2,3), longitude = c(3,4,5))) smart_as_sf(c(1, 2))
smart_as_sf(data.frame(lat = c(1,2,3), longitude = c(3,4,5))) smart_as_sf(c(1, 2))
Convert coordinate matrices to sf objects
## S3 method for class 'coord_matrix' st_as_sf(x, ...)
## S3 method for class 'coord_matrix' st_as_sf(x, ...)
x |
|
... |
ignored |
an sf::sf()
object with an sfc_POINT
-geometry column
Convert coordinate matrices to sfc objects
## S3 method for class 'coord_matrix' st_as_sfc(x, ...)
## S3 method for class 'coord_matrix' st_as_sfc(x, ...)
x |
|
... |
ignored |
an sf::sfc()
object of subclass sfc_POINT
Convert sf objects to normal data.frames with longitude and latitude colu,ns
unsf(x, coord_names = c("lon", "lat"))
unsf(x, coord_names = c("lon", "lat"))
x |
an |
coord_names |
|
a data.frame