Title: | Interactive Editing of Spatial Data in R |
Description: | Suite of interactive functions and helpers for selecting and editing geospatial data. |
Version: | 0.7.0 |
URL: | https://github.com/r-spatial/mapedit |
BugReports: | https://github.com/r-spatial/mapedit/issues |
License: | MIT + file LICENSE |
Depends: | R (≥ 3.1.0) |
Imports: | assertthat, dplyr, DT, htmltools (≥ 0.3), htmlwidgets, jsonlite, leafem, leaflet (≥ 2.0.1), leaflet.extras (≥ 1.0), leafpm, leafpop, mapview, methods, miniUI, raster, rstudioapi, scales, sf (≥ 0.5-2), shiny, tmaptools, shinyWidgets (≥ 0.4.3) |
Suggests: | crayon, sp |
Enhances: | geojsonio |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-04-20 07:25:58 UTC; tim |
Author: | Tim Appelhans [aut, cre],
Kenton Russell [aut],
Lorenzo Busetto [aut],
Josh O'Brien [ctb],
Jakob Gutschlhofer [ctb],
Matt Johnson [ctb],
Eli Pousson |
Maintainer: | Tim Appelhans <tim.appelhans@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-04-20 08:20:01 UTC |
mapedit: interactive editing and selection for geospatial data
Description
mapedit, a RConsortium funded project, provides interactive tools to incorporate in geospatial workflows that require editing or selection of spatial data.
Edit
#' @section Edit:
Shiny edit module
selectModUI
,selectMod
Author(s)
Maintainer: Tim Appelhans tim.appelhans@gmail.com
Authors:
Kenton Russell
Lorenzo Busetto
Other contributors:
Josh O'Brien [contributor]
Jakob Gutschlhofer [contributor]
Matt Johnson [contributor]
Eli Pousson (ORCID) [contributor]
See Also
Useful links:
Add a (possibly customized) toolbar to a leaflet map
Description
Add a (possibly customized) toolbar to a leaflet map
Usage
addToolbar(leafmap, editorOptions, editor, targetLayerId)
Arguments
leafmap |
leaflet map to use for Selection |
editorOptions |
A list of options to be passed on to either
|
editor |
Character string giving editor to be used for the
current map. Either |
targetLayerId |
|
Value
The leaflet map supplied to leafmap
, now with an
added toolbar.
mapedit create features Addin
Description
Create and save spatial objects within the Rstudio IDE. Objects
can then be saved to file types such as .geojson
or .shp
.
Objects are also output to the console and can be assigned to a variable
using .Last.value
. If you wish to pass the output directly to a variable
simply call the addin function, ie. new_sf <- createFeatures()
.
An existing sf data.frame
can also be passed either indirectly by
selecting text in RStudio with the name of the object, or directly by
passing the existing sf object to new_sf <- createFeatures(existing_sf)
.
When passing an existing sf object you can only add and edit additional features,
the existing features cannot be changed.
Usage
createFeatures(SF_OBJECT = NULL)
Arguments
SF_OBJECT |
sf Simple feature collection |
Value
sf object and/or saved to file
Draw (simple) features on a map
Description
Draw (simple) features on a map
Usage
drawFeatures(
map = NULL,
sf = TRUE,
record = FALSE,
viewer = shiny::paneViewer(),
title = "Draw Features",
editor = c("leaflet.extras", "leafpm"),
editorOptions = list(),
...
)
Arguments
map |
a background |
sf |
|
record |
|
viewer |
|
title |
|
editor |
|
editorOptions |
|
... |
additional arguments passed on to |
Details
When setting viewer = browserViewer(browser = getOption("browser"))
and
the systems default browser is Firefox, the browser window will likely not
automatically close when the app is closed (by pressing "done" or "cancel").
To enable automatic closing of tabs/windows in Firefox try the following:
input "about:config " to your firefox address bar and hit enter
make sure your "dom.allow_scripts_to_close_windows" is true
Edit Feature Attributes
Description
Launches a shiny
application where you can add and edit spatial geometry
and attributes. Geometry is created or edited within the interactive map, while feature attributes
can be added to and edited within the editable table.
Starting with a data.frame
or an sf data.frame
, a list of sf data.frames
or nothing
at all. You can add columns, and rows and geometry for each row. Clicking on a row with geometry you can
zoom across the map between features.
When you are done, your edits are saved to an sf data.frame
for
use in R or to be saved to anyformat you wish via st_write.
The application can dynamically handle: character, numeric, integer, factor and date fields.
When the input data set is an sf data.frame
the map automatically zooms to the extent of the sf
object.
When the input has no spatial data, you must tell the function where to zoom. The function uses geocode_OSM to identify the coordinates of your area of interest.
Usage
editAttributes(
dat,
zoomto = NULL,
col_add = TRUE,
reset = TRUE,
provider = "Esri.WorldImagery",
testing = FALSE
)
Arguments
dat |
input data source, can be a |
zoomto |
character area of interest. The area is defined using geocode_OSM, which uses OSM Nominatim. The area can be as ambiguous as a country, or as specific as a street address. You can test the area of interest using the application or the example code below. |
col_add |
boolean option to enable add columns form. Set to false if you don't want to allow a user to modify the data structure. |
reset |
boolean option to reset attribute input. Set to false if you don't want the attribute input to reset to NA after each added row. Use this option when features share common attributes |
provider |
A character string indicating the provider tile of choice, e.g. 'Esri.WorldImagery' (default) |
testing |
Only relevant for internal testing using shinytest. |
Value
sf data.frame
Note
Editing of feature geometries does not work for multi-geometry inputs. For this use case it is advisable to split the data set by geometry type and edit separately
Examples
## Not run:
# with no input
data_sf <- editAttributes(zoomto = 'germany')
# a data.frame input
dat <- data.frame(name = c('SiteA', 'SiteB'),
type = factor(
c('park', 'zoo')
, levels = c('park', 'factory', 'zoo', 'warehouse')
),
size = c(35, 45))
data_sf <- editAttributes(dat, zoomto = 'berlin')
# an sf data.frame input
data_sf <- editAttributes(data_sf)
# test zoomto area of interest
zoomto_area <- tmaptools::geocode_OSM('paris')
mapview(st_as_sfc(zoomto_area$bbox))
## End(Not run)
Interactively Edit Map Features
Description
Interactively Edit Map Features
Usage
editFeatures(x, ...)
## S3 method for class 'sf'
editFeatures(
x,
map = NULL,
mergeOrder = c("add", "edit", "delete"),
record = FALSE,
viewer = shiny::paneViewer(),
crs = 4326,
label = NULL,
title = "Edit Map",
editor = c("leaflet.extras", "leafpm"),
editorOptions = list(),
...
)
## S3 method for class 'Spatial'
editFeatures(x, ...)
Arguments
x |
features to edit |
... |
other arguments |
map |
a background |
mergeOrder |
|
record |
|
viewer |
|
crs |
see |
label |
|
title |
|
editor |
|
editorOptions |
|
Details
When setting viewer = browserViewer(browser = getOption("browser"))
and
the systems default browser is Firefox, the browser window will likely not
automatically close when the app is closed (by pressing "done" or "cancel").
To enable automatic closing of tabs/windows in Firefox try the following:
input "about:config " to your firefox address bar and hit enter
make sure your "dom.allow_scripts_to_close_windows" is true
Examples
## Not run:
library(mapedit)
library(mapview)
lf <- mapview()
# draw some polygons that we will select later
drawing <- lf %>%
editMap()
# little easier now with sf
mapview(drawing$finished)
# especially easy with selectFeatures
selectFeatures(drawing$finished)
# use @bhaskarvk USA Albers with leaflet code
# https://bhaskarvk.github.io/leaflet/examples/proj4Leaflet.html
#devtools::install_github("hrbrmstr/albersusa")
library(albersusa)
library(sf)
library(leaflet)
library(mapedit)
spdf <- usa_sf()
pal <- colorNumeric(
palette = "Blues",
domain = spdf$pop_2014
)
bounds <- c(-125, 24 ,-75, 45)
(lf <- leaflet(
options=
leafletOptions(
worldCopyJump = FALSE,
crs=leafletCRS(
crsClass="L.Proj.CRS",
code='EPSG:2163',
proj4def=paste0(
'+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 ',
'+b=6370997 +units=m +no_defs'
),
resolutions = c(65536, 32768, 16384, 8192, 4096, 2048,1024, 512, 256, 128)
)
)
) %>%
fitBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
setMaxBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
mapview::addFeatures(
data=spdf, weight = 1, color = "#000000",
# adding group necessary for identification
layerId = ~iso_3166_2,
fillColor=~pal(pop_2014),
fillOpacity=0.7,
label=~stringr::str_c(name,' ', format(pop_2014, big.mark=",")),
labelOptions= labelOptions(direction = 'auto')
)
)
# test out selectMap with albers example
selectMap(
lf,
styleFalse = list(weight = 1),
styleTrue = list(weight = 4)
)
## End(Not run)
Interactively Edit a Map
Description
Interactively Edit a Map
Usage
editMap(x, ...)
## S3 method for class 'leaflet'
editMap(
x = NULL,
targetLayerId = NULL,
sf = TRUE,
ns = "mapedit-edit",
record = FALSE,
viewer = shiny::paneViewer(),
crs = 4326,
title = "Edit Map",
editor = c("leaflet.extras", "leafpm"),
editorOptions = list(),
...
)
## S3 method for class 'mapview'
editMap(
x = NULL,
targetLayerId = NULL,
sf = TRUE,
ns = "mapedit-edit",
record = FALSE,
viewer = shiny::paneViewer(),
crs = 4326,
title = "Edit Map",
editor = c("leaflet.extras", "leafpm"),
editorOptions = list(),
...
)
## S3 method for class ''NULL''
editMap(x, editor = c("leaflet.extras", "leafpm"), editorOptions = list(), ...)
Arguments
x |
|
... |
other arguments for |
targetLayerId |
|
sf |
|
ns |
|
record |
|
viewer |
|
crs |
see |
title |
|
editor |
|
editorOptions |
|
Details
When setting viewer = browserViewer(browser = getOption("browser"))
and
the systems default browser is Firefox, the browser window will likely not
automatically close when the app is closed (by pressing "done" or "cancel").
To enable automatic closing of tabs/windows in Firefox try the following:
input "about:config " to your firefox address bar and hit enter
make sure your "dom.allow_scripts_to_close_windows" is true
Value
sf
simple features or GeoJSON
Examples
## Not run:
library(leaflet)
library(mapedit)
editMap(leaflet() %>% addTiles())
## End(Not run)
## Not run:
# demonstrate Leaflet.Draw on a layer
library(sf)
library(mapview)
library(leaflet.extras)
library(mapedit)
# ?sf::sf
pol = st_sfc(
st_polygon(list(cbind(c(0,3,3,0,0),c(0,0,3,3,0)))),
crs = 4326
)
mapview(pol) %>%
editMap(targetLayerId = "pol")
mapview(franconia[1:2,]) %>%
editMap(targetLayerId = "franconia[1:2, ]")
## End(Not run)
Shiny Module Server for Geo Create, Edit, Delete
Description
Shiny Module Server for Geo Create, Edit, Delete
Usage
editMod(
input,
output,
session,
leafmap,
targetLayerId = NULL,
sf = TRUE,
record = FALSE,
crs = 4326,
editor = c("leaflet.extras", "leafpm"),
editorOptions = list()
)
Arguments
input |
Shiny server function input |
output |
Shiny server function output |
session |
Shiny server function session |
leafmap |
leaflet map to use for Selection |
targetLayerId |
|
sf |
|
record |
|
crs |
see |
editor |
|
editorOptions |
|
Value
server function for Shiny module
Shiny Module UI for Geo Create, Edit, Delete
Description
Shiny Module UI for Geo Create, Edit, Delete
Usage
editModUI(id, ...)
Arguments
id |
|
... |
other arguments to |
Value
ui for Shiny module
Merge 'sf' Adds
Description
Internal function used with editFeatures
to apply adds or drawn
to a sf
object.
Usage
merge_add(orig = NULL, drawn = NULL, by = NULL)
Arguments
orig |
|
drawn |
|
by |
not used in merge_add. This argument only exists for symmetry with the other merge functions. |
Merge 'sf' Deletes
Description
Internal function used with editFeatures
to apply deletes
to a sf
object.
Usage
merge_delete(orig = NULL, deletes = NULL, by = c(id = "layerId"))
Arguments
orig |
|
deletes |
|
by |
named |
Merge 'sf' Edits
Description
Internal function used with editFeatures
to apply edits
to a sf
object.
Usage
merge_edit(orig = NULL, edits = NULL, by = c(id = "layerId"))
Arguments
orig |
|
edits |
|
by |
named |
Playback a Recorded 'mapedit' Session on Leaflet Map
Description
Playback a Recorded 'mapedit' Session on Leaflet Map
Usage
playback(x, origsf = NULL)
Arguments
x |
a recorded mapedit session from |
Prepare arguments for addDrawToolbar or addPmToolbar
Description
Prepare arguments for addDrawToolbar or addPmToolbar
Usage
processOpts(fun, args)
Arguments
fun |
Function used by editor package (leafpm or leaflet.extras) to set defaults |
args |
Either a (possibly nested) list of named options of
the form suitable for passage to |
Value
An object suitable for passing in as the supplied argument
to either leaflet.extras::addDrawToolbar
or
leafpm::addPmToolbar
.
Interactively Select Map Features
Description
Interactively Select Map Features
Usage
selectFeatures(x, ...)
## S3 method for class 'sf'
selectFeatures(
x = NULL,
mode = c("click", "draw"),
op = sf::st_intersects,
map = NULL,
index = FALSE,
viewer = shiny::paneViewer(),
label = NULL,
title = "Select features",
...
)
## S3 method for class 'Spatial'
selectFeatures(x, ...)
Arguments
x |
features to select |
... |
other arguments |
mode |
one of "click" or "draw". |
op |
the geometric binary predicate to use for the selection.
Can be any of |
map |
a background |
index |
|
viewer |
|
label |
|
title |
|
Details
When setting viewer = browserViewer(browser = getOption("browser"))
and
the systems default browser is Firefox, the browser window will likely not
automatically close when the app is closed (by pressing "done" or "cancel").
To enable automatic closing of tabs/windows in Firefox try the following:
input "about:config " to your firefox address bar and hit enter
make sure your "dom.allow_scripts_to_close_windows" is true
Examples
## Not run:
library(mapedit)
library(mapview)
lf <- mapview()
# draw some polygons that we will select later
drawing <- lf %>%
editMap()
# little easier now with sf
mapview(drawing$finished)
# especially easy with selectFeatures
selectFeatures(drawing$finished)
# use @bhaskarvk USA Albers with leaflet code
# https://bhaskarvk.github.io/leaflet/examples/proj4Leaflet.html
#devtools::install_github("hrbrmstr/albersusa")
library(albersusa)
library(sf)
library(leaflet)
library(mapedit)
spdf <- usa_sf()
pal <- colorNumeric(
palette = "Blues",
domain = spdf$pop_2014
)
bounds <- c(-125, 24 ,-75, 45)
(lf <- leaflet(
options=
leafletOptions(
worldCopyJump = FALSE,
crs=leafletCRS(
crsClass="L.Proj.CRS",
code='EPSG:2163',
proj4def=paste0(
'+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 ',
'+b=6370997 +units=m +no_defs'
),
resolutions = c(65536, 32768, 16384, 8192, 4096, 2048,1024, 512, 256, 128)
)
)
) %>%
fitBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
setMaxBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
mapview::addFeatures(
data=spdf, weight = 1, color = "#000000",
# adding group necessary for identification
layerId = ~iso_3166_2,
fillColor=~pal(pop_2014),
fillOpacity=0.7,
label=~stringr::str_c(name,' ', format(pop_2014, big.mark=",")),
labelOptions= labelOptions(direction = 'auto')
)
)
# test out selectMap with albers example
selectMap(
lf,
styleFalse = list(weight = 1),
styleTrue = list(weight = 4)
)
## End(Not run)
Interactively Select Map Features
Description
Interactively Select Map Features
Usage
selectMap(x, ...)
## S3 method for class 'leaflet'
selectMap(
x = NULL,
styleFalse = list(fillOpacity = 0.2, weight = 1, opacity = 0.4),
styleTrue = list(fillOpacity = 0.7, weight = 3, opacity = 0.7),
ns = "mapedit-select",
viewer = shiny::paneViewer(),
title = "Select features",
...
)
Arguments
x |
|
... |
other arguments |
styleFalse , styleTrue |
names |
ns |
|
viewer |
|
title |
|
Details
When setting viewer = browserViewer(browser = getOption("browser"))
and
the systems default browser is Firefox, the browser window will likely not
automatically close when the app is closed (by pressing "done" or "cancel").
To enable automatic closing of tabs/windows in Firefox try the following:
input "about:config " to your firefox address bar and hit enter
make sure your "dom.allow_scripts_to_close_windows" is true
Examples
## Not run:
library(mapedit)
library(mapview)
lf <- mapview()
# draw some polygons that we will select later
drawing <- lf %>%
editMap()
# little easier now with sf
mapview(drawing$finished)
# especially easy with selectFeatures
selectFeatures(drawing$finished)
# use @bhaskarvk USA Albers with leaflet code
# https://bhaskarvk.github.io/leaflet/examples/proj4Leaflet.html
#devtools::install_github("hrbrmstr/albersusa")
library(albersusa)
library(sf)
library(leaflet)
library(mapedit)
spdf <- usa_sf()
pal <- colorNumeric(
palette = "Blues",
domain = spdf$pop_2014
)
bounds <- c(-125, 24 ,-75, 45)
(lf <- leaflet(
options=
leafletOptions(
worldCopyJump = FALSE,
crs=leafletCRS(
crsClass="L.Proj.CRS",
code='EPSG:2163',
proj4def=paste0(
'+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 ',
'+b=6370997 +units=m +no_defs'
),
resolutions = c(65536, 32768, 16384, 8192, 4096, 2048,1024, 512, 256, 128)
)
)
) %>%
fitBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
setMaxBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
mapview::addFeatures(
data=spdf, weight = 1, color = "#000000",
# adding group necessary for identification
layerId = ~iso_3166_2,
fillColor=~pal(pop_2014),
fillOpacity=0.7,
label=~stringr::str_c(name,' ', format(pop_2014, big.mark=",")),
labelOptions= labelOptions(direction = 'auto')
)
)
# test out selectMap with albers example
selectMap(
lf,
styleFalse = list(weight = 1),
styleTrue = list(weight = 4)
)
## End(Not run)
Shiny Module Server for Geo Selection
Description
Shiny Module Server for Geo Selection
Usage
selectMod(
input,
output,
session,
leafmap,
styleFalse = list(fillOpacity = 0.2, weight = 1, opacity = 0.4),
styleTrue = list(fillOpacity = 0.7, weight = 3, opacity = 0.7)
)
Arguments
input |
Shiny server function input |
output |
Shiny server function output |
session |
Shiny server function session |
leafmap |
leaflet map to use for Selection |
styleFalse |
named |
styleTrue |
named |
Value
server function for Shiny module
Shiny Module UI for Geo Selection
Description
Shiny Module UI for Geo Selection
Usage
selectModUI(id, ...)
Arguments
id |
|
... |
other arguments to |
Value
ui for Shiny module