Skip to content

Commit

Permalink
add selectFeatures to select features from sf
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-salabim committed May 15, 2017
1 parent 158e614 commit 4dfd8d9
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Suggests:
mapview
Encoding: UTF-8
LazyData: true
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

S3method(edit_map,leaflet)
S3method(selectFeatures,sf)
S3method(select_map,leaflet)
export(edit_map)
export(selectFeatures)
export(select_map)
32 changes: 32 additions & 0 deletions R/select.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Interactively Select Map Features
#'
#' @param x map to use
#'
#' @param ... other arguments
#'
#' @example ./inst/examples/examples_select.R
#' @export
selectFeatures <- function(x, ...) {
UseMethod("selectFeatures")
}

#' @export
selectFeatures.sf <- function(x, ...) {
x$edit_group = as.character(1:nrow(x))

addfun = switch(as.character(sf::st_dimension(sf::st_geometry(x)))[1],
"0" = leaflet::addCircleMarkers,
"1" = leaflet::addPolylines,
"2" = leaflet::addPolygons)

m = leaflet::leaflet() %>%
leaflet::addTiles() %>%
addfun(data = x, weight = 1, group = ~edit_group)

ind = select_map(m, ...)

indx = ind$group[as.logical(ind$selected)]
todrop = "edit_group"
return(x[as.numeric(indx), !names(x) %in% todrop])
}

1 change: 0 additions & 1 deletion man/edit_map.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions man/selectFeatures.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/select_map.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4dfd8d9

Please sign in to comment.