2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

shapelyのsvg出力

Last updated at Posted at 2016-03-10

ああ、shapelyは流行ってないのか。まあいいや

shapelyでgeojsonから画面出力までのサンプルである。

通常はmatplotlibでやるんだろうが、せっかくsvgがあるんでこれを
使いたいなあと思って書いたコードである。とうぜんといってはなんだが
jupyter notebookでの利用が前提である。

.svg()という関数もあるんだが、こっちはあんまりうまくいかない
chromeのせいなんだろうか?

これleafletかなんかを使えばもっとシンプルにできるのかねえ?
まあ、この表示のあと、線の交点を求めるintersectionとかを使いたいので、
shapelyでないといけないんだけど、この
_repr_svg_()のインターフェースしかないんかねえ?
st.replaceはやりすぎかんがあるんだが、まあしかたがないよね
ソースをいじった方が早いかなあ?

tokyo.py
from shapely.geometry import *
import simplejson
from IPython.display import HTML

f=open('tokyo.geojson')
jsn=simplejson.load(f)
s=[]
for i in jsn['features']:
    if(i['properties']['area_en']=='Tokubu'):
        s.append(shape(i['geometry']))

sm=MultiPolygon(s)
st=sm._repr_svg_()
st=st.replace('width="100.0"','width="300.0"')
st=st.replace('height="100.0"','height="300.0"')
st=st.replace('stroke-width="0.0076922352"','stroke-width="0.0008922352"')
# st
HTML(st)
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?