Keep information from original dataset after a mapEdit?
matthewross07 opened this issue · comments
Link to html rendered version:: http://matthewrvross.com/active.html
I'm trying to snap points to a network (like roads or streams). Because many points need to be manually checked when snapping, it is easiest to just do this manually and use site metadata to determine where points should be moved to sit on the network. I'm hoping to do this all in R, but as far as I can tell the excellent package mapedit
does not allow you to edit an exisiting feature and keep the original features' data (like an ID). This makes editing with mapedit
less useful because I can see no way to join the snapped points back to their original information (other than a clunky spatial join, that would introduce as many problems as solutions).
Is this behavior expected? Am I doing something really simple that makes this not work? Any other R solutions that folks know of?
Simple example
Making up data
library(sf)
library(mapview)
library(mapedit)
library(tidyverse)
#Make up some data near a road.
#I want to snap this data to the road
untethered <- tibble(lat=c(35,35.005),
long=c(-80,-80.0001),
id=c(1,2),
road_name=c(1711,1712)) %>%
st_as_sf(.,coords=c('long','lat'),crs=4326)
untethered
Map raw data
#Snap the raw data to the road names
map <- mapview(untethered)
map
Snapping points
#Move points
manually.snapped <- editMap(map,targetLayerId='untethered')
save(manually.snapped,file='snapped.RData')
Check data
load('snapped.RData')
mapview(manually.snapped$edited)
manually.snapped$edited
Problem
How do I join the manually.snapped
data back to the untethered
data without a spatial join?
How about using manually.snapped <- editFeatures(untethered)
? This way you will retain all information from untethered
and only the geometries will be updated. Which, I guess is what you are after right? In case you want to reatin the original location, you can simply join that to manually.snapped
via some id or by cbind
ing them as the order shouldn't change.
Yup, that totally takes care of the example I posted. Unfortunately it doesn't fix my real-data problem. When I use the editFeatures
call instead of the editMap
call I lose the ability to select the features of interest. In the above example, it would be the equivalent of not getting the white boxes (which indicate a feature can be moved). This only occurs with editFeatures. I tried to reproduce the example with the same code from above but couldn't reproduce it. Things that I now know aren't part of my problem
- Adding a background raster layer
- Removing figure legends
- Adding another feature to the map
- Adding custom color ramps
That leaves me to wonder if the problem only occurs when I am mapping a very large raster covering most of West Virginia. Is there reason to suspect editFeatures would be impacted by a large dataset? I'll keep trying to reproduce my issue, but figured I could first ask about the data size idea. Thanks again.
Are you passing a map object to editFeatures
?
Yes. So using the above as an example, it would look like this
manually.snapped <- editFeatures(untethered,map=map)
This works with this data, but for some reason it doesn't work with my much larger dataset. I'll have a reproducible example to post as soon as I have one working!
I guess it doesn't work because mapview is trying to be smart and uses canvas rendering for larger datasets. Does it work if you set up your map with mapview(unterthered, canvas = FALSE)
? How many points are you plotting on your map?
Yea, that did the trick. Thanks again and I'll close this comment.