-
Notifications
You must be signed in to change notification settings - Fork 288
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
Convert list columns to character strings before passing to GDAL? #2142
Comments
It's not clear to me what the issue is here: you get a clear error message, and use it to continue. What is also not clear from your issue is which column(s) is/are list columns, and why - can they non-trivially be converted into non-list columns, and if yes how? Also, how did they arise, did |
|
Update here: |
Looks like the underlying problem is badly written GML, which is read as a bad data.frame; |
> x = st_sf(geom = st_sfc(st_point(0:1), st_point(1:0)))
> x$a = list(1, 2) # bad data.frame: should have c(1, 2) here
> x
Simple feature collection with 2 features and 1 field
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1
CRS: NA
geom a
1 POINT (0 1) 1
2 POINT (1 0) 2
> st_write(x, "/tmp/x.gpkg")
writing: substituting ENGCRS["Undefined Cartesian SRS with unknown unit"] for missing CRS
Error in clean_columns(as.data.frame(obj), factorsAsCharacter) :
list columns are only allowed with raw vector contents You probably don't want this to be written to an |
My understanding was that it's non geo attribute columns like roadName. Would the geometries be incorrect if The work-around I came up with was
That fixed the problem documented in the original post. I'm not sure what is in the list columns. I can investigate if that would be of use and interest. |
If removing the list columns is good enough, then it solves your problem. Another simple approach would be > unl = function(x) { if(inherits(x, "sfc")) { x } else { unlist(x) } }
> data.frame(lapply(x, unl))
geometry a
1 POINT (0 1) 1
2 POINT (1 0) 2
> data.frame(lapply(x, unl)) |> sapply(class)
$geometry
[1] "sfc_POINT" "sfc"
$a
[1] "numeric" but of course I don't have your data, so can only say it worked for my example. |
Thanks for the additional reprex Edzer and apologies for not bringing one, will try to create a minimal example dataset based on the byzantine inputs I have from OS. If that code can pick up on edge cases like this I'm thinking it could go into |
OK, please reopen if you have one. |
Describe the bug
This is a bit of an edge case I think but I have data with the following structure:
When I try to write to .gpkg file it errors as follows:
To Reproduce
Sign up for Ordnance Survey license and follow instructions in Active Travel England's first in-house developed R package: https://github.com/acteng/mastermapr
I think this will fix it, removing the list columns:
The text was updated successfully, but these errors were encountered: