【问题标题】:How to plot Latitude and Longitude in Bokeh如何在散景中绘制纬度和经度
【发布时间】:2019-12-02 08:43:21
【问题描述】:

我创建了一个散景图,其中 X 和 Y 轴标签显示纬度和经度坐标,但使用 WMTS 平铺地图,当然使用墨卡托投影。我认为 Bokeh 进行了某种转换,因为在他们的文档中他们说:

“另请注意,将 x_axis_type="mercator" 和 y_axis_type="mercator" 传递给图形会生成带有纬度和经度标签的轴,而不是原始的 Web 墨卡托坐标” (https://docs.bokeh.org/en/latest/docs/user_guide/geo.html)

但是,当我绘制由 LAT 和 LON 设置的标记时,它们会忽略 X 和 Y 轴比例,而是根据墨卡托比例进行绘制

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 轴 = "mercator" 我的 X 和 Y 轴标签显示为纬度和经度,因此我的标记应该相应地绘制在轴上。换句话说,根据上面的示例,我应该有观察 X 和 Y 轴的标记,但我没有。

下图显示了输出;悬停工具显示我的数据是 50 LAT 和 LON,所以我希望标记位于我手动绘制紫色斑点的位置,但它几乎绘制死点

有什么想法吗?

【问题讨论】:

    标签: python maps bokeh


    【解决方案1】:

    我会回答我自己的问题

    标签是 LAT 和 LNG,但底层图是通过墨卡托坐标进行的

    可以通过将带有 Lat 和 Lon 列的 DF 传递给以下函数来从 LAT/LNG 转换为墨卡托:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 2014-08-15
      • 2023-04-02
      相关资源
      最近更新 更多