StatsFragments instead of ** geopandas ** introduced in PyData.Tokyo Meetup # 9-"Geographic Information Data" I tried it with reference to .hatenablog.com/entry/2015/07/18/215951).
It's easy if you put Anaconda and use conda-forge of Anaconda cloud. One command below [^ 1].
bash
conda install -y geopandas -c conda-forge
I also prepared a Docker image tsutomu7 / geopandas. You should be able to do it as follows. (Please refresh your browser after starting the Jupyter server)
bash
firefox http://localhost:8888 &
docker run -it --rm -p 8888:8888 tsutomu7/geopandas sh -c "jupyter notebook --ip=*"
Preparation. flatten is an array of arrays.
python3
%matplotlib inline
import numpy as np, pandas as pd, geopandas as gpd
from bokeh.plotting import output_notebook, show, figure
output_notebook()
flatten = lambda i: [a for b in i for a in (flatten(b) if hasattr(b,'__iter__') else (b,))]
The version of geopandas is 0.2.1, which is the latest at this time.
python3
gpd.__version__
>>>
'0.2.1'
Download Tokyo data from Global Map Japan.
python3
!wget --no-check-certificate https://github.com/dataofjapan/land/raw/master/tokyo.geojson
Take a look at the first three lines.
python3
df = gpd.read_file('tokyo.geojson')
df[:3]
area_en | area_ja | code | geometry | ward_en | ward_ja |
---|---|---|---|---|---|
0 | Tokubu | Tokyo 23 wards | 131211.0 | POLYGON ((139.821051 35.815077, 139.821684 35.... | Adachi Ku |
1 | Tokubu | Tokyo 23 wards | 131059.0 | POLYGON ((139.760933 35.732206, 139.761002 35.... | Bunkyo Ku |
2 | Tokubu | Tokyo 23 wards | 131016.0 | POLYGON ((139.770135 35.705352, 139.770172 35.... | Chiyoda Ku |
The geometry contains polygon data. Draw with matplotlib.
python3
df[df['area_en'] == 'Tokubu'].plot();
This time, draw with bokeh. Since the polygon of geometry is a mixture of shapely.geometry.polygon.Polygon and shapely.geometry.multipolygon.MultiPolygon, flatten it to make an array of Polygon.
python3
xy = [i.exterior.coords.xy for i in flatten(df[df.area_en == 'Tokubu'].geometry)]
p = figure(plot_width=400, plot_height=300)
p.patches([tuple(i[0]) for i in xy], [tuple(i[1]) for i in xy],
fill_color='white', line_color="black", line_width=0.5)
show(p);
Geocoding didn't work.
Reference link
-I want to plot geographic information with Python geopandas + Bokeh
[^ 1]: You can also do it with "conda install -y pyproj shapely fiona; pip install geopandas".
that's all
Recommended Posts