Skip to content

support MULTILINESTRING #62

@timelyportfolio

Description

@timelyportfolio

promoted from #48

Before I implement the logic into mapedit, I wanted to post the results from my initial exploration.

library(mapview)
library(mapedit)
library(sf)

# @tim-salabim reports, this fails badly
#   and while leaflet draws the multilinestring correctly
#   Leaflet.draw seems to not like it
editFeature(trails[4,])

# we will need to cast to LINESTRING first
#  but be careful to retain some mechanism
#  to preserve the group for proper conversion back
#  to MULTILINESTRING
editFeatures(sf::st_cast(trails[4,], "LINESTRING"))


# one option will be to add a second column identifier
#  after we cast to LINESTRING
#  here is a minimal example before attempting to integrate
#  into the existing module
tr <- trails[c(1,4),]
tr$edit_id <- seq_len(nrow(tr))
# now will need to carefully cast
#  for some reason casting creates sfc
#  so also need to st_sf to get back to sf
tr2 <- st_sf(st_cast(tr, "LINESTRING"))
tr2


# ignore the editMap part for now
#  and see if we can convert back
#  I might be making this way harder than it should be
#  but I could not find a combination of aggregate.sf
#  or dplyr::group_by that would accomplish this
tr3 <- tr
st_geometry(tr3) <- split(tr2, tr2$edit_id) %>%
  lapply(function(x){st_multilinestring(st_geometry(x))}) %>%
  st_sfc
plot(tr3)
tr3

@edzer, is there a way to group_by and then make st_multilinestring on each grouped edit_id? I also tried to do this with aggregate.sf with no luck since it seems the aggregate function could only apply to non-geometry columns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions