-
Notifications
You must be signed in to change notification settings - Fork 292
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
st_write silently drops boolean columns over GDAL DB connection #722
Comments
Thanks! This tries to use the FieldDefn->GetSubType() logic of GDAL; I see logicals round tripped coming back as integers, but I can't see whether in PostGIS they are int or booleans (they print as 0/1: does this indicate they are not booleans?) I don't even know whether the gdal/postgis drivers supports all this, couldn't find any mentioning in the driver docs. |
Sorry my bad; this seems to work now: suppressPackageStartupMessages(library(sf))
nc_bool <-
st_read(
system.file("shape/nc.shp", package="sf"),
stringsAsFactors = FALSE,
quiet = TRUE
)[, c("AREA", "geometry")]
nc_bool$large_area <- nc_bool$AREA >= 0.15
st_write(nc_bool, "PG:dbname=postgis", "nc_bool", delete_layer = TRUE)
# Deleting layer `nc_bool' using driver `PostgreSQL'
# Updating layer `nc_bool' to data source `PG:dbname=postgis' using driver `PostgreSQL'
# features: 100
# fields: 2
# geometry type: Multi Polygon
st_read("PG:dbname=postgis", "nc_bool", quiet = TRUE) %>% sapply(class)
# $area
# [1] "numeric"
# $large_area
# [1] "logical"
# $wkb_geometry
# [1] "sfc_MULTIPOLYGON" "sfc" |
👍 suppressPackageStartupMessages(library(sf))
suppressPackageStartupMessages(library(dplyr))
nc_bool <- st_read(
system.file("shape/nc.shp", package = "sf"),
quiet = TRUE
)[, c("AREA", "geometry")]
nc_bool$large_area <- nc_bool$AREA >= 0.15
st_write(obj = nc_bool, dsn = "nc_bool.gpkg", delete_layer = TRUE)
#> Deleting layer `nc_bool' using driver `GPKG'
#> Updating layer `nc_bool' to data source `C:\Temp\R\Rtmp0UjShP\nc_bool.gpkg' using driver `GPKG'
#> features: 100
#> fields: 2
#> geometry type: Multi Polygon
st_read(dsn = "nc_bool.gpkg", quiet = TRUE) %>% sapply(class)
#> $AREA
#> [1] "numeric"
#>
#> $large_area
#> [1] "logical"
#>
#> $geom
#> [1] "sfc_MULTIPOLYGON" "sfc" |
Documented in |
I meant documented in |
First of all, I don't think any of this (neither support, nor non-support of logical through sf-gdal) ended up in user documentation; github comments simply reflect what I know, or think, at a particular moment in time. It hadn't occurred to me that beyond an |
No, I don't know any other types we should look into at the moment, but I'll let you know should I run into one 😉 . I do not mean to make a big thing of this. I was just surprised that this works now in |
I was surprised too, but it seems an RTFM case (for me, that is). Will add to NEWS. |
As mentioned in #592,
st_write
silently drops boolean columns on a GDAL DB connection:There should be a warning when the driver drops a column. IMO there should also be a warning in the help file re: GDAL and boolean columns (#579) and the use of the GDAL driver possibly even discouraged for DB connections when there are good ‘native’ R DB drivers available (i.e. at least for PostgreSQL)
Session info
The text was updated successfully, but these errors were encountered: