1

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...

Brenda Thompson
  • 327
  • 2
  • 9
  • What happens if you try exporting to a geojson or shapefile and using one of those in Arc? – John Polo Nov 08 '22 at 02:00
  • @JohnPolo as I mentioned in my question, exporting to shapefile works as expected in both programs. – Brenda Thompson Nov 08 '22 at 03:06
  • Sorry about the repetitive query. I don't have Arc access any more (and I haven't used it in years), so I can't try testing anything here. If you can get shapefiles exported and can use those, it'd be interesting to know if another file type is failing besides geopackage. If it's just geopackage, I'm wondering if there is a bug with `st_write()` for geopackage. That's not a definitive method of course. Can you verify that `addr.city` is in the shapefile? – John Polo Nov 08 '22 at 21:51

0 Answers0