Skip to content

Commit

Permalink
Merge pull request #49 from timelyportfolio/master
Browse files Browse the repository at this point in the history
fix bug with multiple actions resulting in FeatureCollection
  • Loading branch information
tim-salabim authored Jul 1, 2017
2 parents 00ff8ab + c1c07bc commit f06d599
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: mapedit
Title: Interactive Editing of Spatial Data in R
Description: Suite of interactive functions and helpers for selecting and editing
geospatial data.
Version: 0.3.0
Date: 2017-06-26
Version: 0.3.1
Date: 2017-07-01
Authors@R: c(
person("Tim", "Appelhans", role = c("aut", "cre"), email = "[email protected]"),
person("Kenton", "Russell", role = c("aut"))
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# mapedit 0.3.1

### Bug Fix

* multiple edits and deletes resulting in multiple FeatureCollections not handled properly causing some actions to not be considered when converting to `sf`; thanks @tim-salabim for identifying

# mapedit 0.3.0

### API Changes
Expand Down
35 changes: 18 additions & 17 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,32 @@ editMod <- function(
if(sf) {
workinglist <- lapply(
workinglist,
function(gj) {
function(action) {
# ignore empty action types to prevent error
# handle in the helper functions?
if(length(gj) == 0) { return() }
if(length(action) == 0) { return() }

# deleted is often a FeatureCollection
# which requires special treatment
if(gj[[1]]$type == "FeatureCollection") {
return(
combine_list_of_sf(
lapply(
gj[[1]]$features,
function(feature) {
st_as_sf.geo_list(feature)
}
)
)
)
}
# FeatureCollection requires special treatment
# and we need to extract features
features <- Reduce(
function(left,right) {
if(right$type == "FeatureCollection") {
right <- lapply(right$features, identity)
} else {
right <- list(right)
}
c(left,right)
},
action,
init = NULL
)

combine_list_of_sf(
lapply(gj, st_as_sf.geo_list)
lapply(features, st_as_sf.geo_list)
)
}
)

recorder <- lapply(
recorder,
function(evt) {
Expand Down

0 comments on commit f06d599

Please sign in to comment.