mapview doesn't show multipolygons of a query from osmdata

197 views Asked by At

I am using the osmdata package to bring the universities of Bogota, some of these are mapped as multipolygons. However the plot comes out empty. Any idea how to fix it?

library(osmdata)
library(mapview)
query <- opq(bbox = "Bogota") %>% add_osm_feature(key = "amenity",value = "university") %>% osmdata_sf()
mapview(query$osm_multipolygons[,c("osm_id","name","amenity")], map.types = "OpenStreetMap")
#mapview(query$osm_polygons[,c("osm_id","name","amenity")], map.types = "OpenStreetMap")

Note: when plotting the points or polygons it works correctly.

1

There are 1 answers

0
Rafael Díaz On BEST ANSWER

The solution is to make a transformation to the object's coordinate system. As it's shown in the following:

library(osmdata)
library(mapview)
library(sf)
query <- opq(bbox = "Bogota") %>% 
  add_osm_feature(key = "amenity",value = "university") %>%
  osmdata_sf()

query <- query$osm_multipolygons[,c("osm_id","name","amenity")] %>%
  st_transform(st_crs("+proj=utm +ellps=GRS80 +datum=WGS84")) %>% 
  st_make_valid() 

mapview(query, map.types = "OpenStreetMap")

enter image description here

For more information check the following link. Coordinate Systems in R