| Title: | Interactive Editing of Spatial Data in R |
|---|---|
| Description: | Suite of interactive functions and helpers for selecting and editing geospatial data. |
| Authors: | Tim Appelhans [aut, cre], Kenton Russell [aut], Lorenzo Busetto [aut], Josh O'Brien [ctb], Jakob Gutschlhofer [ctb], Matt Johnson [ctb], Eli Pousson [ctb] (ORCID: <https://orcid.org/0000-0001-8280-1706>) |
| Maintainer: | Tim Appelhans <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.8.0 |
| Built: | 2026-06-01 17:09:52 UTC |
| Source: | https://github.com/r-spatial/mapedit |
mapedit, a RConsortium funded project, provides interactive tools to incorporate in geospatial workflows that require editing or selection of spatial data.
#' @section Edit:
Shiny edit module selectModUI, selectMod
Maintainer: Tim Appelhans [email protected]
Authors:
Kenton Russell
Lorenzo Busetto
Other contributors:
Josh O'Brien [contributor]
Jakob Gutschlhofer [contributor]
Matt Johnson [contributor]
Eli Pousson (ORCID) [contributor]
Useful links:
Add a (possibly customized) toolbar to a leaflet map
addToolbar(leafmap, editorOptions, editor = "leafpm", targetLayerId)addToolbar(leafmap, editorOptions, editor = "leafpm", targetLayerId)
leafmap |
leaflet map to use for Selection |
editorOptions |
A list of options to be passed on to
|
editor |
Character string giving editor to be used for the
current map. Defaults to |
targetLayerId |
|
The leaflet map supplied to leafmap, now with an
added toolbar.
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.
createFeatures(SF_OBJECT = NULL)createFeatures(SF_OBJECT = NULL)
SF_OBJECT |
sf Simple feature collection |
sf object and/or saved to file
Draw (simple) features on a map
drawFeatures( map = NULL, sf = TRUE, record = FALSE, viewer = shiny::paneViewer(), title = "Draw Features", editor = "leafpm", editorOptions = list(), ... )drawFeatures( map = NULL, sf = TRUE, record = FALSE, viewer = shiny::paneViewer(), title = "Draw Features", editor = "leafpm", editorOptions = list(), ... )
map |
a background |
sf |
|
record |
|
viewer |
|
title |
|
editor |
|
editorOptions |
|
... |
additional arguments passed on to |
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
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.
editAttributes( dat, zoomto = NULL, col_add = TRUE, reset = TRUE, provider = "Esri.WorldImagery", testing = FALSE )editAttributes( dat, zoomto = NULL, col_add = TRUE, reset = TRUE, provider = "Esri.WorldImagery", testing = FALSE )
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. |
sf data.frame
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
## 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)## 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
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 = "leafpm", editorOptions = list(), ... ) ## S3 method for class 'Spatial' editFeatures(x, ...)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 = "leafpm", editorOptions = list(), ... ) ## S3 method for class 'Spatial' editFeatures(x, ...)
x |
features to edit |
... |
other arguments |
map |
a background |
mergeOrder |
|
record |
|
viewer |
|
crs |
see |
label |
|
title |
|
editor |
|
editorOptions |
|
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
## 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) ## End(Not run)## 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) ## End(Not run)
Interactively Edit a Map
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 = "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 = "leafpm", editorOptions = list(), ... ) ## S3 method for class ''NULL'' editMap(x, editor = "leafpm", editorOptions = list(), ...)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 = "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 = "leafpm", editorOptions = list(), ... ) ## S3 method for class ''NULL'' editMap(x, editor = "leafpm", editorOptions = list(), ...)
x |
|
... |
other arguments for |
targetLayerId |
|
sf |
|
ns |
|
record |
|
viewer |
|
crs |
see |
title |
|
editor |
|
editorOptions |
|
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
sf simple features or GeoJSON
## 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(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)## 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(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
editMod( input, output, session, leafmap, targetLayerId = NULL, sf = TRUE, record = FALSE, crs = 4326, editor = "leafpm", editorOptions = list() )editMod( input, output, session, leafmap, targetLayerId = NULL, sf = TRUE, record = FALSE, crs = 4326, editor = "leafpm", editorOptions = list() )
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 |
|
server function for Shiny module
Shiny Module UI for Geo Create, Edit, Delete
editModUI(id, ...)editModUI(id, ...)
id |
|
... |
other arguments to |
ui for Shiny module
Prepare arguments for addPmToolbar
processOpts(fun, args)processOpts(fun, args)
fun |
Function used by editor package (leafpm) to set defaults |
args |
Either a (possibly nested) list of named options of
the form suitable for passage to |
An object suitable for passing in as the supplied argument
to leafpm::addPmToolbar.
Interactively Select Map Features
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, ...)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, ...)
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 |
|
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
## 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) ## End(Not run)## 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) ## End(Not run)
Interactively Select Map Features
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", ... )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", ... )
x |
|
... |
other arguments |
styleFalse, styleTrue
|
names |
ns |
|
viewer |
|
title |
|
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
## 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) ## End(Not run)## 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) ## End(Not run)
Shiny Module Server for Geo Selection
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) )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) )
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 |
server function for Shiny module
Shiny Module UI for Geo Selection
selectModUI(id, ...)selectModUI(id, ...)
id |
|
... |
other arguments to |
ui for Shiny module