Type: | Package |
Title: | Smartly Create Maps from R Objects |
Version: | 0.1.1 |
Maintainer: | Stefan Fleck <stefan.b.fleck@gmail.com> |
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'. |
License: | MIT + file LICENSE |
Imports: | leaflet, magrittr, sf, utils |
Suggests: | covr, testthat |
Depends: | R (≥ 3.6.0) |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.1.1.9000 |
NeedsCompilation: | no |
Packaged: | 2020-07-01 14:36:26 UTC; fleck |
Author: | Stefan Fleck |
Repository: | CRAN |
Date/Publication: | 2020-07-02 11:30:09 UTC |
smartmap: 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'.
Author(s)
Maintainer: Stefan Fleck stefan.b.fleck@gmail.com (ORCID)
Coerce an R object to a matrix of coordinates
Description
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.
Usage
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))
Arguments
x |
any of the following:
|
... |
passed on to methods |
loncol , latcol |
|
Value
as_coord_matrix()
returns a coord_matrix
object: A numeric
matrix
with the columns "lon"
and "lat"
(in that order)
See Also
https://stackoverflow.com/questions/7309121/preferred-order-of-writing-latitude-longitude-tuples
View spatial objects as interactive leaflet maps
Description
Can be used to preview spatial R objects
Usage
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")
)
Arguments
x |
any input supported by
|
... |
passed on to methods. |
tools |
|
provider |
|
labels |
an optional |
Value
a leaflet::leaflet object
Examples
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))
Smartly convert an object to a simple features data frame
Description
Converts R objects to sf::sf objects, but supports a wider range of input data than sf::st_as_sf.
Usage
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, ...)
Arguments
x |
any of the following:
|
... |
ignored |
Value
an sf::sf data.frame
Note
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.
Examples
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
Description
Convert coordinate matrices to sf objects
Usage
## S3 method for class 'coord_matrix'
st_as_sf(x, ...)
Arguments
x |
|
... |
ignored |
Value
an sf::sf()
object with an sfc_POINT
-geometry column
See Also
Convert coordinate matrices to sfc objects
Description
Convert coordinate matrices to sfc objects
Usage
## S3 method for class 'coord_matrix'
st_as_sfc(x, ...)
Arguments
x |
|
... |
ignored |
Value
an sf::sfc()
object of subclass sfc_POINT