Skip to content

Commit

Permalink
fix so intermediate steps do not change original type and also add wa…
Browse files Browse the repository at this point in the history
…rning
  • Loading branch information
timelyportfolio committed Jan 6, 2019
1 parent 279831c commit 6106b90
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ merge_edit <- function(
mapply(
function(ed, ed_id) {
matched_id_row = which(orig_ids == ed_id)
# sf::st_geometry(orig2)[matched_id_row] <<- ed

# get type of original
orig_type <- as.character(sf::st_geometry_type(
sf::st_geometry(orig[matched_id_row,])
))

tryCatch(
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,])
))
orig_type
)),
error = function(e) {
sf::st_geometry(orig2)[matched_id_row] <<- ed
warning(
paste0("Unable to cast back to original type - ", e$message, " - but this is often caused by intermediate step."),
call. = FALSE
)
}
)
return(NULL)
Expand Down

0 comments on commit 6106b90

Please sign in to comment.