我将尝试在bokeh中绘制一些圆形标记,使用Python和Stamen Toner地图。我有来自Google Map API的位置数据,其格式如下:
latitude 41.552164 longitude 44.990961
但是,bokeh地图绘图得到的数据点是以X和Y坐标格式表示的。我该如何将这些纬度/经度坐标转换为X和Y坐标?
谢谢。
我将尝试在bokeh中绘制一些圆形标记,使用Python和Stamen Toner地图。我有来自Google Map API的位置数据,其格式如下:
latitude 41.552164 longitude 44.990961
你的问题有些模糊,不清楚你具体想要做什么。提供一个代码示例会更好地帮助得出更好的答案。
通常情况下,当试图绘制从在线来源获取的地理数据时,您将拥有使用坐标系统(WGS84)获取的数据,其中纬度是y轴,经度是x轴。 Bokeh可以通过在ColumnDataSource中正确指定名称来简单地绘制经度和纬度。
from bokeh.io import show
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
longitude = [44.990961]
latitude = [41.552164]
source = ColumnDataSource(data=dict(longitude=longitude, latitude=latitude))
p = figure(plot_width=400, plot_height=400)
p.circle(x='longitude', y='latitude', source=source)
show(p)
如果您的问题确实与数据的坐标转换有关,那么没有更多细节很难回答您的问题。我建议您查看https://en.wikipedia.org/wiki/Map_projection来了解地图投影。
如果您需要将经度/纬度坐标转换为不同的坐标系,则可以使用pyproj
软件包。
import pyproj
project_projection = pyproj.Proj("+init=EPSG:4326") # wgs84
google_projection = pyproj.Proj("+init=EPSG:3857") # default google projection
longitude = [44.990961]
latitude = [41.552164]
x, y = pyproj.transform(google_projection, project_projection, longitude, latitude)
print(x, y)
Google投影参考:Google地图API v3投影?
shapely
使用pyproj
包实现,例如:from functools import partial
from shapely.geometry import Point
from shapely.ops import transform
import pyproj
pnt = transform(
partial(
pyproj.transform,
pyproj.Proj(init='EPSG:4326'),
pyproj.Proj(init='EPSG:3857')), Point(44.990961, 41.552164))
print(pnt.x, pnt.y)