From c1c07bc15b6dfc1324a7b437b9f146e73cdc5263 Mon Sep 17 00:00:00 2001 From: timelyportfolio Date: Sat, 1 Jul 2017 09:03:56 -0500 Subject: [PATCH] fix bug with multiple actions resulting in FeatureCollection --- DESCRIPTION | 4 ++-- NEWS.md | 6 ++++++ R/modules.R | 35 ++++++++++++++++++----------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9a14fd0..d95dbb0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "tim.appelhans@gmail.com"), person("Kenton", "Russell", role = c("aut")) diff --git a/NEWS.md b/NEWS.md index f72fc4e..05c3318 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/modules.R b/R/modules.R index 249c527..2c51c10 100644 --- a/R/modules.R +++ b/R/modules.R @@ -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) {