Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

python - GeoPandas and Bokeh extract xs and ys from data - WorldMap

I found this post on Geopandas and bokeh extract xs and ys from data

What I need is basically the same thing but for the map of the whole world (extract XS and ys from GeoPandas and convert into bokeh readable format). I am struggling with the fact the world data has both polygons and multi polygons.

If anyone can help, that would be much appreciated. Thanks!

question from:https://stackoverflow.com/questions/65903761/geopandas-and-bokeh-extract-xs-and-ys-from-data-worldmap

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is how you can run a GeoJSON using pandas GeoJSONDataSource like I mentioned in my comment.

from bokeh.models import GeoJSONDataSource
from bokeh.plotting import figure, show, output_notebook
import geopandas as gp

output_notebook()

world = gp.read_file(gp.datasets.get_path('naturalearth_lowres'))
geo_source = GeoJSONDataSource(geojson=world.to_json())

p = figure(title='World', tooltips=[('Country', '@name')],
           x_range=(-180, 180), y_range=(-90, 90), 
           x_axis_location=None, y_axis_location=None,
           plot_width=1000, plot_height=500
          )
p.patches('xs', 'ys', fill_alpha=0.4, fill_color='grey', 
          line_color='black', line_width=0.5, source=geo_source
         )
show(p)

Output

world


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...