I have been experiencing issues when using st_write
to export data as a geopackage in R. The following is an example of my workflow to export data as a geopackage:
install.packages("osmdata")
library(osmdata)
bb <- getbb('Montreal') #get bounding box for montreal
q <- opq(bbox = bb) #constructing an overpass API query (opq)
x <- q %>%
add_osm_feature(key = 'amenity', value = "hospital", value_exact = FALSE)
hospitals <- osmdata_sf(x) #Now that the query is designed, we can send it to Overpass, get the data, and store it as an sf object with osmdata_sf()
library(sf)
centroid_hospitals <- hospitals$osm_polygons %>% st_centroid()
st_write(centroid_hospitals, "hospitals.gpkg", "hospitals" )
I am successfully able to export the data as a layer in a geopackage. However, when I open the data in ArcGIS Pro, I am unable to add a new field to the attribute table. This seemed weird, so I tried opening the same data in ArcMap, and got the following error:
One or more layers failed to draw: main.hospitals: Attribute column not found[no such column: addr.city]
When I export the same data as a shapefile, I am able to use it in ArcGIS Pro and ArcMap as expected with no errors raised in either program:
st_write(centroid_hospitals, "hospitals.shp")
I am not sure if this is happening due to user error or if there is a bug with st_write
...