python basemap drawgreatcircle有奇怪的行为

时间:2013-03-12 21:51:26

标签: python matplotlib-basemap

我试图在一组点和第二点之间绘制一个大圆。然而,当我使用均值时,大圆路径是不正确的,但如果我使用与均值相同的预定义变量,则是正确的。下面是一个例子。

from mpl_toolkits.basemap import Basemap
import pyproj
from pylab import *

# setup basemap.
lat_1 = 49.5
lat_2 = 55.5
lat_0 = 52.5
lon_1 = -16.5
lon_2 = -1.0
lon_0 = -5.25


m = Basemap(llcrnrlon=lon_1,llcrnrlat=lat_1,urcrnrlon=lon_2,urcrnrlat=lat_2,
        resolution='i',projection='lcc',lon_0=lon_0,lat_0=lat_0)        
m.drawcoastlines()

lon1 = -8.2395881636363644
lat1 = 54.876441136363631

lons = [-8.3771698, -8.177818, -8.2758546, -8.2197834, -8.3409037, -8.247925, -8.3208079, -8.3288984, -8.1521259, -8.0139167, -8.1802664]
lats = [54.9846137, 54.8639587, 54.8730255, 54.89845, 54.9096928, 54.9390132, 54.7620135, 54.8300078, 54.8883947, 54.8743167, 54.8173659]

clon = mean(lons)
clat = mean(lats)

g = pyproj.Geod(ellps='WGS84')
az = 261.0
lon2, lat2, baz1 = g.fwd(lon1, lat1, az, 1000000)

m.drawgreatcircle(lon1, lat1, lon2, lat2, del_s=0.1)
m.drawgreatcircle(clon, clat, lon2, lat2, del_s=0.1)

clon==lon1
clat==lat1

有谁知道问题是什么?

1 个答案:

答案 0 :(得分:2)

>>> type(clon)
<type 'numpy.float64'>
>>> type(lon1)
<type 'float'>

可能drawgreatcircle()不知道如何处理numpy.float64,因此请将其转换为常规浮点数

>>> clon = float(clon)
>>> type(clon)
<type 'float'>