GEOS APILink to this heading

背景Link to this heading

GEOS とは?Link to this heading

GEOSGeometry Engine - Open Source の略であり、C++ライブラリであり、 Java Topology Suite から移植されました。GEOS は OpenGIS の Simple Features for SQL 空間記述関数や空間演算子を実装しています。GEOS は現在、OSGeo プロジェクトとなっており、もともとはカナダ・ビクトリアの Refractions Research によって開発・維持されていました。

特徴Link to this heading

GeoDjango は GEOS ライブラリの高レベルな Python ラッパーを実装しており、その機能には次のものがあります:

  • ctypes を使用して純粋に Python で実装された GEOS ジオメトリルーチンへの BSD ライセンスのインターフェイス。

  • GeoDjango とは疎結合です。たとえば、GEOSGeometry オブジェクトは Django プロジェクト/アプリケーションの外でも使用可能です。つまり、DJANGO_SETTINGS_MODULE を設定したり、データベースを使用する必要はありません。

  • ミュータビリティ (Mutability): GEOSGeometry オブジェクトは変更可能です。

  • クロスプラットフォームでテストされています。

チュートリアルLink to this heading

このセクションには、 GEOSGeometry オブジェクトの簡単な紹介とチュートリアルが含まれています。

ジオメトリを作成するLink to this heading

GEOSGeometry オブジェクトはいくつかの方法で作成できます。最初の方法は、単純に空間入力のオブジェクトをインスタンス化することです。以下は、同じジオメトリを WKT、HEX、WKB、GeoJSON から作成する例です:

Python console
>>> from django.contrib.gis.geos import GEOSGeometry
>>> pnt = GEOSGeometry("POINT(5 23)")  # WKT
>>> pnt = GEOSGeometry("010100000000000000000014400000000000003740")  # HEX
>>> pnt = GEOSGeometry(
...     memoryview(
...         b"\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x007@"
...     )
... )  # WKB
>>> pnt = GEOSGeometry(
...     '{ "type": "Point", "coordinates": [ 5.000000, 23.000000 ] }'
... )  # GeoJSON

もう一つの方法は、作成したい特定のジオメトリタイプのコンストラクタを使用することです。たとえば、Point オブジェクトは、そのコンストラクタに X 座標と Y 座標を渡すことで作成できます:

Python console
>>> from django.contrib.gis.geos import Point
>>> pnt = Point(5, 23)

これらのコンストラクタはすべて、キーワード引数 srid を受け取ります。例えば:

Python console
>>> from django.contrib.gis.geos import GEOSGeometry, LineString, Point
>>> print(GEOSGeometry("POINT (0 0)", srid=4326))
SRID=4326;POINT (0 0)
>>> print(LineString((0, 0), (1, 1), srid=4326))
SRID=4326;LINESTRING (0 0, 1 1)
>>> print(Point(0, 0, srid=32140))
SRID=32140;POINT (0 0)

最後に、ファイルから GEOSGeometry オブジェクトを返す fromfile() ファクトリーメソッドがあります:

Python console
>>> from django.contrib.gis.geos import fromfile
>>> pnt = fromfile("/path/to/pnt.wkt")
>>> pnt = fromfile(open("/path/to/pnt.wkt"))

ジオメトリは Pythonic ですLink to this heading

GEOSGeometry オブジェクトは 'Pythonic' (Pythonらしい) であり、要素には標準的な Python 形式を使ってアクセスしたり変更したり、イテレートしたりできます。例えば、Point の座標をイテレートできます:

Python console
>>> pnt = Point(5, 23)
>>> [coord for coord in pnt]
[5.0, 23.0]

ジオメトリオブジェクトの GEOSGeometry.coords プロパティを使用すると、ジオメトリ座標を Python のタプルで取得できます:

Python console
>>> pnt.coords
(5.0, 23.0)

標準の Python インデックス形式を使用して、ジオメトリオブジェクトを取得または設定できます。ただし、返されるものはオブジェクトのジオメトリタイプに依存します。例えば、LineString に対してインデックスを使用すると、座標の Python タプルが返されます:

Python console
>>> from django.contrib.gis.geos import LineString
>>> line = LineString((0, 0), (0, 50), (50, 50), (50, 0), (0, 0))
>>> line[0]
(0.0, 0.0)
>>> line[-2]
(50.0, 0.0)

Polygon 上のインデックス指定は、そのインデックスに対応するリング (LinearRing オブジェクト) を返します:

Python console
>>> from django.contrib.gis.geos import Polygon
>>> poly = Polygon(((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0)))
>>> poly[0]
<LinearRing object at 0x1044395b0>
>>> poly[0][-2]  # second-to-last coordinate of external ring
(50.0, 0.0)

さらに、ジオメトリの座標や要素はPythonのリストのように追加や変更が可能です:

Python console
>>> line[0] = (1.0, 1.0)
>>> line.pop()
(0.0, 0.0)
>>> line.append((1.0, 1.0))
>>> line.coords
((1.0, 1.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (1.0, 1.0))

ジオメトリーは set のような演算子をサポートします:

Python console
>>> from django.contrib.gis.geos import LineString
>>> ls1 = LineString((0, 0), (2, 2))
>>> ls2 = LineString((1, 1), (3, 3))
>>> print(ls1 | ls2)  # equivalent to `ls1.union(ls2)`
MULTILINESTRING ((0 0, 1 1), (1 1, 2 2), (2 2, 3 3))
>>> print(ls1 & ls2)  # equivalent to `ls1.intersection(ls2)`
LINESTRING (1 1, 2 2)
>>> print(ls1 - ls2)  # equivalent to `ls1.difference(ls2)`
LINESTRING(0 0, 1 1)
>>> print(ls1 ^ ls2)  # equivalent to `ls1.sym_difference(ls2)`
MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))

ジオメトリ・オブジェクトLink to this heading

GEOSGeometryLink to this heading

class GEOSGeometry(geo_input, srid=None, *, max_geom_collections=198)Link to this definition
パラメータ:
  • geo_input -- ジオメトリ入力値 (文字列または memoryview)

  • srid (int) -- 空間参照識別子

  • max_geom_collections -- maximum number of nested (WKT) or total (WKB) geometry collections accepted before parsing is refused

これはすべてのGEOSジオメトリオブジェクトの基底クラスです。geo_input 引数で初期化され、適切なジオメトリサブクラスを想定します (たとえば、 GEOSGeometry('POINT(1 1)')Point オブジェクトを作成します)。

パラメータ srid が与えられた場合、 geo_input が SRID を持っていない場合は、作成されたジオメトリの SRID が設定されます。パラメータ geo_inputsrid で異なる SRID が指定された場合、 ValueError が発生します:

Python console
>>> from django.contrib.gis.geos import GEOSGeometry
>>> GEOSGeometry("POINT EMPTY", srid=4326).ewkt
'SRID=4326;POINT EMPTY'
>>> GEOSGeometry("SRID=4326;POINT EMPTY", srid=4326).ewkt
'SRID=4326;POINT EMPTY'
>>> GEOSGeometry("SRID=1;POINT EMPTY", srid=4326)
Traceback (most recent call last):
...
ValueError: Input geometry already has SRID: 1.

以下の入力形式とそれに対応するPythonの型を受け付けます:

フォーマット

入力の型

WKT / EWKT

str

HEX / HEXEWKB

str

WKB / EWKB

memoryview

GeoJSON

str

GeoJSON形式では、SRIDは crs メンバーに基づいて設定されます。もし crs が指定されていない場合、SRIDはデフォルトで4326になります。

classmethod GEOSGeometry.from_gml(gml_string)Link to this definition

与えられたGML文字列から GEOSGeometry を構築します。

プロパティLink to this heading

GEOSGeometry.coordsLink to this definition

ジオメトリの座標をタプルで返します。

GEOSGeometry.dimsLink to this definition

ジオメトリの次元を返します:

GEOSGeometry.emptyLink to this definition

ジオメトリ内の点の集合が空であるかどうかを返します。

GEOSGeometry.geom_typeLink to this definition

ジオメトリの種類に対応する文字列を返します。例:

Python console
>>> pnt = GEOSGeometry("POINT(5 23)")
>>> pnt.geom_type
'Point'
GEOSGeometry.geom_typeidLink to this definition

GEOS ジオメトリタイプ識別番号を返します。  次の表に、各ジオメトリタイプの値を示します:

GEOSGeometry.num_coordsLink to this definition

ジオメトリ内の座標の数を返します。

GEOSGeometry.num_geomLink to this definition

このジオメトリに含まれるジオメトリの数を返します。つまり、ジオメトリ・コレクション以外では 1 を返します。

GEOSGeometry.haszLink to this definition

ジオメトリが3次元であるかどうかを示す真偽値を返します。

GEOSGeometry.ringLink to this definition

ジオメトリが LinearRing であるかどうかを示す真偽値を返します。

GEOSGeometry.simpleLink to this definition

与えられたジオメトリが "simple" であるかどうかを示す真偽値を返します。ジオメトリが "simple" であるのは、自分自身と交差しない場合に限ります (境界点での交差を除く) 。例えば、LineString オブジェクトは、自分自身と交差すると "simple" ではありません。したがって、定義上自身と交差しないため、LinearRingPolygon オブジェクトは常に "simple" です。

GEOSGeometry.validLink to this definition

ジオメトリが有効かどうかを示すブール値を返します。

GEOSGeometry.valid_reasonLink to this definition

ジオメトリが無効である理由を表す文字列を返します。

GEOSGeometry.sridLink to this definition

ジオメトリに関連付けられた SRID を取得または設定するために使用できるプロパティ。例えば:

Python console
>>> pnt = Point(5, 23)
>>> print(pnt.srid)
None
>>> pnt.srid = 4326
>>> pnt.srid
4326

出力プロパティLink to this heading

このセクションのプロパティは、GEOSGeometry オブジェクトを異なる()形式にエクスポートします。この出力は文字列、バッファ、または別のオブジェクトの形式で表されます。

GEOSGeometry.ewktLink to this definition

ジオメトリの "拡張" Well-Known Text を返します。この表現は PostGIS に固有であり、OGC WKT 標準のスーパーセットです。 [1] SRID は本質的に WKT 表現の前に付加されます。例えば SRID=4326;POINT(5 23) のようになります。

GEOSGeometry.hexLink to this definition

このジオメトリの WKB を 16 進数で返します。  SRID値はOGC仕様の一部ではないため、この表現には含まれないことに注意してください (代わりに GEOSGeometry.hexewkb プロパティを使用してください) 。

GEOSGeometry.hexewkbLink to this definition

このジオメトリのEWKBを16進形式で返します。これは、このジオメトリの一部であるSRID値を含むWKB仕様の拡張です。

GEOSGeometry.jsonLink to this definition

ジオメトリの GeoJSON 表現を返します。結果は完全な GeoJSON 構造ではなく、GeoJSON 構造の geometry キーの内容のみです。 GeoJSON シリアライザ も参照してください。

GEOSGeometry.geojsonLink to this definition

GEOSGeometry.json のエイリアス。

GEOSGeometry.kmlLink to this definition

ジオメトリの KML (Keyhole Markup Language) 表現を返します。 これは、SRID が 4326 (WGS84) のジオメトリにのみ使用すべきですが、この制限は強制されません。

GEOSGeometry.ogrLink to this definition

GEOS ジオメトリに対応する OGRGeometry オブジェクトを返します。

GEOSGeometry.wkbLink to this definition

このジオメトリのWKB (Well-Known Binary) 表現を Python バッファとして返します。SRID 値は含まれません。代わりに、ewkb プロパティを使用してください。

GEOSGeometry.ewkbLink to this definition

このジオメトリの EWKB 表現を Python バッファとして返します。これは、このジオメトリの一部であるすべての SRID 値を含む WKB 仕様の拡張です。

GEOSGeometry.wktLink to this definition

ジオメトリの Well-Known Text (OGC標準) を返します。

空間述語メソッド (Spatial Predicate Method)Link to this heading

以下の空間述語 (predicate) メソッドは、別の GEOSGeometry インスタンス (other) をパラメータとして受け取り、真偽値を返します。

GEOSGeometry.contains(other)Link to this definition

other.within(this)True を返した場合に True を返します。

GEOSGeometry.covers(other)Link to this definition

このジオメトリが指定したジオメトリをカバーしている場合は True を返します。

covers predicate は以下の定義と等価です:

  • もう一方のジオメトリのすべての点は、このジオメトリの点である。

  • 2つのジオメトリの DE-9IM 交差行列は T*****FF*, *T****FF*, ***T**FF*, または ****T*FF* である。

どちらかのジオメトリが空の場合、False を返します。

この predicate は GEOSGeometry.contains() に似ていますが、より包括的です (つまり、より多くの場合に True を返します) 。特に、 contains() とは異なり、ジオメトリの境界と内部の点を区別しません。ほとんどの場合、 contains() よりも covers() を優先すべきです。さらに、 covers() は最適化しやすいので、 contains() よりも優れています。

GEOSGeometry.crosses(other)Link to this definition

2つのジオメトリの DE-9IM 交差行列が T*T******* (点と曲線、点と面積、線と面積の場合) 0******** (2つの曲線の場合) である場合に True を返します。

GEOSGeometry.disjoint(other)Link to this definition

2つのジオメトリのDE-9IM交差行列が FF*FF**** である場合に True を返します。

GEOSGeometry.equals(other)Link to this definition

2つのジオメトリの DE-9IM 交差行列が T*F**FFF* である場合に True を返します。

GEOSGeometry.equals_exact(other, tolerance=0)Link to this definition

2つのジオメトリが指定した許容誤差まで正確に等しい場合に true を返します。tolerance 値は、比較における誤差の許容値を表す浮動小数点数である必要があります。たとえば、 poly1.equals_exact(poly2, 0.001) は、1000分の1単位以内で等しいかどうかを比較します。

GEOSGeometry.equals_identical(other)Link to this definition

すべての次元において、すべての頂点の構造、順序、および値が同じであることをチェックすることにより、2つのジオメトリが点的に等価である場合に True を返します。 NaN 値は他の NaN 値と等しいとみなされます。GEOS 3.12が必要です。

GEOSGeometry.intersects(other)Link to this definition

GEOSGeometry.disjoint()False の場合に True を返します。

GEOSGeometry.overlaps(other)Link to this definition

2つのジオメトリの DE-9IM 交差行列が T*T***T** (2つの点または2つの曲面の場合) 1*T***T** (2つの曲線の場合) である場合に true を返します.

GEOSGeometry.relate_pattern(other, pattern)Link to this definition

このジオメトリと他のジオメトリの DE-9IM 交差行列の要素が、与えられた pattern -- アルファベットから 9 文字の文字列と一致する場合に True を返します: {T, F, *, 0} の9文字の文字列。

GEOSGeometry.touches(other)Link to this definition

2つのジオメトリのDE-9IM交差行列が FT*******, F**T***** または F***T**** である場合に True を返します。

GEOSGeometry.within(other)Link to this definition

2つのジオメトリの DE-9IM 交差行列が T*F**F*** である場合に True を返します。

トポロジー的 (Topological) メソッドLink to this heading

GEOSGeometry.buffer(width, quadsegs=8)Link to this definition

このジオメトリからの距離が与えられた width 以下のすべての点を表す GEOSGeometry を返す。オプションの quadsegs キーワードは、1/4円の近似に使用するセグメントの数を設定します (デフォルトは8) 。

GEOSGeometry.buffer_with_style(width, quadsegs=8, end_cap_style=1, join_style=1, mitre_limit=5.0)Link to this definition

buffer() と同じですが、バッファのスタイルをカスタマイズできます。

  • end_cap_style には、round (1) 、flat (2) 、square (3) を指定できます。

  • join_style には round (1) 、mitre (2) 、bevel (3) のいずれかを指定します。

  • Mitre レシオ制限 (mitre_limit) は、mitre 形式の結合スタイルにのみ影響します。

GEOSGeometry.difference(other)Link to this definition

このジオメトリを構成する点のうち、他の点を構成しない点を表す GEOSGeometry を返す。

GEOSGeometry.interpolate(distance)Link to this definition
GEOSGeometry.interpolate_normalized(distance)Link to this definition

与えられた距離 (float) に対する、その距離上の点 (またはもっとも近い点) を返します。この距離は、 LineString または MultiLineString のジオメトリであり、正規化されたバージョンでは、0 (始点) から 1 (終点) の値を取る float 型として距離の値を取ります。

GEOSGeometry.project() の逆。

GEOSGeometry.intersection(other)Link to this definition

このジオメトリと他のジオメトリが共有する点を表す GEOSGeometry を返す。

GEOSGeometry.project(point)Link to this definition
GEOSGeometry.project_normalized(point)Link to this definition

ジオメトリ (LineString または MultiLineString) の原点から、ジオメトリに投影された点 (つまり、指定された点に最も近い線の点) までの距離 (float) を返します。正規化されたバージョンは、0 (原点) と 1 (終点) の間の浮動小数点数として距離を返します。

GEOSGeometry.interpolate() の逆。

GEOSGeometry.relate(other)Link to this definition

このジオメトリと他のジオメトリのトポロジカルな関係を表す DE-9IM 交差行列 (文字列) を返します。

GEOSGeometry.simplify(tolerance=0.0, preserve_topology=False)Link to this definition

新しい GEOSGeometry を返します。これは Douglas-Peucker アルゴリズムを用いて、指定した許容誤差まで単純化されます。許容誤差の値が大きいほど、出力される点は少なくなります。公差が指定されない場合、デフォルトは0です。

デフォルトでは、この関数はトポロジーを保持しません。例えば、 Polygon オブジェクトは分割されたり、線に折りたたまれたり、消えたりすることがあります。 Polygon の穴ができたり消えたり、線が交差したりすることがあります。 preserve_topology=True を指定することで、結果は入力と同じ次元と要素数になります。

GEOSGeometry.sym_difference(other)Link to this definition

このジオメトリに含まれる点のうち他のジオメトリに含まれない点と、他のジオメトリに含まれる点のうちこのジオメトリに含まれない点を結合した GEOSGeometry を返す。

GEOSGeometry.union(other)Link to this definition

このジオメトリともう一方のジオメトリのすべての点を表す GEOSGeometry を返す。

トポロジー的プロパティLink to this heading

GEOSGeometry.boundaryLink to this definition

新しく割り当てられた Geometry オブジェクトとして境界を返します。

GEOSGeometry.centroidLink to this definition

ジオメトリの幾何学的中心を表す Point オブジェクトを返します。この点はジオメトリの内側にあることは保証されません。

GEOSGeometry.convex_hullLink to this definition

ジオメトリ内のすべての点を含む最小の Polygon を返す。

GEOSGeometry.envelopeLink to this definition

このジオメトリの外接を表す Polygon を返します。入力ジオメトリが点の場合は Point を返すこともあります。

GEOSGeometry.point_on_surfaceLink to this definition

このジオメトリ内部に存在することが保証された Point を計算し、返します。

GEOSGeometry.unary_unionLink to this definition

このジオメトリのすべての要素の和集合を計算します。

結果は次の規約に従います:

  • LineString の集合を結合することは、ラインワークを完全にノード化し、分解する効果がある。

  • Polygon のセットを結合すると常に Polygon または MultiPolygon ジオメトリが返されます (GEOSGeometry.union() は、トポロジーの崩壊が発生した場合、次元が低いジオメトリが返される可能性がある点が異なります)。

その他のプロパティとメソッドLink to this heading

GEOSGeometry.areaLink to this definition

このプロパティは、ジオメトリの面積を返します。

GEOSGeometry.extentLink to this definition

このプロパティは、このジオメトリの範囲を (xmin, ymin, xmax, ymax) からなる4タプルで返します。

GEOSGeometry.clone()Link to this definition

このメソッドは、元のジオメトリのクローンである GEOSGeometry を返します。

GEOSGeometry.distance(geom)Link to this definition

このジオメトリと与えられた geom (別の GEOSGeometry オブジェクト) との間の最も近い点の距離を返します。

GEOSGeometry.lengthLink to this definition

このジオメトリの長さを返します (例: Point の場合は 0、LineString の長さ、または Polygon の円周)。

GEOSGeometry.preparedLink to this definition

このジオメトリの内容の GEOS PreparedGeometry を返します。 PreparedGeometry オブジェクトは、contains、intersects、covers、crosss、disjoint、overlaps、touches、および within の操作に最適化されています。詳細は 準備された (Prepared) ジオメトリ のドキュメントを参照してください。

GEOSGeometry.srsLink to this definition

ジオメトリの SRID に対応する SpatialReference オブジェクト、または None を返します。

GEOSGeometry.transform(ct, clone=False)Link to this definition

与えられた座標変換パラメータ (ct) に従ってジオメトリを変換します。座標変換パラメータは、整数の SRID、空間参照の WKT 文字列、PROJ 文字列、 SpatialReference オブジェクト、 CoordTransform オブジェクトのいずれかです。デフォルトでは、ジオメトリはその場で変換され、何も返されません。しかし、 clone キーワードが設定されている場合、ジオメトリは変更されず、変換されたジオメトリのクローンが返されます。

GEOSGeometry.make_valid()Link to this definition

入力された頂点を失わず、有効な GEOSGeometry に変換して返します。既に有効なジオメトリの場合、そのまま返されます。これは MakeValid データベース関数に類似しています。GEOS 3.8が必要です。

GEOSGeometry.normalize(clone=False)Link to this definition

このジオメトリを正規形に変換します。 clone キーワードがセットされている場合、ジオメトリは変更されず、代わりにジオメトリの正規化されたクローンが返されます:

Python console
>>> g = MultiPoint(Point(0, 0), Point(2, 2), Point(1, 1))
>>> print(g)
MULTIPOINT (0 0, 2 2, 1 1)
>>> g.normalize()
>>> print(g)
MULTIPOINT (2 2, 1 1, 0 0)

PointLink to this heading

class Point(x=None, y=None, z=None, srid=None)Link to this definition

Point オブジェクトは、ポイントの座標を表す引数を使用してインスタンス化されたり、1 つのシーケンス座標でインスタンス化されたりします。例えば、以下は同等です:

Python console
>>> pnt = Point(5, 23)
>>> pnt = Point([5, 23])

空の Point オブジェクトを引数なしまたは空のシーケンスを渡すことでインスタンス化できます。以下は同等です:

Python console
>>> pnt = Point()
>>> pnt = Point([])

LineStringLink to this heading

class LineString(*args, **kwargs)Link to this definition

LineString オブジェクトは、座標のシーケンスまたは Point オブジェクトを引数としてインスタンス化されます。例えば、以下は同等です:

Python console
>>> ls = LineString((0, 0), (1, 1))
>>> ls = LineString(Point(0, 0), Point(1, 1))

さらに、LineString オブジェクトは、座標または Point オブジェクトのシーケンスを渡すことによっても作成できます:

Python console
>>> ls = LineString(((0, 0), (1, 1)))
>>> ls = LineString([Point(0, 0), Point(1, 1)])

空の LineString オブジェクトは、引数を渡さないか空のシーケンスを渡すことでインスタンス化できます。以下は同等です:

Python console
>>> ls = LineString()
>>> ls = LineString([])
closedLink to this definition

この LineString が閉じているかどうかを返します。

LinearRingLink to this heading

class LinearRing(*args, **kwargs)Link to this definition

LinearRing オブジェクトは、LineString オブジェクトとまったく同じ方法で構築されますが、座標は 閉じている 必要があります。つまり、最初の座標と最後の座標が同じである必要があります。例:

Python console
>>> ls = LinearRing((0, 0), (0, 1), (1, 1), (0, 0))

(0, 0) は最初で最後の座標です。もし等しくなければ、エラーが発生します。

is_counterclockwiseLink to this definition

この LinearRing が反時計回りかどうかを返します。

PolygonLink to this heading

class Polygon(*args, **kwargs)Link to this definition

Polygon オブジェクトは、多角形のリングを表すパラメータを渡すことでインスタンス化できます。パラメータは、 LinearRing インスタンスであるか、 LinearRing を構築するために使用できるシーケンスである必要があります。

Python console
>>> ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
>>> int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 0.4))
>>> poly = Polygon(ext_coords, int_coords)
>>> poly = Polygon(LinearRing(ext_coords), LinearRing(int_coords))
classmethod from_bbox(bbox)Link to this definition

与えられたバウンディングボックスからポリゴンオブジェクトを返します。ポリゴンオブジェクトは (xmin, ymin, xmax, ymax) からなる4タプルで構成されます。

num_interior_ringsLink to this definition

このジオメトリの内部リングの数を返します。

ジオメトリのコレクションLink to this heading

MultiPointLink to this heading

class MultiPoint(*args, **kwargs)Link to this definition

MultiPoint オブジェクトは Point オブジェクトを引数として渡すか、1つの Point オブジェクトのシーケンスを渡すことでインスタンス化できます。

Python console
>>> mp = MultiPoint(Point(0, 0), Point(1, 1))
>>> mp = MultiPoint((Point(0, 0), Point(1, 1)))

MultiLineStringLink to this heading

class MultiLineString(*args, **kwargs)Link to this definition

MultiLineString オブジェクトは、 LineString オブジェクトを引数として渡すか、1つの LineString オブジェクトのシーケンスを渡すことでインスタンス化が可能です。

Python console
>>> ls1 = LineString((0, 0), (1, 1))
>>> ls2 = LineString((2, 2), (3, 3))
>>> mls = MultiLineString(ls1, ls2)
>>> mls = MultiLineString([ls1, ls2])
mergedLink to this definition

この MultiLineString のすべてのコンポーネントを結合した線を表す LineString を返します。

closedLink to this definition

すべての要素が閉じられている場合にのみ True を返します。

MultiPolygonLink to this heading

class MultiPolygon(*args, **kwargs)Link to this definition

MultiPolygon オブジェクトは、 Polygon オブジェクトを引数として渡すか、1つの Polygon オブジェクトのシーケンスを渡すことでインスタンス化できます。

Python console
>>> p1 = Polygon(((0, 0), (0, 1), (1, 1), (0, 0)))
>>> p2 = Polygon(((1, 1), (1, 2), (2, 2), (1, 1)))
>>> mp = MultiPolygon(p1, p2)
>>> mp = MultiPolygon([p1, p2])

GeometryCollectionLink to this heading

class GeometryCollection(*args, **kwargs)Link to this definition

GeometryCollection オブジェクトは、他の GEOSGeometry オブジェクトを引数として渡すか、または単一の GEOSGeometry オブジェクトのシーケンスを引数として渡すことでインスタンス化できます:

Python console
>>> poly = Polygon(((0, 0), (0, 1), (1, 1), (0, 0)))
>>> gc = GeometryCollection(Point(0, 0), MultiPoint(Point(0, 0), Point(1, 1)), poly)
>>> gc = GeometryCollection((Point(0, 0), MultiPoint(Point(0, 0), Point(1, 1)), poly))

準備された (Prepared) ジオメトリLink to this heading

事前に準備された prepared ジオメトリを取得するには、 GEOSGeometry.prepared プロパティにアクセスします。 PreparedGeometry インスタンスを取得したら、以下にリストされているその空間述語 (predicate) メソッドを他の GEOSGeometry オブジェクトで使用できます。prepared ジオメトリを使った操作は、桁違いに高速になることがあります。prepared ジオメトリがより複雑な場合、操作は大いに高速化されます。詳細については、 GEOS wiki page on prepared geometries. を参照してください。

例:

Python console
>>> from django.contrib.gis.geos import Point, Polygon
>>> poly = Polygon.from_bbox((0, 0, 5, 5))
>>> prep_poly = poly.prepared
>>> prep_poly.contains(Point(2.5, 2.5))
True

PreparedGeometryLink to this heading

class PreparedGeometryLink to this definition

PreparedGeometry のすべてのメソッドは other 引数を取ります。この引数は GEOSGeometry インスタンスでなければなりません。

contains(other)Link to this definition
contains_properly(other)Link to this definition
covers(other)Link to this definition
crosses(other)Link to this definition
disjoint(other)Link to this definition
intersects(other)Link to this definition
overlaps(other)Link to this definition
touches(other)Link to this definition
within(other)Link to this definition

ジオメトリ ファクトリLink to this heading

fromfile(file_h)Link to this definition
パラメータ:

file_h (a Python file object or a string path to the file) -- 空間データを含む入力ファイル

戻り値の型:

ファイル内の空間データに対応する GEOSGeometry

例:

Python console
>>> from django.contrib.gis.geos import fromfile
>>> g = fromfile("/home/bob/geom.wkt")
fromstr(string, srid=None)Link to this definition
パラメータ:
  • string (str) -- 空間データを含む文字列

  • srid (int) -- 空間参照識別子

戻り値の型:

文字列内の空間データに対応する GEOSGeometry

fromstr(string, srid) は、 GEOSGeometry(string, srid) と同等です。

例:

Python console
>>> from django.contrib.gis.geos import fromstr
>>> pnt = fromstr("POINT(-90.5 29.5)", srid=4326)

I/O オブジェクトLink to this heading

Reader オブジェクトLink to this heading

Reader I/Oクラスは、 read(geom) メソッドに渡されたWKBおよび/またはWKT入力から GEOSGeometry インスタンスを返します。

class WKBReaderLink to this definition

例:

Python console
>>> from django.contrib.gis.geos import WKBReader
>>> wkb_r = WKBReader()
>>> wkb_r.read("0101000000000000000000F03F000000000000F03F")
<Point object at 0x103a88910>
class WKTReaderLink to this definition

例:

Python console
>>> from django.contrib.gis.geos import WKTReader
>>> wkt_r = WKTReader()
>>> wkt_r.read("POINT(1 1)")
<Point object at 0x103a88b50>

Writer オブジェクトLink to this heading

すべての Writer オブジェクトは write(geom) メソッドを持っており、与えられたジオメトリの WKB または WKT を返します。さらに、WKBWriter オブジェクトは、バイトオーダーを変更したり、SRID 値 (言い換えれば、EWKB) を含めるために使用できるプロパティも持っています。

class WKBWriter(dim=2)Link to this definition

WKBWriter はその出力を最もコントロールできます。デフォルトでは、 write メソッドが呼ばれると OGC 準拠の WKB を返します。ただし、追加情報を含むWKB標準のスーパーセットであるEWKBを作成できるプロパティも持っています。引数 dim の詳細については WKBWriter.outdim のドキュメントを参照してください。

write(geom)Link to this definition

与えられたジオメトリの WKB を Python の buffer オブジェクトとして返します。例:

Python console
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> pnt = Point(1, 1)
>>> wkb_w = WKBWriter()
>>> wkb_w.write(pnt)
<read-only buffer for 0x103a898f0, size -1, offset 0 at 0x103a89930>
write_hex(geom)Link to this definition

ジオメトリのWKBを16進数で返します。例:

Python console
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> pnt = Point(1, 1)
>>> wkb_w = WKBWriter()
>>> wkb_w.write_hex(pnt)
'0101000000000000000000F03F000000000000F03F'
byteorderLink to this definition

このプロパティを設定すると、ジオメトリ表現のバイトオーダーを変更できます。

バイトオーダーの値

説明

0

ビッグエンディアン (例: RISC システムと互換性あり)

1

リトルエンディアン (例: x86 システムと互換性あり)

例:

Python console
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> wkb_w = WKBWriter()
>>> pnt = Point(1, 1)
>>> wkb_w.write_hex(pnt)
'0101000000000000000000F03F000000000000F03F'
>>> wkb_w.byteorder = 0
'00000000013FF00000000000003FF0000000000000'
outdimLink to this definition

このプロパティは、ジオメトリ表現の出力次元を変更するために設定できます。つまり、3D ジオメトリの場合は 3 に設定し、Z 値が WKB に含まれるようにします。

Outdim 値

説明

2

デフォルトで、2次元のWKBを出力します。

3

3D の WKB を出力します。

例:

Python console
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> wkb_w = WKBWriter()
>>> wkb_w.outdim
2
>>> pnt = Point(1, 1, 1)
>>> wkb_w.write_hex(pnt)  # By default, no Z value included:
'0101000000000000000000F03F000000000000F03F'
>>> wkb_w.outdim = 3  # Tell writer to include Z values
>>> wkb_w.write_hex(pnt)
'0101000080000000000000F03F000000000000F03F000000000000F03F'
sridLink to this definition

このプロパティに真偽値を設定して、ジオメトリのSRIDがWKB表現に含まれるかどうかを示します。例:

Python console
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> wkb_w = WKBWriter()
>>> pnt = Point(1, 1, srid=4326)
>>> wkb_w.write_hex(pnt)  # By default, no SRID included:
'0101000000000000000000F03F000000000000F03F'
>>> wkb_w.srid = True  # Tell writer to include SRID
>>> wkb_w.write_hex(pnt)
'0101000020E6100000000000000000F03F000000000000F03F'
class WKTWriter(dim=2, trim=False, precision=None)Link to this definition

このクラスを使用すると、ジオメトリの WKT 表現を出力できます。コンストラクタの引数の詳細については WKBWriter.outdim, trim, precision 属性を参照してください。

write(geom)Link to this definition

与えられたジオメトリのWKTを返します。例:

Python console
>>> from django.contrib.gis.geos import Point, WKTWriter
>>> pnt = Point(1, 1)
>>> wkt_w = WKTWriter()
>>> wkt_w.write(pnt)
'POINT (1.0000000000000000 1.0000000000000000)'
outdimLink to this definition

WKBWriter.outdim を参照。

trimLink to this definition

このプロパティは、不要な小数のトリミングを有効または無効にするために使用されます。

Python console
>>> from django.contrib.gis.geos import Point, WKTWriter
>>> pnt = Point(1, 1)
>>> wkt_w = WKTWriter()
>>> wkt_w.trim
False
>>> wkt_w.write(pnt)
'POINT (1.0000000000000000 1.0000000000000000)'
>>> wkt_w.trim = True
>>> wkt_w.write(pnt)
'POINT (1 1)'
precisionLink to this definition

このプロパティは座標の丸め精度をコントロールします。もし None に設定すると丸めは無効になります。

Code
>>> from django.contrib.gis.geos import Point, WKTWriter
>>> pnt = Point(1.44, 1.66)
>>> wkt_w = WKTWriter()
>>> print(wkt_w.precision)
None
>>> wkt_w.write(pnt)
'POINT (1.4399999999999999 1.6599999999999999)'
>>> wkt_w.precision = 0
>>> wkt_w.write(pnt)
'POINT (1 2)'
>>> wkt_w.precision = 1
>>> wkt_w.write(pnt)
'POINT (1.4 1.7)'

脚注

設定Link to this heading

GEOS_LIBRARY_PATHLink to this heading

GEOS Cライブラリの場所を指定する文字列。通常、この設定は GEOS C ライブラリが標準以外の場所にある場合にのみ使用されます (/home/bob/lib/libgeos_c.so など)。

例外Link to this heading

exception GEOSExceptionLink to this definition

ベースとなるGEOS例外。GEOS関連のエラーを示します。