LoginSignup
11
10

More than 5 years have passed since last update.

scipy Voronoi

Last updated at Posted at 2016-09-28

ボロノイ分割をしたかったので scipy.spatial.Voronoi を使ったのだけれど、用語や配列の意味に混乱したので、整理してみた。

ドキュメントにあるように、処理自体はすぐにできる。

import numpy
import scipy.spatial
v = scipy.spatial.Voronoi(numpy.array([[0,0],[0,1],[1,1]]))

まず point, region, ridge, vertice の意味。2 次元だとこんな絵になる。2 次元だと ridge は線だけれども、3 次元だと ridge は面になる。

IMG_1585[1].JPG

それぞれのデータは Voronoi object の属性に対応表の形で入っている。インデックス番号で対応表は表現されている。図にするとこんな感じで辿るようになっている。少し凝ったことをすると、たくさん辿らないといけないので、迷子にならないように丁寧に追いかけないといけない。

IMG_1584[1].JPG

閉じた領域で Polygon を作る時は、例えば次のようなコードになる。

import geopandas as gpd
from shapely.geometry import Polygon
va = gpd.GeoDataFrame([dict(geometry=Polygon([v.vertices[vt] for vt in v.regions[r]]), pti=pti)
    for pti,r in enumerate(v.point_region) if -1 not in v.regions[r]])
11
10
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
11
10