get_stamenmap: Get a Stamen Map

Description Usage Arguments Value See Also Examples

View source: R/get_stamenmap.R

Description

get_stamenmap accesses a tile server for Stamen Maps and downloads/stitches map tiles/formats a map image. Note that Stamen maps don't cover the entire world, e.g. http://tile.stamen.com/terrain/#4/30.28/-87.21

Usage

1
2
3
4
5
6
7
get_stamenmap(bbox = c(left = -95.80204, bottom = 29.38048, right = -94.92313,
  top = 30.14344), zoom = 10, maptype = c("terrain", "terrain-background",
  "terrain-labels", "terrain-lines", "toner", "toner-2010", "toner-2011",
  "toner-background", "toner-hybrid", "toner-labels", "toner-lines",
  "toner-lite", "watercolor"), crop = TRUE, messaging = FALSE,
  urlonly = FALSE, color = c("color", "bw"), force = FALSE,
  where = tempdir(), ...)

Arguments

bbox

a bounding box in the format c(lowerleftlon, lowerleftlat, upperrightlon, upperrightlat).

zoom

a zoom level

maptype

terrain, terrain-background, terrain-labels, terrain-lines, toner, toner-2010, toner-2011, toner-background, toner-hybrid, toner-labels, toner-lines, toner-lite, or watercolor.

crop

crop raw map tiles to specified bounding box

messaging

turn messaging on/off

urlonly

return url only

color

color or black-and-white (use force = TRUE if you've already downloaded the images)

force

if the map is on file, should a new map be looked up?

where

where should the file drawer be located (without terminating "/")

...

...

Value

a ggmap object (a classed raster object with a bounding box attribute)

See Also

http://maps.stamen.com/#watercolor, ggmap

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
## Not run:  # to diminish run check time


##### basic usage
########################################

place <- "baylor science building"
google <- get_googlemap(place, zoom = 15)
ggmap(google)

# grab the bounding box
bbox <- bb2bbox(attr(google, "bb"))

# and pull stamen map tiles
ggmap(get_stamenmap(bbox, zoom = 13))
ggmap(get_stamenmap(bbox, zoom = 14))
ggmap(get_stamenmap(bbox, zoom = 15))
# ggmap(get_stamenmap(bbox, zoom = 16))
# ggmap(get_stamenmap(bbox, zoom = 17))



# since mid-2016, stamen's terrain tileset is available for
# the entire globe
place <- "mount everest"
(google <- get_googlemap(place, zoom = 9))
ggmap(google)
bbox_everest <- c(left = 86.05, bottom = 27.21, right = 87.81, top = 28.76)
ggmap(get_stamenmap(bbox_everest, zoom = 9))


# note that the osm code may not run due to overloaded
# servers.

##### maptypes
########################################

place <- "rio de janeiro"
google <- get_googlemap(place, zoom = 10)
ggmap(google)
bbox <- bb2bbox(attr(google, "bb"))


ggmap(get_stamenmap(bbox, maptype = "terrain"))
ggmap(get_stamenmap(bbox, maptype = "terrain-background"))
ggmap(get_stamenmap(bbox, maptype = "terrain-labels"))
ggmap(get_stamenmap(bbox, maptype = "terrain-lines"))
ggmap(get_stamenmap(bbox, maptype = "toner"))
ggmap(get_stamenmap(bbox, maptype = "toner-2010"))
ggmap(get_stamenmap(bbox, maptype = "toner-2011"))
ggmap(get_stamenmap(bbox, maptype = "toner-background"))
ggmap(get_stamenmap(bbox, maptype = "toner-hybrid"))
ggmap(get_stamenmap(bbox, maptype = "toner-labels"))
ggmap(get_stamenmap(bbox, maptype = "toner-lines"))
ggmap(get_stamenmap(bbox, maptype = "toner-lite"))
ggmap(get_stamenmap(bbox, maptype = "watercolor"))

ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 11), extent = "device")
ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 12), extent = "device")
ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 13), extent = "device")
ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 14), extent = "device")
ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 15), extent = "device")
# ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 16), extent = "device")
# ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 17), extent = "device")
# ggmap(get_stamenmap(bbox, maptype = "watercolor", zoom = 18), extent = "device")

stamen <- get_stamenmap(bbox, zoom = 15)
ggmap(stamen) +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)

stamen <- get_stamenmap(bbox, zoom = 15, crop = FALSE)
ggmap(stamen) +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)



ggmap(get_stamenmap(bbox, zoom = 15, maptype = "watercolor"))+
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)

ggmap(get_stamenmap(bbox, zoom = 15, maptype = "toner"))+
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 2)


# here's an interesting example:
us <- c(left = -125, bottom = 25.75, right = -67, top = 49)
map <- get_stamenmap(us, zoom = 5, maptype = "toner-labels")
ggmap(map)



# accuracy check - white house
gc <- geocode("the white house")

qmap("the white house", zoom = 16)  +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 3)

qmap("the white house", zoom = 16, source = "stamen", maptype = "terrain")  +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 3)





# accuracy check - statue of liberty
# see https://github.com/dkahle/ggmap/issues/32

gc <- geocode("statue of liberty")

googMapZ10 <- get_googlemap(center = as.numeric(gc))
bbZ10 <- attr(googMapZ10, "bb")
stamMapZ10 <- get_stamenmap(bb2bbox(bbZ10))

ggmap(googMapZ10) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
  )

ggmap(stamMapZ10) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
)


# using a higher zoom
googMapZ15 <- get_googlemap(center = as.numeric(gc), zoom = 15)
bbZ15 <- attr(googMapZ15, "bb")
stamMapZ15 <- get_stamenmap(bb2bbox(bbZ15),
  zoom = calc_zoom(bb2bbox(bbZ15))
)

ggmap(googMapZ15) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
)

ggmap(stamMapZ15) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
  )


# using a lower zoom
googMapZ5 <- get_googlemap(center = as.numeric(gc), zoom = 4)
bbZ5 <- attr(googMapZ5, "bb")
stamMapZ5 <- get_stamenmap(bb2bbox(bbZ5),
  zoom = calc_zoom(bb2bbox(bbZ5))
)

ggmap(googMapZ5) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
  )

ggmap(stamMapZ5) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
  )


stamMapZ5unCropped <- get_stamenmap(bb2bbox(bbZ5),
  zoom = calc_zoom(bb2bbox(bbZ5)),
  crop = FALSE)

ggmap(stamMapZ5unCropped) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
  )

qmap(location = c(lon = -74.0445, lat = 40.68925),
    zoom = 16, source = "stamen")  +
  geom_point(aes(x = lon, y = lat), data = gc, colour = "red", size = 3)


## End(Not run) # end dontrun

fresques/ggmap documentation built on May 28, 2019, 8:40 p.m.