get bounding box from ggmap object
Asked Answered
D

1

6

I'm using ggmap library in R. I'm trying to download a rectangular map with it, but I know it'll give me a square. I only need the bounding box of the returned square.

library(ggmap)
map <- get_map(c(-65.7,-3.1,-64.4,-2.3),maptype="satellite",filename="map.png")
str(map)

 chr [1:1280, 1:1280] "#294829" "#294829" "#2D512D" "#264425" ...
 - attr(*, "class")= chr [1:2] "ggmap" "raster"
 - attr(*, "bb")='data.frame':  1 obs. of  4 variables:
  ..$ ll.lat: num -3.14
  ..$ ll.lon: num -65.5
  ..$ ur.lat: num -2.26
  ..$ ur.lon: num -64.6

Object map have two classes "ggmap" and "raster". I can't use @ or $ in it. How then can I access the ll.lat and other attributes from "bb" sub-object?

Delagarza answered 5/2, 2015 at 15:54 Comment(0)
M
11

You can do this:

> attr(map, "bb")
     ll.lat    ll.lon    ur.lat    ur.lon
1 -3.139567 -65.48877 -2.261646 -64.60986
Minicam answered 5/2, 2015 at 17:41 Comment(2)
Perhaps. I generally feel that way after seeing most answers on SO! :) glad it helped.Minicam
I don't see this on an object I got from qmap; should I? I see what may be the box in map$data...Ester

© 2022 - 2024 — McMap. All rights reserved.