2014-09-17 1 views
1

내 코드는 A 지점에서 B 지점까지지도와 선을 생성하는 데 적합하지만 극동 반구의 국가의 경우 선은 최단 경로 (예 : 호주에서 동쪽)를 통과하려고 시도하고 플롯에서 직선을 만들기 위해 끊습니다. 어떤 제안? 나는 코드를 짧게하고 모두 아래에 포함되어 있습니다.지도에서 선을 그리기 - gcIntermediate

greatCircle을 사용하면 (코드의 링크에서) 언급되었지만 작동하지 못했습니다.

감사합니다.

adds <- c("Argentina", 
      "Australia", 
      "Germany", 
      "Japan", 
      "Korea") 

# people are coming 'from' all those spots 'to' heidelberg 
add0 <- "Salt Lake City, UT" 

# get lat/lon 
from <- geocode(adds) 
to <- geocode(add0) 

from 

# see: http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/ 
library(maps) 
library(geosphere) 


# will need to adjust these limits... 
xlim <- c(-170, 200) 
ylim <- c(-50, 95) 

quartz(file = "UCC.pdf", 
     type = "pdf", 
     height = 5, width = 9) 

#print the map itself 
map("world", 
    fill=TRUE, 
    xlim=xlim, 
    ylim=ylim, 
    # projection = "mercator", 
    # orientation=c(90,-111, 0), 
    col = grey(0.50), 
    bg = grey(0.08), 
    lwd=0.05) 

# following gets the 2D projection of a line moving between two points on a sphere 
for (i in 1:nrow(from)) { 
    inter <- gcIntermediate(c(from[i, "lon"], 
          from[i, "lat"]), 
          c(to[1, "lon"], 
          to[1, "lat"]), 
          n=500, addStartEnd = T) 

    # and plot lines 
    lines(inter, 
     col = grey(0.90), 
     lwd = 1) 
} 

dev.off() 

답변

3

대답을 알아 냈습니다. breakAtDateLine을 true로 설정해야합니다. 이렇게하면 줄의 각 섹션을 개별적으로 그려서 목록과 코드 계정을 구분할 수 있습니다. DA에 도움을 청하십시오.

for (i in 1:nrow(from)) { 
    inter <- gcIntermediate(c(from[i, "lon"], 
          from[i, "lat"]), 
          c(to[1, "lon"], 
          to[1, "lat"]), 
          n=100, addStartEnd=TRUE, breakAtDateLine = T) 

if (is.list(inter)) { 
    inter1 <- inter[[1]] 
    inter2 <- inter[[2]] 
    lines(inter1, 
     col = grey(0.90), 
     lwd = .75) 
    lines(inter2, 
     col = grey(0.90), 
     lwd = .75) 
} else { 
    # and plot lines 
    lines(inter, 
     col = grey(0.90), 
     lwd = .75) 

}} 

dev.off() 
관련 문제