`GetMapBD` <- structure(function# download a static map from the Google server
### Query the Google server for a static map tile, defined primarily by its
### center and zoom. Many additional arguments allow the user to customize
### the map tile.
(
center=c( lon=-76,lat=42), ##<< optional center (lat first,lon second )
size = c(640,640), ##<< desired size of the map tile image. defaults to maximum size returned by the Gogle server, which is 640x640 pixels
destfile, ##<< File to load the map image from or save to, depending on \code{NEWMAP}.
zoom =12, ##<< Google maps zoom level.
markers, ##<< (optional) defines one or more markers to attach to the image at specified locations. This parameter takes a string of marker definitions separated by the pipe character (|)
path="", ##<< (optional) defines a single path of two or more connected points to overlay on the image at specified locations. This parameter takes a string of point definitions separated by the pipe character (|)
span, ##<< (optional) defines a minimum viewport for the map image expressed as a latitude and longitude pair. The static map service takes this value and produces a map of the proper zoom level to include the entire provided span value from the map`s center point. Note that the resulting map may include larger bounds for either latitude or longitude depending on the rectangular dimensions of the map. If zoom is specified, span is ignored
frame, ##<< (optional) specifies that the resulting image should be framed with a colored blue border. The frame consists of a 5 pixel, 55 % opacity blue border.
hl, ##<< (optional) defines the language to use for display of labels on map tiles. Note that this paramater is only supported for some country tiles; if the specific language requested is not supported for the tile set, then the default language for that tile set will be used.
sensor = "true", ##<< specifies whether the application requesting the static map is using a sensor to determine the user`s location. This parameter is now required for all static map requests.
maptype = c("roadmap","mobile","satellite","terrain","hybrid","mapmaker-roadmap","mapmaker-hybrid")[2], ##<< defines the type of map to construct. There are several possible maptype values, including satellite, terrain, hybrid, and mobile.
format = c("gif","jpg","jpg-baseline","png8","png32")[5], ##<< (optional) defines the format of the resulting image. By default, the Static Maps API creates GIF images. There are several possible formats including GIF, JPEG and PNG types. Which format you use depends on how you intend to present the image. JPEG typically provides greater compression, while GIF and PNG provide greater detail. This version supports only PNG.
RETURNIMAGE = TRUE, ##<< return image yes/no default: TRUE
GRAYSCALE =FALSE, ##<< Boolean toggle; if TRUE the colored map tile is rendered into a black & white image, see \link{RGB2GRAY}
NEWMAP = TRUE, ##<< if TRUE, query the Google server and save to \code{destfile}, if FALSE load from destfile.
SCALE = 1, ##<< use the API's scale parameter to return higher-resolution map images. The scale value is multiplied with the size to determine the actual output size of the image in pixels, without changing the coverage area of the map
verbose=0 ##<< level of verbosity
){
##note<<Note that size is in order (lon, lat)
if (missing(destfile)) destfile=file.path(tempdir(),"mapTile.png")
if (is.character(center)) {
if (verbose) cat("geocoding ", center, "\n")
center = getGeoCodeBD(center,verbose)
}
if (all(c("lat","lon") %in% names(center))) center = center[c("lat","lon")]
##seealso<< \link{GetMapBD.bbox}
# if (is.null(names(center))) {
# names(center) = c("lat", "lon");
# } else stopifnot( all(names(center) %in% c("lat", "lon")) )
#
stopifnot(all(size <=640));
fileBase <- substring(destfile,1, nchar(destfile)-4);
fileExt <- substring(destfile,nchar(destfile)-2,nchar(destfile));
#save meta information about the image:
if (is.null(center)) {
if (verbose) print("Note that when center and zoom are not specified, no meta information on the map tile can be stored. This basically means that R cannot compute proper coordinates. You can still download the map tile and view it in R but overlays are not possible.");
#ans <- readLines(n=1);
#if (ans != "y") return();
MetaInfo <- list(lon.center = NULL, lat.center = NULL, zoom = zoom,
url = "baidu", BBOX = NULL, size=size, SCALE = SCALE);
save(MetaInfo, file = paste(destfile,"rda",sep="."));
} else if ( is.numeric(center) & !missing(zoom)) {
MyMap <- list(lon.center = center[1], lat.center = center[2], zoom = zoom, SCALE = SCALE);
BBOX <- list(ll = XY2LatLonBD(MyMap, -size[1]/2 + 0.5, -size[2]/2 - 0.5), ur = XY2LatLonBD(MyMap, size[1]/2 + 0.5, size[2]/2 - 0.5) );
MetaInfo <- list(lon.center = center[1], lat.center = center[2], zoom = zoom,
url = "baidu", BBOX = BBOX, size=size, SCALE = SCALE);
save(MetaInfo, file = paste(destfile,"rda",sep="."));
}
ttmp=center[1]
center[1]=center[2];
center[2]=ttmp;
if (length(size) < 2) {s <- paste(size,size,sep="x")} else {s <- paste(size,collapse="x");}
if (!is.null(center)) center <- paste(center,collapse=",")
if (missing(format)){
if ( fileExt == "png") format <- "png32"
}
googleurl <- "http://api.map.baidu.com/staticimage?"; # googleurl <- 'http://maps.google.com/staticmap?';
if (verbose>1) browser()
if (!missing(span)){#Images may specify a viewport (defined by latitude and longitude values expressed as degrees) to display around a provided center point by passing a span parameter. Defining a minimum viewport in this manner obviates the need to specify an exact zoom level. The static map service uses the span parameter in conjunction with the size parameter to construct a map of the proper zoom level which includes at least the given viewport constraints.
span <- paste(span,collapse=",")
url <- paste(googleurl, "center=", center, "&span=", span, "&width=", s[1], "&height=", s[2], "&maptype=", maptype, "&format=", format, "&sensor=", sensor, sep="")
} else if (is.null(center) & missing(zoom)) {#let the Static Maps API determine the correct center and zoom level implicitly, based on evaluation of the position of the markers:
stopifnot(!missing(markers) | path != "");
url <- paste(googleurl, "size=", s, "&maptype=", maptype, "&format=", format, "&sensor=", sensor, sep="")
} else {
stopifnot(!is.null(center), !missing(zoom));
url <- paste(googleurl, "center=", center, "&zoom=", zoom, "&width=", size[1], "&height=", size[2], "&maptype=", maptype, "&format=", format, "&sensor=", sensor, sep="")
}
url <- paste(url, path, sep="");
#cat('Now url is:::::::',url)
if (!missing(hl)) url <- paste0(url, "&language=",hl);
if (SCALE == 2) url <- paste(url, "&scale=", SCALE, sep="");
if (!missing(markers)) {
#assumes markers is a list with names lat, lon, size (optional), color (optional), char (optional)
if(is.data.frame(markers)) markers<-as.matrix(markers)
if ( is.matrix(markers)) {
stopifnot(all(c("lat","lon") %in% colnames(markers)))
latlon = which(colnames(markers) %in% c("lat","lon"))
for (i in 1:nrow(markers)){
m1 <- paste(markers[i,c("lon","lat")], collapse=",");
if (any(c("size","color","label") %in% colnames(markers) ) ) {
m2 <- paste(colnames(markers)[-latlon], markers[i,-latlon], collapse="|",sep=":");
m <- paste(m2,m1,sep="|")
} else {
m <- m1
}
#去掉了下一行的注释
#m <- paste("&markers=",m,sep="")
#print(m)
if (i==1){
markers.string <- m;
} else {
markers.string <- paste(markers.string,m, sep="|");
}
#if (verbose) print(markers.string);
}
#brows
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
RbaiduMaps_0.1.tar.gz (38个子文件)
RbaiduMaps
MyTile.png.rda 283B
man
RbaiduMaps.Rd 194B
DC.png 15KB
MyTile.png 98KB
NAMESPACE 126B
MyTile1.png 154B
SIDS.png.rda 281B
MyTile1.png.rda 292B
SIDS.png 16KB
DC.png.rda 284B
R
PlotPolysOnStaticMapBD.R 5KB
RbaiduMaps-package.r 68B
IdentifyPointsBD.R 691B
LatLon2XYBD.centered.R 1KB
AddAlphaBD.R 611B
ColorMapBD.R 4KB
MaxZoomBD.R 788B
getGeoCodeBD.R 1KB
MapBackgroundBD.R 3KB
degreeAxisBD.R 2KB
updateusrBD.R 3KB
GetMapBD.R 12KB
TextOnStaticMapBD.R 2KB
RGB2GRAYBD.R 2KB
XY2LatLonBD.R 2KB
qbboxBD.R 2KB
PlotOnStaticMapBD.R 6KB
ReadMapTileBD.R 1KB
DF2SpatialPointsDataFrameBD.R 843B
GetMapBD.OSM.R 3KB
SpatialToPBSBD.R 2KB
LatLon2XYBD.R 2KB
PlotArrowsOnStaticMapBD.R 2KB
GetMapBD.bbox.R 4KB
Tile2RBD.R 1KB
mypolygonBD.R 357B
bubbleMapBD.R 8KB
DESCRIPTION 402B
共 38 条
- 1
trueman007
- 粉丝: 21
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页