-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add editFeatures function similar to selectFeatures #29
Comments
… use in future editFeatures function; see r-spatial#29
Surely I kind of like the idea of appending a new geometry column... This way changes can be tracked easily (even intersecting old and new geometry is possible). I'd love to hear some thoughts by @edzer regarding this. If the mechanism of switching |
Yeah, that's a nice use case for multiple geometry columns that I hadn't thought of. The constraint here is that a geometry column has the same number of geometries as there are features (rows in the table), and so if you'd delete a point you shouldn't remove it from the list but replace it with an empty geometry, e.g. > st_geometrycollection()
GEOMETRYCOLLECTION() or one of a more appropriate type such as > st_multipolygon()
MULTIPOLYGON() so that after editing the list still has the same length as it originally had. Not a bad idea, since we don't require list element IDs (list names) to identify features. |
Ok, so this should work not only work for editing (as I had originally thought) but also for deleting. Adding features would simply mean filling attribute columns with NAs I guess... |
Yes, unless you add e.g. a point to an existing multipoint, a polygon to an existing multipolygon, or anything to an existing geometrycollection. |
I love the idea that we could reproduce using the approach, but I foresee problems if there is a sequence such as add and then edit/delete additions. I think it is still do-able, but will require a different approach than what I had envisioned for For best reproducibility, we could record the actions/events with timestamp or sequential id, and then be able to play that back, but I think this would be a different set of functions targeting this concept. This approach would closely mirror something like Redux time traveller. Or, we could try to write some functions to diff the output from I'd love to hear your feedback. |
I guess no matter what both would be very helpful. I think the I am closer to a potential solution for merge all in one column, so given time constraint, I advocate for getting that in place before initial CRAN release and useR. Then, I will implement the record/playback method later. |
|
I did a proof of concept in |
I can't seem to get the recording feature working? |
@tim-salabim I forgot to note that I changed the recorder to be an
|
@timelyportfolio yes it does work! Nice, I really like the recorder feature and the fact that it distinguishes between actions ("add", "edit", "delete"). |
Great, glad it works. Been trying to think of interesting or fun example all week. Also, thought flubber would be fun way to animate edits. |
Yeah, maybe we could have a fun function to |
It would be a nice feature to be able to remove holes from polygons. |
OK, so it seems to work to delete individual vertices (by clicking on them - though rather buggy). But then I get the following error: Error: nrow(x) == length(value) is not TRUE
In addition: Warning message:
drop ignored This was the setup # devtools::install_github("nowosad/spData")
library(spData)
library(sf)
library(dplyr)
# library(tidyverse)
library(mapview)
library(mapedit)
library(leaflet.extras)
world_continents2 = world %>%
st_set_precision(10000) %>%
group_by(continent) %>%
summarise(pop = sum(pop, na.rm = TRUE), country_n = n())
plot(world_continents2[1])
editFeatures(world_continents2) and I deleted a few vertices of the holes in Africa (you can verify that these are holes by zooming in quite far using mapview). I think in many cases it would be desirable to be able to select vertices to be deleted by drawing a polygon (or rectangle) similar to this |
@timelyportfolio can we have |
I will add a |
Awesome! |
@tim-salabim, @edzer is the |
@timelyportfolio regarding editing of complete features, I think it is working well so far. Yet, when deleting individual vertices from polygons (haven't tried for lines) I get the above reported error. Any ideas? |
… use in future editFeatures function; see r-spatial#29
I will debug the vertices issue today. |
@tim-salabim, do you have a screenshot/screencast? Can you replicate with this smaller example from here?
I cannot seem to delete all the vertices from the hole in either case. |
No I can't. I think in my example above the hole got so small that it seemed to have disappeared. With your example I can only remove all vertices > 3 at which it stops deleting. Also, I noticed that hole vertices become un-editable when you move the enclosing polygon. Also, deleting hole vertices is a final deletion, i.e. it doesn't seem to respect pressing cancel to undo stuff. In any case, I think this is all not our problem at this point as this all stems from the |
Ok, I noticed the same issues. I will plan to submit a pull request to |
Yip. That is fine. |
#33 closes |
selectFeatures()
by @tim-salabim is brilliant and helpful.editFeatures
done properly could also be very nice, but will require a little more care to apply the edits, add, and deletes. I will try to describe my initial thoughts from quite a bit of experimentation.immutability
editFeatures()
should return a newsf
with merged changes rather than attempting to mutate the original/sourcesf
.change original
sf
geometryeditFeatures()
could add new a new non-primary geometry column for edits like a join might, add new property column to mark deletes, and add geometries by adding to the new edit column if done as stated in first item of the list with property column marker like deletes. However, I think it should simply merge the changes into the primary geometry column.merge edits
Changing the geometry column of an
sf
is not well-documented, and I tried a whole lot of different ways. @tim-salabim though showed me the nifty little trick of assignment (timelyportfolio/r-spatial.org@bf13e81#commitcomment-22430626) withst_geometry
that seems to work as expected. I would like to test this thoroughly, and if it works as it seems then add some examples and better documentation tosf::st_geometry()
.The text was updated successfully, but these errors were encountered: