Skip to content
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

CRS of edited feature in editMap() #64

Closed
pat-s opened this issue Sep 11, 2017 · 9 comments
Closed

CRS of edited feature in editMap() #64

pat-s opened this issue Sep 11, 2017 · 9 comments

Comments

@pat-s
Copy link
Member

pat-s commented Sep 11, 2017

Hi guys,

see the following mapview object: https://www.dropbox.com/s/l0owf7cul38o7x7/test-map.rda?dl=0

When saving edits of a layer and checking the result, the CRS is always 4326 (as far as I saw thats the intended behaviour):

editMap(map1, targetLayerId = "laukiz1", record = TRUE) -> map2
mapview(map2$finished)

Simple feature collection with 1 feature and 2 fields
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 505685.5 ymin: 4799974 xmax: 505768.5 ymax: 4800021
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
  X_leaflet_id feature_type                       geometry
1          670      polygon POLYGON ((505685.5 4799999,...

The problem in my case is that the bbox is stored in UTM coordinates (because map1 is in UTM) and the proj4 string is in lat/long. This screws up the spatial object.

I figured out that I need to call st_set_crs with the matching crs of map1 to get a valid sf object again.

map2$finished %>% 
  st_set_crs(32630) -> new_object

st_transform, which should be normaly used here, does not work because of the UTM<->long/lat problem just mentioned. st_set_crs gives the usual warning message which can be ignored here. This post-processing is really confusing and might cause a lot of problems for unexperienced users.

Is there a way to specify the output CRS of a resulting editMap() object within the function call?
Wouldn't it be best to use the CRS of the layer that has been edited?

Thanks for your time and keep rocking 👍

@tim-salabim
Copy link
Member

When I try to load your map I get "Error: path[1]="/home/patrick/R/x86_64-pc-linux-gnu-library/3.4/mapview/htmlwidgets/lib/HomeButton": No such file or directory"

Maybe better to provide a reprex than a file

@pat-s
Copy link
Member Author

pat-s commented Sep 12, 2017

Hi Tim,

thats strange, I tested it now on two computers and it works fine.
Did you do a map1 <- readRDS("test-map.rda")? If it still does not work I am happy to provide a reprex instead. Thought it would be easier this way

@tim-salabim
Copy link
Member

I used readr::read_rds

@tim-salabim
Copy link
Member

I managed work on your map object by creating a new mapview map using the @object slot of the original you provided (finally a use for that slot :-) ).
I have no problems editing and retrieving the polygon layer using the original crs (editMap has a crs argument):

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

map1 = readRDS("/home/ede/software/testing/mapedit/crs/test-map.rda")
map2 = mapview(map1@object, layer.name = list("pt1", "pt2", "pol"), native.crs = TRUE)
epsg = st_crs(map1@object[[1]])

editMap(map2, targetLayerId = "pol", record = TRUE, crs = epsg) -> map3

mapview(map3$edited, native.crs = TRUE)

If this does not work for you, can you please explain in more detail what it is you are trying to achieve?

@pat-s
Copy link
Member Author

pat-s commented Sep 12, 2017

Hi Tim,

thanks for the quick response!
I want to continue working with the edited feature (here the modified polygon) and use it as a sf object with epsg: 32630 in further functions. I am confused why the epsg code changes after having called editMap().

Is it important to put map1 again in a new object map2 before calling editMap()?

Here is a reprex:

map1 = readRDS("path/test-map.rda")
map2 = editMap(map1, targetLayerId = "laukiz1", record = TRUE, crs = 32630)

print(map2$finished)

Simple feature collection with 1 feature and 2 fields
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 505690.8 ymin: 4799979 xmax: 505763.8 ymax: 4800020
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
  X_leaflet_id feature_type                       geometry
1          660      polygon POLYGON ((505690.75 4799997...

Note that map2$finished shows epsg: 4326 although I used crs = 32630 in this case. The problem is that the bbox is in UTM coords (= epgs 32630) and the epsg ID in lat/lon.

Also when calling st_crs directly on map1 it returns NA while calling it on your map2 works fine. map1 was created with mapview(native.crs = T, crs = 32630). Any idea why?

st_crs(map1)
$epsg
[1] NA

$proj4string
[1] NA

attr(,"class")
[1] "crs"

@tim-salabim
Copy link
Member

what version of the package are you using? with the latest github version I get:

map3
$drawn
NULL

$edited
Simple feature collection with 1 feature and 2 fields
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 505676.4 ymin: 4799965 xmax: 505779.6 ymax: 4800026
epsg (SRID):    32630
proj4string:    +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs
  X_leaflet_id layerId                       geometry
1          614     { } POLYGON ((505770.7081 47999...

$deleted
NULL

$finished
NULL

attr(,"recorder")
attr(,"recorder")[[1]]
attr(,"recorder")[[1]]$evt
[1] "map_draw_edited_features"

attr(,"recorder")[[1]]$timestamp
[1] "2017-09-13 07:37:44 CEST"

attr(,"recorder")[[1]]$feature
Simple feature collection with 1 feature and 2 fields
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 505676.4 ymin: 4799965 xmax: 505779.6 ymax: 4800026
epsg (SRID):    32630
proj4string:    +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs
# A tibble: 1 x 3
  X_leaflet_id layerId          geometry
         <int>   <chr>  <simple_feature>
1          614     { } <POLYGON ((50...>

@pat-s
Copy link
Member Author

pat-s commented Sep 13, 2017

mapedit        * 0.3.6    2017-09-13 Github (r-spatial/mapedit@1efb86c)
mapview        * 2.1.7    2017-09-13 Github (r-spatial/mapview@7372c3c)

Just tried your and mine example again and got the same result with a resulting epsg: 4326 :/

I have no idea where the error source could be located right now 😯

@tim-salabim
Copy link
Member

is the $edited also in 4326 in your case?

@pat-s
Copy link
Member Author

pat-s commented Sep 13, 2017

Yes, if I edit something its also in 4326. If I delete the polygon and draw a new one as well. Its then stored under $finished.

@pat-s pat-s closed this as completed Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants