2015-02-05 90 views
4

我在R中使用ggmap库我试图用它下载一个矩形地图,但我知道它会给我一个方形。我只需要返回的方块的边界框。从ggmap对象中获取边界框

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 

对象地图有两个类 “ggmap” 和 “光栅”。我不能在其中使用@或$。那么我怎样才能从“bb”子对象访问ll.lat和其他属性?

回答

8

你可以这样做:

> attr(map, "bb") 
    ll.lat ll.lon ur.lat ur.lon 
1 -3.139567 -65.48877 -2.261646 -64.60986 
+0

呵呵呵那么明显当你意识到这一点...... – Rodrigo 2015-02-05 19:38:34

+1

也许。在看到大多数答案之后,我通常会这样认为! :)很高兴它帮助。 – lawyeR 2015-02-05 20:01:55

+0

我在'qmap'中找不到这个对象;我是不是该?我看到'map $ data'中的框可能是... – MichaelChirico 2016-10-30 21:52:49