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(2)

Posted at

前回の続き。

Lines

LineString properties and methods

前回の復習。複数の点から線を形成したので、線の座標=複数の点です。

# Get coordinate tuples
list(line.coords)

image.png

単一の点ではありません。単一の点では線にならない、という当たり前の話です。
x座標とy座標を分けることもできます。 xy[0]がx座標、xy[1]がyz座標です。

image.png

また、線なので長さが存在します。lengthに格納されています。
image.png

さて、この長さですが、a:点間距離の合計、b:始点→終点の直線距離なのでしょうか?

2.82842... ≒sqrt(2)*2なので、a:点間距離の合計でした。

line3 = LineString([(1, 1), (2,2), (3,1)])
line3.length

image.png

あと、線の重心はcentroidで求められます。
分かりやすくするために、先ほど作成したline3の重心を求めます。
image.png

Polygon

なお、この章は何かいっぱい書いてありますが、大半は help(Polygon)の出力のコピペです。。。

Creating a polygon geometry follows the same logic as creating a point or line geometry. However, as discussed above the rules for what constitutes a polygon are more complex: It is constructed of exactly one linear ring forming its exterior (perimeter), and any number of additional linear rings forming holes that are cut out of the exterior shell.

Consequently, the shapely.geometry.Polygon constructor function accepts two parameter: the first one, shell, is a list of coordinate tuples, a list of points, or a LinearRing, and will form the outer hull of the new polygon. The second, optional, parameter holes can be a list of holes to cut out of shell (the items in the list can be the same data types as shell).

ざっくりいうと、ポリゴン=外周と内周からなる多角形(内周のリングは必須ではない)かと思います。
ひとまず、必須の外周を引数に指定します。

from shapely.geometry import Polygon

# Create a Polygon from the coordinates
polygon1 = Polygon([(2.2, 4.2), (7.2, -25.1), (9.26, -2.456)])

image.png

LineStringと同じように、Pointのリストから作成することもできます。

polygon2 = Polygon([point1, point2, point3])

座標を見ましょう。

list(polygon1.coords)

エラーになりました。

NotImplementedError: Component rings have coordinate sequences, but the polygon does not

image.png

先ほどふれたとおり、ポリゴン=外周と内周からなる多角形なので、coords(座標)だけだと、どっち?という話になります。

なので、外周は、exterior.coordsで。

list(polygon1.exterior.coords)

image.png

内周は、、、設定していないので、表示できません。
image.png

なお、外周はexteriorで単数ですが、内周はinteriorsで複数です。
help(Polygon)の出力のコピペが役に立ちましたね。

image.png

なお、単純に座標をみたければ、printしてしまえばよいです。
image.png

またしても中途半端ですが、いったんここまでとします。

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?