如何在Bokeh中绘制纬度和经度。

3
我已经在bokeh中创建了一个图形,其中X和Y轴标签显示纬度和经度坐标,但使用WMTS瓷砖地图,这当然使用墨卡托投影。 我推测Bokeh正在进行某种转换,因为在他们的文档中他们说:
"还要注意,将x_axis_type ="mercator"和y_axis_type ="mercator"传递给figure会生成带有纬度和经度标签的轴,而不是原始Web Mercator坐标" (https://docs.bokeh.org/en/latest/docs/user_guide/geo.html
然而,当我绘制标记时,它们忽略了X和Y轴刻度,而是根据Mercator比例尺绘制。
title = "test"

mercator_extent = dict(start=-20000000, end=20000000,bounds=None)

# create a tile source
tile_options = {}
tile_options['url'] = 'http://tile.stamen.com/watercolor/{z}/{x}/{y}.jpg'
tile_options['attribution'] = """
    Map tiles by <a href="http://stamen.com">Stamen Design</a>, under
    <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>.
    Data by <a href="http://openstreetmap.org">OpenStreetMap</a>,
    under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.
    """

mq_tile_source = WMTSTileSource(**tile_options)

source = ColumnDataSource(data=OrderedDict(lat=([50]), lon=([50])))

x_range= Range1d(**mercator_extent)
y_range= Range1d(**mercator_extent)

plot = figure(title='printed line on map',
              tools= "pan,wheel_zoom",
              x_range=x_range,
              x_axis_type="mercator",
              y_axis_type="mercator",
              y_range=y_range,
              sizing_mode = 'stretch_both')#create a figure

plot.add_tile(mq_tile_source)#add the map

plot.circle(source=source,x='lon',y='lat',line_color ='red')

output_file("file.html")
save(plot)

我认为将X和Y轴设置为“墨卡托投影”,我的X和Y轴标签将显示为纬度和经度,因此我的标记应该相应地绘制在轴上。换句话说,根据上面的示例,我应该有一个观察X和Y轴的标记,但我没有。下面的图像显示输出结果;悬停工具显示我的数据是50 LAT和LON,因此我希望标记出现在我手动绘制的紫色斑点处,但它实际上绘制在几乎正中心的位置。

enter image description here

任何想法?
1个回答

5

我将回答自己的问题。

标签是LAT和LNG,但基础图绘制是通过墨卡托坐标实现的。

可以通过将具有“Lat”和“Lon”列的DF传递到以下函数中来将LAT/LNG转换为Mercator:

def wgs84_to_web_mercator(df, lon="LON", lat="LAT"):

      k = 6378137
      df["x"] = df[lon] * (k * np.pi/180.0)
      df["y"] = np.log(np.tan((90 + df[lat]) * np.pi/360.0)) * k

      return df

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接