lat_0,lon_0被Basemap忽略

2024-05-07 18:58:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图设置Basemap以使用柱面等面积投影,并将原点放置在特定的lat/lon(这是为了匹配一些输入的x/y数据),但是似乎设置lat_0和{}参数没有任何作用。在

from mpl_toolkits.basemap import Basemap

# Oklahoma bounds 
# ('o' = origin at corner of Kingfisher/Logan/Canadian/Oklahoma counties)
lats = {'n':  37.1, 's':  33.6,  'c':  35.5, 'o':  35.726}
lons = {'e': -94.4, 'w': -103.0, 'c': -97.5, 'o': -97.674}

buf = 0.05 # plot buffer size (in degrees)

res = 'c' # map shapes resolution

# projection parameters
proj = 'cea' # cylindrical equal area
lat_ts = lats['c'] # true scale at geographic center
lon_0 = lons['o']  # x=0 at counties corner
lat_0 = lats['o']  # y=0 at counties corner

m = Basemap(projection = proj, lat_ts = lat_ts, resolution = res,
            lon_0 = lon_0, lat_0 = lat_0,
            urcrnrlon = lons['e'] + buf, urcrnrlat = lats['n'] + buf,
            llcrnrlon = lons['w'] - buf, llcrnrlat = lats['s'] - buf*4)

然后检查原点得到:

^{pr2}$

…这是地图边界的左下角,而不是我为lat_0lon_0提供的坐标。如果我完全忽略lat_0和lon_0,我得到相同的输出。在

起初,我想也许CEA投影不支持这些参数,我应该手动移动数据,但是the docs claim that ^{} and ^{} are used by all projections。在

作为解决方法,我可以设置偏移量以获得预期结果:

offset = m(lon_0, lat_0)
df['x'], df['y'] = (df.x + offset[0], df.y + offset[1]) # where df is a Pandas dataframe with my data

现在,我已将此问题作为一个问题提交到basemapgithub存储库中。 https://github.com/matplotlib/basemap/issues/192


Tags: 数据dfatoffset投影lonbasemaplat