The my_box can be a matrix or a vector as the documenation for opq says
bbox - Either (i) four numeric values specifying the maximal and minimal longitudes and latitudes, in the form c(xmin, ymin, xmax, ymax) or (ii) a character string in the form xmin,ymin,xmax,ymax. These will be passed to getbb to be converted to a numerical bounding box. Can also be (iii) a matrix representing a bounding polygon as returned from getbb(..., format_out = "polygon").
With getbb, the output generated is a matrix with x values on the top row and y values below
getbb("Bogota", display_name_contains = "Colombia")
# min max
#x -74.223514 -74.01025
#y 4.471175 4.83317
getbb("Bogota", display_name_contains = "Colombia") %>%
opq() %>%
add_osm_feature(key = "amenity", "bank") %>%
osmdata_sf() -> bank_pol
So, if we check the OP's vector, some of the 'x' and 'y' values are reversed. It could be either created as
my_box <- c(-74.075607061386, 4.6304414673187, -74.072549343109, 4.6332058140013)
Now, call the opq
bank_pol <- opq(bbox = my_box, timeout = 25*100) %>%
add_osm_feature(key = "amenity", "bank") %>%
osmdata_sf()
-checking the data
bank_pol$osm_polygons
#Simple feature collection with 3 features and 18 fields
#geometry type: POLYGON
#dimension: XY
#bbox: xmin: -74.07552 ymin: 4.630524 xmax: -74.07264 ymax: 4.633099
#geographic CRS: WGS 84
# osm_id name addr.city addr.country addr.district #addr.housenumber addr.state addr.street
#392010374 392010374 Bancolombia Bogotá CO Teusaquillo 40-95 Distrito Capital Carrera 24
#392010458 392010458 Banco AV Villas Bogotá CO Teusaquillo 40-71/73 <NA> Carrera 24
#394955633 394955633 <NA> Bogotá CO Teusaquillo 42-19 <NA> Carrera 24
# addr.suburb amenity atm brand brand.wikidata brand.wikipedia building building.levels operator
#392010374 La Soledad bank yes Bancolombia Q806206 en:Bancolombia yes 2 Bancolombia
#392010458 La Soledad bank <NA> <NA> <NA> <NA> yes 4 <NA>
#394955633 La Soledad bank yes <NA> <NA> <NA> yes 2 Davivienda
# source geometry
#392010374 Kaart Ground Survey 2017 POLYGON ((-74.07546 4.63140...
#3392010458 Kaart Ground Survey 2017 POLYGON ((-74.07546 4.63112...
#394955633 <NA> POLYGON ((-74.0754 4.632585...
-plot
mapview(bank_pol$osm_polygons)
It is also possible to use ggmap
library(ggplot2)
library(ggmap)
library(sf)
library(osmdata)
bogota_map <- get_map(getbb("Bogota",
display_name_contains = "Colombia"), maptype = "toner-background")
ggmap(bogota_map) +
geom_sf(data = bank_pol$osm_points, inherit.aes = FALSE,
colour = "#238443",
fill = "#004529",
alpha = .5,
size = 4,
shape = 21)+
labs(x = "", y = "")