Closed tibbles-and-tribbles closed 9 months ago
Thanks @tibbles-and-tribbles! I looked at the write_sf
help file and it states "append logical; should we append to an existing layer, or replace it? if TRUE append". Thus, it seems to me like a bug in sf.
@Robinlovelace -- can you confirm it? @tibbles-and-tribbles can you open a new issue on the sf issue tracker?
library(sf)
library(spData)
write_sf(world, dsn = "world_many_layers.gpkg", append = TRUE)
write_sf(world, dsn = "world_many_layers.gpkg", append = TRUE)
st_layers("world_many_layers.gpkg")
#> Driver: GPKG
#> Available layers:
#> layer_name geometry_type features fields crs_name
#> 1 world_many_layers Multi Polygon 354 10 WGS 84
I thought the documentation matched my results (or maybe I'm just interpreting it incorrectly). The new data is being appended to an existing layer when I set append = TRUE
, for example, the existing layer in world.gpkg
doubled in terms of features. But the docs for append
don't say that a new layer would be created.
@tibbles-and-tribbles -- you are totally right! Sorry for adding more confusion
@tibbles-and-tribbles What do you think about the following fix?
Instead of overwriting the file, we could add a new layer to the file by specifying the `layer` argument.
This is supported by several spatial formats, including GeoPackage.
```{r 07-read-write-plot-31, results='hide'}
write_sf(obj = world, dsn = "world_many_layers.gpkg", layer = "second_layer")
@tibbles-and-tribbles -- you are totally right! Sorry for adding more confusion
No worries. I'm just happy that I can contribute!
@tibbles-and-tribbles What do you think about the following fix?
Instead of overwriting the file, we could add a new layer to the file by specifying the `layer` argument. This is supported by several spatial formats, including GeoPackage. ```{r 07-read-write-plot-31, results='hide'} write_sf(obj = world, dsn = "world_many_layers.gpkg", layer = "second_layer")
Sure, that makes more sense, but I haven't played around with the layer
argument yet.
See:
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.7.3, PROJ 9.2.1; sf_use_s2() is TRUE
library(spData)
write_sf(world, dsn = "world_many_layers.gpkg", append = TRUE)
write_sf(world, dsn = "world_many_layers.gpkg", layer = "second_layer")
st_layers("world_many_layers.gpkg")
#> Driver: GPKG
#> Available layers:
#> layer_name geometry_type features fields crs_name
#> 1 world_many_layers Multi Polygon 177 10 WGS 84
#> 2 second_layer Multi Polygon 177 10 WGS 84
In subsection 8.4.1, you state that setting
append = TRUE
will create a new layer, but I'm not able to get that result.Output:
Even if I use the
world.gpkg
file instead, I still don't get a multilayer file.Output: