0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Automating GIS Processes 2024 写経 Lesson 1(3)

Last updated at Posted at 2025-05-05

前回の続き

Polygon

内周もあるポリゴンを作ってみましょう。Polygon()の第二引数で内周のリストを指定します。

from shapely.geometry import LinearRing, Polygon

# define the exterior
outer = LinearRing([(-180, 90), (-180, -90), (180, -90), (180, 90)])

# define a hole:
hole = LinearRing([(-170, 80), (-100, -80), (100, -80), (170, 80)])

polygon_with_hole = Polygon(outer, [hole])
polygon_with_hole

holeのところだけ、白抜きになりました。
image.png

image.png

printすると、内周の座標も表示されます。
image.png

Polygon properties and methods

Polygonはいろいろな属性を持っています。print文の内容は教材からすこし変更しています。

print(f"重心: {polygon_with_hole.centroid}")
print(f"面積: {polygon_with_hole.area}")
print(f"minx, miny, maxx, maxy: {polygon_with_hole.bounds}")
print(f"exterior: {polygon_with_hole.exterior}")
print(f"exteriorr.coords: {list(polygon_with_hole.exterior.coords)}")
print(f"周囲(長さ): {polygon_with_hole.exterior.length}")

image.png

Check your understanding

多角形のお絵かきができます。
なお、円(真円)を描きたいときは、Polygonではなく、Pointを使います。

# Circle (using a buffer around a point)
point = Point((0,0))
point.buffer(1)

ちょっとだけ変形。結果は同じです。さて、distanceの1はどういう意味なのでしょうか。後ほど出てくるとかもですが。

# Circle (using a buffer around a point)
point = Point((0,0))
point.buffer(distance=1)

image.png

Geometry collections (optional)

optionalなので省略します。
まあ、PointとかLinestringとかPolygonを複数まとめて管理できる、ということです。

Convex hull and envelope

Convex hull:凸包(convex hull)とは, 与えられた点をすべて包含する最小の凸多角形(凸多面体)のこと
凸多角形:単純な多角形であって、その内部または境界にある任意の二点間を結ぶ線分が、その多角形の外に出ることがないもの

とのことです。私もあまりよくわかっていませんが。

まずは、MultiPointを用意します。
image.png

convex_hull属性を取得しています。確かに、与えられた点をすべて包含する最小の凸多角形ですね。
image.png

次にenvelope属性を取得します。convex_hullとは異なった値です。
image.png

envelopeについては、よくわかりませんでした。。。

Validity of geometries

Point Linestring Polygonなどは、それを定義しうる要件があります。その要件を満たすことをチェックする関数is_validが用意されています。

image.png

いったんここまでとします。次回はExercise 1です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?