Skip to content

Commit

Permalink
Merge pull request #52 from timelyportfolio/master
Browse files Browse the repository at this point in the history
0.3.2 suite of bug fixes and improvements
  • Loading branch information
timelyportfolio authored Jul 13, 2017
2 parents f652bd1 + a0db6f9 commit d54cbf2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 27 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.1
Date: 2017-07-01
Version: 0.3.2
Date: 2017-07-12
Authors@R: c(
person("Tim", "Appelhans", role = c("aut", "cre"), email = "[email protected]"),
person("Kenton", "Russell", role = c("aut"))
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# mapedit 0.3.2

### Bug Fix

* polygons of `length > 1` not handled correctly. See [discussion](https://github.com/r-spatial/mapedit/issues/48).

* remove internally added `edit_id` column in editFeatures return

* cast edits back to their original type. See [discussion](https://github.com/r-spatial/mapedit/issues/48)

* fix merge_edit to only consider last edit when there are multiple edits per layerId

# mapedit 0.3.1

### Bug Fix
Expand Down
5 changes: 4 additions & 1 deletion R/edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,15 @@ editFeatures.sf = function(
init = x
)

merged <- dplyr::select_(merged, "-edit_id")

# return merged features
if(record==TRUE) {
attr(merged, "recorder") <- attr(crud, "recorder", exact=TRUE)
attr(merged, "original") <- x
}
return(merged)

merged
}

#' @name editFeatures
Expand Down
31 changes: 9 additions & 22 deletions R/edit_map_return_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,7 @@ st_as_sf.geo_list = function(x, ...) {
stop("should be of type 'Feature'", call.=FALSE)
}

x <- fix_geojson_coords(x)

#props <- do.call(
# data.frame,
# modifyList(
# Filter(Negate(is.null), x$properties),
# list(stringsAsFactors=FALSE)
# )
#)

geom_sf <- st_as_sfc.geo_list(x)
# if props are empty then we need to handle differently
#if(nrow(props) == 0 ) {
# return(sf::st_sf(feature=geom_sf, crs = sf::st_crs(4326)))
#} else {
# return(sf::st_sf(props, feature=geom_sf, crs = sf::st_crs(4326)))
#}
}

#' @keywords internal
Expand All @@ -59,12 +43,15 @@ fix_geojson_coords <- function(ft) {
}

if(!(ft$geometry$type %in% c("Point", "LineString"))) {
ft$geometry$coordinates <- list(
matrix(
unlist(ft$geometry$coordinates),
ncol = 2,
byrow = TRUE
)
ft$geometry$coordinates <- lapply(
ft$geometry$coordinates,
function(coords) {
matrix(
unlist(ft$geometry$coordinates),
ncol = 2,
byrow = TRUE
)
}
)
}

Expand Down
34 changes: 32 additions & 2 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,41 @@ merge_edit <- function(
orig2 <- orig

orig_ids = orig2[[names(by)[1]]]

edit_ids = edits[,by[[1]], drop=TRUE]

matched_id_rows = which(orig_ids %in% edit_ids)
mapply(
function(ed, ed_id) {
matched_id_row = which(orig_ids == ed_id)
sf::st_geometry(orig2)[matched_id_row] <<- sf::st_geometry(sf::st_cast(
sf::st_sfc(ed),
as.character(sf::st_geometry_type(
sf::st_geometry(orig2[matched_id_row,])
))
))
return(NULL)
},
sf::st_geometry(edits),
edit_ids
)

sf::st_geometry(orig2)[matched_id_rows] <- sf::st_geometry(edits)
#matched_id_rows = which(orig_ids %in% edit_ids)

# cast edits to original type
#sf::st_geometry(edits) <- sf::st_sfc(mapply(
# function(ed, type) {
# sf::st_cast(ed, type)
# },
# sf::st_geometry(edits),
# as.character(
# sf::st_geometry_type(
# sf::st_geometry(orig2)
# )[matched_id_rows]
# ),
# SIMPLIFY = FALSE
#))

#sf::st_geometry(orig2)[matched_id_rows] <- sf::st_geometry(edits)
orig2
}

Expand Down

0 comments on commit d54cbf2

Please sign in to comment.