地理データを製図する

Bokehは地理的データを使用するための支援を追加し始めた。すでに多くの強力な機能が使用可能だが、私たちはまだ追加しなければならないもっと多くの機能を持っている。以下のようにご利用例を教えてください Discourse あるいはあります。行け! GitHub そうすれば、私たちはあなたの要求を満たすためにこの機能を拡張し続けることができます。

プロバイダの地図をスライスする

Bokeh PlotはWebメルカトル投影を用いたXYZタイルサービスも利用可能である.このモジュールは bokeh.tile_providers 適切な属性を有する複数の事前構成スライスソースを含み、これらのスライスソースをブロックに追加することを使用することができる add_tile() 方法です。

from bokeh.plotting import figure, output_file, show
from bokeh.tile_providers import CARTODBPOSITRON, get_provider

output_file("tile.html")

tile_provider = get_provider(CARTODBPOSITRON)

# range bounds supplied in web mercator coordinates
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
           x_axis_type="mercator", y_axis_type="mercator")
p.add_tile(tile_provider)

show(p)

また、パスにご注意ください x_axis_type="mercator" そして y_axis_type="mercator" 至る figure 元のWebメルカトル座標ではなく、緯度および経度タグを有する軸が生成される。

グーグルマップ

Bokehはまだご利用いただけます gmap() 機能します。あなたが伝えなければならないのは Google API Key この関数に追加して正常に動作させ、どんなものでも GMapOptions Googleマップ参照ベースマップを構成するには、以下の操作を実行してください。Google API鍵は、Bokeh文書JSONに格納されます。

from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, GMapOptions
from bokeh.plotting import gmap

output_file("gmap.html")

map_options = GMapOptions(lat=30.2861, lng=-97.7394, map_type="roadmap", zoom=11)

# For GMaps to function, Google requires you obtain and enable an API key:
#
#     https://developers.google.com/maps/documentation/javascript/get-api-key
#
# Replace the value below with your personal API key:
p = gmap("GOOGLE_API_KEY", map_options, title="Austin")

source = ColumnDataSource(
    data=dict(lat=[ 30.29,  30.20,  30.29],
              lon=[-97.70, -97.74, -97.78])
)

p.circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8, source=source)

show(p)

注釈

GoogleにはGoogle Maps APIを使用する独自のサービス条項があり、どのBokehとGoogle Mapsの使用もGoogleのサービス条項に適合しなければなりません。

Google Mapsは常にアスペクト比を明示的に制御しています GMapPlot

  • わずか Range1d 支持範囲。他の範囲タイプを使用しようとすることはエラーを招くだろう。

  • 使用 BoxZoomTool 互換性がない GMapPlot それがそうです。1つ追加する BoxZoomTool 何の効果もありません。

GeoJSONデータ

GeoJSON 地理的要素をJSONで表す流行開放基準です。これは,点,線,ポリゴン(Bokehでは面片と呼ぶ)を要素集合として記述する.各機能は属性のセットを持つこともできる.

Bokeh‘s GeoJSONDataSource Bokehの代わりにほぼシームレスに使うことができます ColumnDataSource それがそうです。例:

import json

from bokeh.io import output_file, show
from bokeh.models import GeoJSONDataSource
from bokeh.plotting import figure
from bokeh.sampledata.sample_geojson import geojson

output_file("geojson.html")

data = json.loads(geojson)
for i in range(len(data['features'])):
    data['features'][i]['properties']['Color'] = ['blue', 'red'][i%2]

geo_source = GeoJSONDataSource(geojson=json.dumps(data))

TOOLTIPS = [
    ('Organisation', '@OrganisationName')
]

p = figure(background_fill_color="lightgrey", tooltips=TOOLTIPS)
p.circle(x='x', y='y', size=15, color='Color', alpha=0.7, source=geo_source)

show(p)

警告

舞台裏ではBokehはGeoJSON座標を x そして y あるいは…。 xs そして ys (要素が点,直線,多行,ポリゴンか多重ポリゴンかに依存する). GeoJSONを変換する際には,名前の衝突する属性が上書きされ,これらの属性の使用を避けるべきである. それがそうです。