-
Notifications
You must be signed in to change notification settings - Fork 300
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
Merging layers #1172
Comments
even if we force them to be all read as res <- dir_ls("shp", glob = "*.shp") %>%
tibble(fname = .) %>%
mutate(data = map(fname, read_sf, type = 6)) %>%
unnest(data)
# Error: No common type for `..1$data$geometry` <sfc_MULTIPOLYGON> and `..2$data$geometry` <sfc_MULTIPOLYGON>. Removing the geometry column makes this work. As this might indeed be a |
You need to write We're planning a drastic simplification of the way a common type is declared (ptype2 methods). In the mean time you'll need to write the double dispatch methods. You might also need to define vec-proxy and vec-restore methods. The proxy is the raw data that vctrs will concatenate or subset, and then the restore method restores attributes based on the result. You might need to define your proxy to return a data frame if you have vectorised attributes (i.e. metadata in your attributes for each element of the S3 vector). I've been meaning to look into sf-vctrs compatibility, sorry I didn't have time to get to it yet. |
Thanks - I think I'll wait for your drastic simplification before diving into this! |
Thanks for investigating... |
It looks like it! I'm now getting: #> Simple feature collection with 1018 features and 19 fields
#> geometry type: GEOMETRY
#> dimension: XY
#> bbox: xmin: 834044 ymin: 6504749 xmax: 943513 ymax: 6604240
#> epsg (SRID): NA
#> proj4string: NA With the legacy tidyr, I'm seeing these warnings indicating attributes were being lost:
The loss of these attributes is my working hypothesis for the different
With vctrs-powered tidyr we now manipulate data frames (splitting and combining on rows) while correctly preserving attributes. @dicorynia Note that as a stopgap you can use |
Thank you both of you, on this issue and for your work on sf... |
There are still two issues running this case:
I think the first we should address, the second may be a somewhat deeper problem, related to usability. |
Agreed that we should look into geometries later on, probably in several stages. Regarding the CRS attributes, they are propagated from the first element without any check right? I see in attributes(ret) = attributes(lst[[1]]) # crs |
With this in # Propagate CRS attributes from the LHS
ret = st_sfc(crs = st_crs(x)) We now have:
If it doesn't make sense to always propagate the CRS of the first element, other possible strategies are:
Regarding |
Just a remark - all code relating to |
Thanks @rsbivand - this will not affect the work here, since we are only assigning / copying entire CRS objects, possibly checking they are identical, which is handled by other code (the |
It was the |
@lionel- I think
@rsbivand that |
@edzer oops I now see your message, I'll update the error messages to use your wording. |
Is there a description or implementation of the combination strategy you're looking for? AFAICS class(st_sfc(st_point(), st_multipoint()))
#> [1] "sfc_GEOMETRY" "sfc"
class(st_sfc(st_polygon(), st_multipolygon()))
#> [1] "sfc_GEOMETRY" "sfc" Also, should the sfc geometry be set to MULTIPOLYGON even though it contains POLYGON geometries? Or should the individual geometries be upcoerced to MULTIPOLYGON? But surely changing the individual types is potentially problematic. Can a multipolygon of size 1 considered equal to the equivalent polygon (as I understand yes, through the notion of spatial equality)? |
It is a more generic usability thing, although I brought it up I would also leave it for here/now. Users can anticipate this by specifying |
I used list-columns and
map
+unnest
to merge multiple shapefiles into onesf
object. But it recently doesn't work any longer (it worked in March 2019). I'm not sure if it's related tosf
ortidyr
.Reprex :
I don't know the inner workings of
vctrs
... Shouldsf
"advertise" in some way that POLYGON and MULTIPOLYGON are compatible (are they ?) ?Any other method to easily merge multiple layers ?
Since the structures of the files are slightly different (column numbers) I can't use
rbind
:Thanks.
The text was updated successfully, but these errors were encountered: