使用ggmap创建正射地图

7
在以下脚本中,我读取了许多点对,并在地图上绘制了线条。我使用ggmap从谷歌拉取地图,将这些线条绘制在地图上:
source('./library/latlong2state.R')

library(maps)
library(mapproj)
library(mapdata)
library(geosphere)
library(ggmap)

fileName = "_CanadaData/CanadaHospitalComplete.csv"

getLineColor <- function(val) {
  pal <- colorRampPalette(lineColours)
  colors <- pal(80)
  val.log <- log(val)

  if (val > 50) {
    col <- colors[80]
  } else {
    colindex <- max(1, round( 80 * val / 50))
    col <- colors[colindex]
  }
  return(col)
}

# Load the data
location <- read.csv(fileName, stringsAsFactors=FALSE)

# Omit locations that are not on the map of focus (not needed for city maps unless they are on a border)
location$state <- latlong2state(data.frame(location$lng, location$lat))
location$nearstate <- latlong2state(data.frame(location$lngnear, location$latnear))
location <- na.omit(location)

createMap <- function(bbox, thedata, mapzoom=3, linesize=0.6, pointsize=2) {
  basemap <- get_map(location=bbox, zoom=mapzoom, source='google', maptype="roadmap", color="color")
  ggmap(basemap) + geom_segment(aes(x=lng, xend=lngnear, y=lat, yend=latnear, color=dist_miles), size=0.6, data=thedata) + geom_point(aes(x=lngnear, y=latnear), size=2, color="#000000", border="black", data=thedata) + scale_color_gradient(low="blue", high="red", limits=c(0, max(thedata$dist_miles))) + coord_map("orthographic")
}

# Country bounding box c(left, bottom, right, top)
canada <- c(-140.920514, 42.016722, -52.524864, 83.2911)
createMap(canada, location)

很遗憾,由于加拿大位于北纬较高的位置,这会导致地图顶部的距离发生严重畸变:

Distances to hospitals in Canada

为了解决这个问题,可以轻松切换到正投影图,只需在createMap函数中添加projection=mapprojection(orthographic)即可更改线条绘制的投影方式。但是,我无法更改从谷歌获取的地图图像的投影方式 - 它被固定在Web Mercator投影中。使用ggmap能否解决此问题?或者我需要尝试其他软件包吗?如果是,请问您有什么推荐?

你应该因为美丽而获得点赞。 - IRTFM
1个回答

3
简短的答案是“不行”。您只能使用谷歌所谓的“Web Mercator”投影。(它不是WGS84。那是一个数据,而不是投影。)我不知道是否有任何R库可以实现这一点,但您可能需要使用WMS服务器。一个很好的选择可能是GeoBase,它是加拿大特有的。http://www.geobase.ca/geobase/en/wms/index.html此外,我建议避免正射投影,而是使用已经被选为适用于加拿大的投影,例如为加拿大地图集选择的EPSG:42304。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接