In [42]:
%pylab inline --no-import-all
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
In [47]:
from geopandas import GeoSeries;
gs = GeoSeries.from_file('minato_shinagawa.shp'); # 出典: 地球地図日本(国土地理院技術資料D・1-No.576) より港区・品川区を抜粋
In [48]:
gs
Out[48]:
In [49]:
gs.plot();
In [51]:
from geopandas import GeoDataFrame;
gdf = GeoDataFrame.from_file('minato_shinagawa.shp'); # 出典: 地球地図日本(国土地理院技術資料D・1-No.576) より港区・品川区を抜粋
In [52]:
gdf
Out[52]:
In [53]:
gdf.plot();
In [54]:
gs.plot();
In [57]:
GeoSeries([gs[0].buffer(-0.001)]).plot();
In [58]:
GeoSeries([gs[0].buffer(-0.005),gs[0],gs[0].buffer(0.01),gs[0].buffer(0.005)]).plot(alpha=0.3);
In [59]:
GeoSeries([gs[0],gs[1]]).plot();
In [60]:
GeoSeries(gs[0].union(gs[1])).plot();
In [61]:
GeoSeries([gs[0].buffer(0.001).intersection(gs[1].buffer(0.001))]).plot();
In [62]:
GeoSeries([gs[0],gs[1],gs[0].buffer(0.005).intersection(gs[1].buffer(0.005))]).plot();
In [63]:
japan_gdf = GeoDataFrame.from_file('gm-jpn-bnd_u_2_1/polbnda_jpn.shp') # 出典: 地球地図日本(国土地理院技術資料D・1-No.576)
In [64]:
japan_gdf.plot();
In [66]:
hokkaido=japan_gdf[japan_gdf['nam']=='Hokkai Do']; # 北海道のみ抽出
hokkaido.plot();
In [67]:
hokkaido.area.sum()
Out[67]:
In [68]:
hokkaido['pop'].max()
Out[68]:
In [69]:
hokkaido[hokkaido['pop']==hokkaido['pop'].max()]
Out[69]:
In [70]:
hokkaido.plot();
In [71]:
popDict = {laa: max(0,hokkaido[hokkaido['laa']==laa]['pop'].max()) for laa in hokkaido['laa']};
hokkaido.ix[:,'pop'] = [popDict[laa] for laa in hokkaido['laa']];
county_xs=[];
county_ys=[];
for poly in hokkaido['geometry']:
lons, lats = zip(*list(poly.exterior.coords))
county_xs.append(lons)
county_ys.append(lats)
colors = ["#AAA", "#888", "#666", "#444", "#222", "#000"]
popMax = hokkaido['pop'].max();
county_colors = []
county_names = []
county_pop = []
for pop,laa in zip(hokkaido['pop'],hokkaido['laa']):
rate = float(pop)/float(popMax);
idx = min(int(rate*6),5);
county_colors.append(colors[idx]);
county_names.append(laa);
county_pop.append(pop);
from bokeh import plotting;
source = plotting.ColumnDataSource(data = {'x':county_xs,'y':county_ys,'color':county_colors,'name':county_names,'pop':county_pop})
In [72]:
from bokeh.models import HoverTool
from collections import OrderedDict;
plotting.output_notebook();
TOOLS="pan,wheel_zoom,box_zoom,reset,hover,save"
p = plotting.figure(toolbar_location="left", plot_width=900, plot_height=700,tools=TOOLS)
p.patches('x', 'y',
fill_color='color', fill_alpha=0.7,
line_color="white", line_width=0.5,
source=source)
hover = p.select(dict(type=HoverTool))
hover.point_policy = "follow_mouse"
hover.tooltips = OrderedDict([
("Name", "@name"),
("(人口)", "@pop"),
("(Long, Lat)", "($x, $y)"),
])