2014-01-05 1 views
7

다음 스크립트에서 여러 쌍의 점을 읽고지도에 선을 그립니다.ggmap을 사용하여 정사각형지도 만들기

Distances to hospitals in Canada :

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) 

불행하게도,이 때문에 캐나다의 북부 위도의지도의 상단에 거리의 엄청난 왜곡을 초래 : 나는 이상이 줄을 음모 구글에서지도에 끌어 ggmap을 사용하고 있습니다

이것은 직교 플롯으로 전환하면 쉽게 수정할 수 있으며, createMap 함수 내에 projection=mapprojection(orthographic)을 추가하여 선의 투영 방법을 변경할 수는 있지만 Google에서 얻은지도 이미지의 투영을 변경할 수는 없습니다. - 웹 메르카토르 투영법에 갇혀있다. ggmap을 사용하여이 작업을 수행 할 수있는 방법이 있습니까? 아니면 다른 패키지를 사용해보아야합니까? 그렇다면 무엇을 권하고 싶습니까?

+0

아름다움을위한 upvotes를 얻어야합니다. –

답변

3

짧은 대답은 "아니오"입니다. 당신은 구글의 소위 말하는 "웹 메르 케이터 (Web Mercator)"투영에 매달려 있습니다.

R 라이브러리가 있는지 잘 모르겠지만 아마도 WMS 서버를 사용해야 할 것입니다. (WGS84가 아닙니다. 좋은 선택은 아마도 캐나다에만 해당되는 GeoBase 일 것입니다. http://www.geobase.ca/geobase/en/wms/index.html

또한 직교 투영을 피하고 캐나다의 경우 Atlas of Canada : EPSG : 42304와 같이 캐나다에 적합한 것으로 선택하는 것이 좋습니다.

관련 문제