2012-12-15 2 views
3

안녕하세요, 저는 Basmap (matplot lib의 일부)에서 greatcircle 함수를 사용하여 세계지도에 IP 주소의 그래프를 매핑하려고했지만, 태평양 (즉, 미국 서해안과 호주의 어딘가에) 내 음모에 나타나는 수평선이 있습니다.Python Basemap drawgreatcircle 함수

는 나는이 문제로 인해 알고 : 누군가가 그것을 해결하는 방법을 알고 또는이 문제가 '일부러 다른 패키지를 알고있는 경우

Note Cannot handle situations in which the great circle intersects the edge of the map projection domain, and then re-enters the domain. (http://matplotlib.org/basemap/api/basemap_api.html#mpl_toolkits.basemap.Basemap.drawgreatcircle) 

그냥 궁금. 감사!

+0

, 그때 우리는 간단한 솔루션 ... – pelson

+0

참고로 올 수있는 (적어도 내 생각) 확신 basemap (1.0.8,)의 github 라이브러리이지만 현재 릴리즈 된 basemap (1.0.7) 버전에는 수정 사항이 포함되어 있지 않습니다. –

답변

8

기본 맵에서이 문제를 해결하기 위해 특정 경우에 당신이 결과 경로에있는 X 정점의 차이를 확인할 수 있습니다. 거기에서 우리는 나쁜 경로를 두 부분으로 나눌 수 있습니다. 나는베이스 맵과 함께이 일을 함께 내 자신의 예를 던진 :

from mpl_toolkits.basemap import Basemap 
import numpy as np 
import matplotlib.pyplot as plt 


m = Basemap(projection='cyl', lon_0=0, resolution='c') 

m.fillcontinents(color='coral',lake_color='aqua') 
m.drawmapboundary(fill_color='aqua') 

places = {'Mexico City': (19.05, -99.366667), 
      'London': (51.507222, -0.1275), 
      'Sydney': (-33.859972, 151.211111), 
      'Cape Town': (-33.925278, 18.423889), 
      'Delhi': (28.61, 77.23), 
      } 

network = [ 
      ('London', 'Delhi'), 
      ('Mexico City', 'Sydney'), 
      ] 


for source, target in network: 
    lat1, lon1 = places[source] 
    lat2, lon2 = places[target] 
    line, = m.drawgreatcircle(lon1, lat1, lon2, lat2, lw=3) 

    p = line.get_path() 
    # find the index which crosses the dateline (the delta is large) 
    cut_point = np.where(np.abs(np.diff(p.vertices[:, 0])) > 200)[0] 
    if cut_point: 
     cut_point = cut_point[0] 

     # create new vertices with a nan inbetween and set those as the path's vertices 
     new_verts = np.concatenate(
            [p.vertices[:cut_point, :], 
            [[np.nan, np.nan]], 
            p.vertices[cut_point+1:, :]] 
            ) 
     p.codes = None 
     p.vertices = new_verts 


plt.show() 

결과를 :

example output

이 일반적인 해결책이 아니다, 당신은 위도와 경도가있는 경우에만 작동합니다. 일반적인 문제를 해결하는 것은 많이, 많은 것은이고 더 초점은 cartopy (http://scitools.org.uk/cartopy/docs/latest/)입니다. 나는 이것을 다음 날 며칠 안에 cartopy에서 똑같은 줄거리를 보여주는 예제를 게시 할 것이다. 이 문제는 고정되어 있습니다 : 당신이 실패의 간단한 예제를 포함 할 수 있다면

HTH

0

이 문제가없는 다른 패키지 : cartopy (아직 알려지지 않음). 찾은 예제는 here입니다.

HTH