-
Notifications
You must be signed in to change notification settings - Fork 304
append = T doesn't write geom column as geoemetry #2278
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
Comments
@etiennebr is this something you could look into? BR, |
Thanks for reporting @jonathananolan. I can reproduce the issue. I'll have a look library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.1, PROJ 9.3.1; sf_use_s2() is TRUE
con <- DBI::dbConnect(RPostgres::Postgres())
x <- st_sf(geometry = st_sfc(st_point(1:2)))
st_write(x, con, "x", append = TRUE, temporary = TRUE)
st_write(x, con, "y", temporary = TRUE)
st_read(con, "x")
#> Warning in st_read.DBIObject(con, "x"): Could not find a simple features
#> geometry column. Will return a `data.frame`.
#> geometry
#> 1 0101000000000000000000f03f0000000000000040
st_read(con, "y")
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2
#> CRS: NA
#> geometry
#> 1 POINT (1 2) Created on 2023-12-05 with reprex v2.0.2 |
It seems like loading the package from source with devtools::load_all("~/workspace/sf")
#> ...
#> Linking to GEOS 3.11.1, GDAL 3.6.4, PROJ 9.1.1; sf_use_s2() is TRUE
con <- DBI::dbConnect(RPostgres::Postgres(), host = "localhost")
x <- st_sf(geometry = st_sfc(st_point(1:2)))
st_write(x, con, "x", append = TRUE, temporary = TRUE)
st_read(con, "x")
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2
#> CRS: NA
#> geometry
#> 1 POINT (1 2) Created on 2023-12-06 with reprex v2.0.2 |
@etiennebr this works for me without problems, appending simply appends. The first time in an R session I write to a PostGIS database I see
|
One thing I forgot to mention was that the table has to be new. If there is an existing table with geometry behaviour is as you expect. It can be useful to use 'append = t' for a new table when you aren't sure if the table exists yet when writing. My current workaround is to write a function that checks, and if there is no table use append = F. Best, Jonathan. |
Thanks for sharing your workaround Jonathan since this can be useful to other users. It seems like having your version of @edzer, the |
If I'm making a new table from an sf object in R and I type
con is the connection:
The geometry column is stored as text. As a result you can't then import the sf object into R again.
But if I comment out "append = T" the geometry column is stored as geometry.
Is this expected behaviour? Thanks so much!
The text was updated successfully, but these errors were encountered: