GEOS API¶
背景¶
GEOS とは?¶
GEOS stands for Geometry Engine - Open Source, and is a C++ library, ported from the Java Topology Suite. GEOS implements the OpenGIS Simple Features for SQL spatial predicate functions and spatial operators. GEOS, now an OSGeo project, was initially developed and maintained by Refractions Research of Victoria, Canada.
特徴¶
GeoDjango は GEOS ライブラリの高レベルな Python ラッパーを実装しており、その機能には次のものがあります:
ctypesを使用して純粋に Python で実装された GEOS ジオメトリルーチンへの BSD ライセンスのインターフェイス。Loosely-coupled to GeoDjango. For example,
GEOSGeometryobjects may be used outside of a Django project/application. In other words, no need to haveDJANGO_SETTINGS_MODULEset or use a database, etc.ミュータビリティ (Mutability):
GEOSGeometryオブジェクトは変更可能です。クロスプラットフォームでテストされています。
チュートリアル¶
このセクションには、 GEOSGeometry オブジェクトの簡単な紹介とチュートリアルが含まれています。
ジオメトリを作成する¶
GEOSGeometry objects may be created in a few ways. The first is
to simply instantiate the object on some spatial input -- the following
are examples of creating the same geometry from WKT, HEX, WKB, and GeoJSON:
>>> 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
Another option is to use the constructor for the specific geometry type
that you wish to create. For example, a Point object may be
created by passing in the X and Y coordinates into its constructor:
>>> from django.contrib.gis.geos import Point
>>> pnt = Point(5, 23)
これらのコンストラクタはすべて、キーワード引数 srid を受け取ります。例えば:
>>> 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() ファクトリーメソッドがあります:
>>> from django.contrib.gis.geos import fromfile
>>> pnt = fromfile("/path/to/pnt.wkt")
>>> pnt = fromfile(open("/path/to/pnt.wkt"))
ジオメトリは Pythonic です¶
GEOSGeometry オブジェクトは 'Pythonic' (Pythonらしい) であり、要素には標準的な Python 形式を使ってアクセスしたり変更したり、イテレートしたりできます。例えば、Point の座標をイテレートできます:
>>> pnt = Point(5, 23)
>>> [coord for coord in pnt]
[5.0, 23.0]
ジオメトリオブジェクトの GEOSGeometry.coords プロパティを使用すると、ジオメトリ座標を Python のタプルで取得できます:
>>> pnt.coords
(5.0, 23.0)
You can get/set geometry components using standard Python indexing
techniques. However, what is returned depends on the geometry type
of the object. For example, indexing on a LineString
returns a coordinate tuple:
>>> 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 オブジェクト) を返します:
>>> 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のリストのように追加や変更が可能です:
>>> 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 のような演算子をサポートします:
>>> 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))
等値演算子は空間的な等価性をチェックしません
GEOSGeometry の等値演算子は、equals_exact() を使用します。equals() ではありません。つまり、比較されるジオメトリは、同じ座標、同じ位置、同じSRID を持つ必要があります。
>>> from django.contrib.gis.geos import LineString
>>> ls1 = LineString((0, 0), (1, 1))
>>> ls2 = LineString((1, 1), (0, 0))
>>> ls3 = LineString((1, 1), (0, 0), srid=4326)
>>> ls1.equals(ls2)
True
>>> ls1 == ls2
False
>>> ls3 == ls2 # different SRIDs
False
ジオメトリ・オブジェクト¶
GEOSGeometry¶
- class GEOSGeometry(geo_input, srid=None)[ソース]¶
- パラメータ:
geo_input -- ジオメトリ入力値 (文字列または
memoryview)srid (int) -- 空間参照識別子
This is the base class for all GEOS geometry objects. It initializes on the
given geo_input argument, and then assumes the proper geometry subclass
(e.g., GEOSGeometry('POINT(1 1)') will create a Point object).
パラメータ srid が与えられた場合、 geo_input が SRID を持っていない場合は、作成されたジオメトリの SRID が設定されます。パラメータ geo_input と srid で異なる SRID が指定された場合、 ValueError が発生します:
>>> 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 |
|
HEX / HEXEWKB |
|
WKB / EWKB |
|
|
GeoJSON形式では、SRIDは crs メンバーに基づいて設定されます。もし crs が指定されていない場合、SRIDはデフォルトで4326になります。
- classmethod GEOSGeometry.from_gml(gml_string)¶
与えられたGML文字列から
GEOSGeometryを構築します。
プロパティ¶
- GEOSGeometry.coords¶
ジオメトリの座標をタプルで返します。
- GEOSGeometry.dims¶
ジオメトリの次元を返します:
PointおよびMultiPointに対しては0LineStringおよびMultiLineStringに対しては1PolygonおよびMultiPolygonに対しては2です。GeometryCollectionが空の場合は-1を返します。空ではない
GeometryCollectionの要素の最大次元
- GEOSGeometry.empty¶
ジオメトリ内の点の集合が空であるかどうかを返します。
- GEOSGeometry.geom_type¶
Returns a string corresponding to the type of geometry. For example:
>>> pnt = GEOSGeometry("POINT(5 23)") >>> pnt.geom_type 'Point'
- GEOSGeometry.geom_typeid¶
Returns the GEOS geometry type identification number. The following table shows the value for each geometry type:
ジオメトリ
ID
0
1
2
3
4
5
6
7
- GEOSGeometry.num_coords¶
ジオメトリ内の座標の数を返します。
- GEOSGeometry.num_geom¶
Returns the number of geometries in this geometry. In other words, will return 1 on anything but geometry collections.
- GEOSGeometry.hasz¶
Returns a boolean indicating whether the geometry has the Z dimension.
- GEOSGeometry.hasm¶
- New in Django 6.0.
Returns a boolean indicating whether the geometry has the M dimension. Requires GEOS 3.12.
- GEOSGeometry.ring¶
ジオメトリが
LinearRingであるかどうかを示す真偽値を返します。
- GEOSGeometry.simple¶
Returns a boolean indicating whether the geometry is 'simple'. A geometry is simple if and only if it does not intersect itself (except at boundary points). For example, a
LineStringobject is not simple if it intersects itself. Thus,LinearRingandPolygonobjects are always simple because they cannot intersect themselves, by definition.
- GEOSGeometry.valid¶
ジオメトリが有効かどうかを示すブール値を返します。
- GEOSGeometry.valid_reason¶
ジオメトリが無効である理由を表す文字列を返します。
- GEOSGeometry.srid¶
Property that may be used to retrieve or set the SRID associated with the geometry. For example:
>>> pnt = Point(5, 23) >>> print(pnt.srid) None >>> pnt.srid = 4326 >>> pnt.srid 4326
出力プロパティ¶
The properties in this section export the GEOSGeometry object into
a different. This output may be in the form of a string, buffer, or even
another object.
- GEOSGeometry.ewkt¶
Returns the "extended" Well-Known Text of the geometry. This representation is specific to PostGIS and is a superset of the OGC WKT standard. [1] Essentially the SRID is prepended to the WKT representation, for example
SRID=4326;POINT(5 23).注釈
このプロパティからの出力には、PostGISがそのEWKT表現でサポートする3dm、3dz、および4d情報は含まれません。
- GEOSGeometry.hex¶
Returns the WKB of this Geometry in hexadecimal form. Please note that the SRID value is not included in this representation because it is not a part of the OGC specification (use the
GEOSGeometry.hexewkbproperty instead).
- GEOSGeometry.hexewkb¶
Returns the EWKB of this Geometry in hexadecimal form. This is an extension of the WKB specification that includes the SRID value that are a part of this geometry.
- GEOSGeometry.json¶
ジオメトリの GeoJSON 表現を返します。結果は完全な GeoJSON 構造ではなく、GeoJSON 構造の
geometryキーの内容のみです。 GeoJSON シリアライザ も参照してください。
- GEOSGeometry.geojson¶
GEOSGeometry.jsonのエイリアス。
- GEOSGeometry.kml¶
Returns a KML (Keyhole Markup Language) representation of the geometry. This should only be used for geometries with an SRID of 4326 (WGS84), but this restriction is not enforced.
- GEOSGeometry.ogr¶
GEOS ジオメトリに対応する
OGRGeometryオブジェクトを返します。
- GEOSGeometry.wkb¶
Returns the WKB (Well-Known Binary) representation of this Geometry as a Python buffer. SRID value is not included, use the
GEOSGeometry.ewkbproperty instead.
- GEOSGeometry.ewkb¶
このジオメトリの EWKB 表現を Python バッファとして返します。これは、このジオメトリの一部であるすべての SRID 値を含む WKB 仕様の拡張です。
- GEOSGeometry.wkt¶
ジオメトリの Well-Known Text (OGC標準) を返します。
空間述語メソッド (Spatial Predicate Method)¶
以下の空間述語 (predicate) メソッドは、別の GEOSGeometry インスタンス (other) をパラメータとして受け取り、真偽値を返します。
- GEOSGeometry.contains(other)¶
other.within(this)がTrueを返した場合にTrueを返します。
- GEOSGeometry.covers(other)¶
このジオメトリが指定したジオメトリをカバーしている場合は
Trueを返します。coverspredicate は以下の定義と等価です:もう一方のジオメトリのすべての点は、このジオメトリの点である。
2つのジオメトリの DE-9IM 交差行列は
T*****FF*,*T****FF*,***T**FF*, または****T*FF*である。
どちらかのジオメトリが空の場合、
Falseを返します。この predicate は
GEOSGeometry.contains()に似ていますが、より包括的です (つまり、より多くの場合にTrueを返します) 。特に、contains()とは異なり、ジオメトリの境界と内部の点を区別しません。ほとんどの場合、contains()よりもcovers()を優先すべきです。さらに、covers()は最適化しやすいので、contains()よりも優れています。
- GEOSGeometry.crosses(other)¶
2つのジオメトリの DE-9IM 交差行列が
T*T*******(点と曲線、点と面積、線と面積の場合)0********(2つの曲線の場合) である場合にTrueを返します。
- GEOSGeometry.disjoint(other)¶
2つのジオメトリのDE-9IM交差行列が
FF*FF****である場合にTrueを返します。
- GEOSGeometry.equals(other)¶
2つのジオメトリの DE-9IM 交差行列が
T*F**FFF*である場合にTrueを返します。
- GEOSGeometry.equals_exact(other, tolerance=0)¶
Returns true if the two geometries are exactly equal, up to a specified tolerance. The
tolerancevalue should be a floating point number representing the error tolerance in the comparison, e.g.,poly1.equals_exact(poly2, 0.001)will compare equality to within one thousandth of a unit.
- GEOSGeometry.equals_identical(other)¶
すべての次元において、すべての頂点の構造、順序、および値が同じであることをチェックすることにより、2つのジオメトリが点的に等価である場合に
Trueを返します。NaN値は他のNaN値と等しいとみなされます。GEOS 3.12が必要です。
- GEOSGeometry.intersects(other)¶
GEOSGeometry.disjoint()がFalseの場合にTrueを返します。
- GEOSGeometry.overlaps(other)¶
2つのジオメトリの DE-9IM 交差行列が
T*T***T**(2つの点または2つの曲面の場合)1*T***T**(2つの曲線の場合) である場合に true を返します.
- GEOSGeometry.relate_pattern(other, pattern)¶
このジオメトリと他のジオメトリの DE-9IM 交差行列の要素が、与えられた
pattern-- アルファベットから 9 文字の文字列と一致する場合にTrueを返します: {T,F,*,0} の9文字の文字列。
- GEOSGeometry.touches(other)¶
2つのジオメトリのDE-9IM交差行列が
FT*******,F**T*****またはF***T****である場合にTrueを返します。
- GEOSGeometry.within(other)¶
2つのジオメトリの DE-9IM 交差行列が
T*F**F***である場合にTrueを返します。
トポロジー的 (Topological) メソッド¶
- GEOSGeometry.buffer(width, quadsegs=8)¶
このジオメトリからの距離が与えられた
width以下のすべての点を表すGEOSGeometryを返す。オプションのquadsegsキーワードは、1/4円の近似に使用するセグメントの数を設定します (デフォルトは8) 。
- GEOSGeometry.buffer_with_style(width, quadsegs=8, end_cap_style=1, join_style=1, mitre_limit=5.0)¶
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)¶
このジオメトリを構成する点のうち、他の点を構成しない点を表す
GEOSGeometryを返す。
- GEOSGeometry.interpolate(distance)¶
- GEOSGeometry.interpolate_normalized(distance)¶
与えられた距離 (float) に対する、その距離上の点 (またはもっとも近い点) を返します。この距離は、
LineStringまたはMultiLineStringのジオメトリであり、正規化されたバージョンでは、0 (始点) から 1 (終点) の値を取る float 型として距離の値を取ります。
- GEOSGeometry.intersection(other)¶
このジオメトリと他のジオメトリが共有する点を表す
GEOSGeometryを返す。
- GEOSGeometry.project(point)¶
- GEOSGeometry.project_normalized(point)¶
ジオメトリ (
LineStringまたはMultiLineString) の原点から、ジオメトリに投影された点 (つまり、指定された点に最も近い線の点) までの距離 (float) を返します。正規化されたバージョンは、0 (原点) と 1 (終点) の間の浮動小数点数として距離を返します。
- GEOSGeometry.relate(other)¶
このジオメトリと他のジオメトリのトポロジカルな関係を表す DE-9IM 交差行列 (文字列) を返します。
- GEOSGeometry.simplify(tolerance=0.0, preserve_topology=False)¶
新しい
GEOSGeometryを返します。これは Douglas-Peucker アルゴリズムを用いて、指定した許容誤差まで単純化されます。許容誤差の値が大きいほど、出力される点は少なくなります。公差が指定されない場合、デフォルトは0です。デフォルトでは、この関数はトポロジーを保持しません。例えば、
Polygonオブジェクトは分割されたり、線に折りたたまれたり、消えたりすることがあります。Polygonの穴ができたり消えたり、線が交差したりすることがあります。preserve_topology=Trueを指定することで、結果は入力と同じ次元と要素数になります。
- GEOSGeometry.sym_difference(other)¶
このジオメトリに含まれる点のうち他のジオメトリに含まれない点と、他のジオメトリに含まれる点のうちこのジオメトリに含まれない点を結合した
GEOSGeometryを返す。
- GEOSGeometry.union(other)¶
このジオメトリともう一方のジオメトリのすべての点を表す
GEOSGeometryを返す。
トポロジー的プロパティ¶
- GEOSGeometry.boundary¶
新しく割り当てられた Geometry オブジェクトとして境界を返します。
- GEOSGeometry.centroid¶
Returns a
Pointobject representing the geometric center of the geometry. The point is not guaranteed to be on the interior of the geometry.
- GEOSGeometry.unary_union¶
このジオメトリのすべての要素の和集合を計算します。
結果は次の規約に従います:
LineStringの集合を結合することは、ラインワークを完全にノード化し、分解する効果がある。Polygonのセットを結合すると常にPolygonまたはMultiPolygonジオメトリが返されます (GEOSGeometry.union()は、トポロジーの崩壊が発生した場合、次元が低いジオメトリが返される可能性がある点が異なります)。
その他のプロパティとメソッド¶
- GEOSGeometry.area¶
このプロパティは、ジオメトリの面積を返します。
- GEOSGeometry.extent¶
このプロパティは、このジオメトリの範囲を
(xmin, ymin, xmax, ymax)からなる4タプルで返します。
- GEOSGeometry.clone()¶
このメソッドは、元のジオメトリのクローンである
GEOSGeometryを返します。
- GEOSGeometry.distance(geom)¶
このジオメトリと与えられた
geom(別のGEOSGeometryオブジェクト) との間の最も近い点の距離を返します。注釈
GEOSの距離計算は線形です。言い換えると、GEOSはSRIDが地理座標系を指定していても球面計算を行いません。
- GEOSGeometry.length¶
このジオメトリの長さを返します (例:
Pointの場合は 0、LineStringの長さ、またはPolygonの円周)。
- GEOSGeometry.prepared¶
このジオメトリの内容の GEOS
PreparedGeometryを返します。PreparedGeometryオブジェクトは、contains、intersects、covers、crosss、disjoint、overlaps、touches、および within の操作に最適化されています。詳細は 準備された (Prepared) ジオメトリ のドキュメントを参照してください。
- GEOSGeometry.srs¶
ジオメトリの SRID に対応する
SpatialReferenceオブジェクト、またはNoneを返します。
- GEOSGeometry.transform(ct, clone=False)¶
与えられた座標変換パラメータ (
ct) に従ってジオメトリを変換します。座標変換パラメータは、整数の SRID、空間参照の WKT 文字列、PROJ 文字列、SpatialReferenceオブジェクト、CoordTransformオブジェクトのいずれかです。デフォルトでは、ジオメトリはその場で変換され、何も返されません。しかし、cloneキーワードが設定されている場合、ジオメトリは変更されず、変換されたジオメトリのクローンが返されます。注釈
GDALが利用できないか、ジオメトリのSRIDが
Noneまたは0未満の場合にGEOSExceptionを発生させます。CoordTransformオブジェクトを使用して呼び出される場合、ジオメトリのSRIDには制約を与えません。
- GEOSGeometry.make_valid()¶
入力された頂点を失わず、有効な
GEOSGeometryに変換して返します。既に有効なジオメトリの場合、そのまま返されます。これはMakeValidデータベース関数に類似しています。GEOS 3.8が必要です。
- GEOSGeometry.normalize(clone=False)¶
このジオメトリを正規形に変換します。
cloneキーワードがセットされている場合、ジオメトリは変更されず、代わりにジオメトリの正規化されたクローンが返されます:>>> 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)
Point¶
LineString¶
- class LineString(*args, **kwargs)[ソース]¶
LineStringオブジェクトは、座標のシーケンスまたはPointオブジェクトを引数としてインスタンス化されます。例えば、以下は同等です:>>> ls = LineString((0, 0), (1, 1)) >>> ls = LineString(Point(0, 0), Point(1, 1))
さらに、
LineStringオブジェクトは、座標またはPointオブジェクトのシーケンスを渡すことによっても作成できます:>>> ls = LineString(((0, 0), (1, 1))) >>> ls = LineString([Point(0, 0), Point(1, 1)])
空の
LineStringオブジェクトは、引数を渡さないか空のシーケンスを渡すことでインスタンス化できます。以下は同等です:>>> ls = LineString() >>> ls = LineString([])
- closed¶
この
LineStringが閉じているかどうかを返します。
LinearRing¶
- class LinearRing(*args, **kwargs)[ソース]¶
LinearRingオブジェクトは、LineStringオブジェクトとまったく同じ方法で構築されますが、座標は 閉じている 必要があります。つまり、最初の座標と最後の座標が同じである必要があります。例:>>> ls = LinearRing((0, 0), (0, 1), (1, 1), (0, 0))
(0, 0)は最初で最後の座標です。もし等しくなければ、エラーが発生します。
Polygon¶
- class Polygon(*args, **kwargs)[ソース]¶
Polygonobjects may be instantiated by passing in parameters that represent the rings of the polygon. The parameters must either beLinearRinginstances, or a sequence that may be used to construct aLinearRing:>>> 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))
ポリゴン(多角形)の比較
ポリゴンのオブジェクトを直接 < や > と比較することも可能ですが、比較はポリゴンの LineString を通して行われるため、あまり意味がないことに注意してください (しかし、一貫性があり、素早く比較できます) 。 area プロパティで常に強制的に比較することもできます:
>>> if poly_1.area > poly_2.area:
... pass
...
ジオメトリのコレクション¶
MultiPoint¶
MultiLineString¶
- class MultiLineString(*args, **kwargs)[ソース]¶
MultiLineStringオブジェクトは、LineStringオブジェクトを引数として渡すか、1つのLineStringオブジェクトのシーケンスを渡すことでインスタンス化が可能です。>>> ls1 = LineString((0, 0), (1, 1)) >>> ls2 = LineString((2, 2), (3, 3)) >>> mls = MultiLineString(ls1, ls2) >>> mls = MultiLineString([ls1, ls2])
- merged¶
この
MultiLineStringのすべてのコンポーネントを結合した線を表すLineStringを返します。
- closed¶
すべての要素が閉じられている場合にのみ
Trueを返します。
MultiPolygon¶
GeometryCollection¶
- class GeometryCollection(*args, **kwargs)[ソース]¶
GeometryCollectionオブジェクトは、他のGEOSGeometryオブジェクトを引数として渡すか、または単一のGEOSGeometryオブジェクトのシーケンスを引数として渡すことでインスタンス化できます:>>> 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) ジオメトリ¶
In order to obtain a prepared geometry, access the
GEOSGeometry.prepared property. Once you have a PreparedGeometry
instance its spatial predicate methods, listed below, may be used with other
GEOSGeometry objects. An operation with a prepared geometry can be orders
of magnitude faster -- the more complex the geometry that is prepared, the
larger the speedup in the operation. For more information, please consult the
GEOS wiki page on prepared geometries.
例:
>>> 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
PreparedGeometry¶
ジオメトリ ファクトリ¶
- fromfile(file_h)[ソース]¶
- パラメータ:
file_h (a Python
fileobject or a string path to the file) -- 空間データを含む入力ファイル- 戻り値の型:
ファイル内の空間データに対応する
GEOSGeometry
例:
>>> from django.contrib.gis.geos import fromfile >>> g = fromfile("/home/bob/geom.wkt")
- fromstr(string, srid=None)[ソース]¶
- パラメータ:
- 戻り値の型:
文字列内の空間データに対応する
GEOSGeometry
fromstr(string, srid)は、GEOSGeometry(string, srid)と同等です。例:
>>> from django.contrib.gis.geos import fromstr >>> pnt = fromstr("POINT(-90.5 29.5)", srid=4326)
I/O オブジェクト¶
Reader オブジェクト¶
Reader I/Oクラスは、 read(geom) メソッドに渡されたWKBおよび/またはWKT入力から GEOSGeometry インスタンスを返します。
Writer オブジェクト¶
All writer objects have a write(geom) method that returns either the
WKB or WKT of the given geometry. In addition, WKBWriter objects
also have properties that may be used to change the byte order, and or
include the SRID value (in other words, EWKB).
- class WKBWriter(dim=2)[ソース]¶
WKBWriterprovides the most control over its output. By default it returns OGC-compliant WKB when itswritemethod is called. However, it has properties that allow for the creation of EWKB, a superset of the WKB standard that includes additional information. See theWKBWriter.outdimdocumentation for more details about thedimargument.与えられたジオメトリの WKB を Python の
bufferオブジェクトとして返します。例:>>> 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>
Returns WKB of the geometry in hexadecimal. Example:
>>> from django.contrib.gis.geos import Point, WKBWriter >>> pnt = Point(1, 1) >>> wkb_w = WKBWriter() >>> wkb_w.write_hex(pnt) '0101000000000000000000F03F000000000000F03F'
- byteorder¶
このプロパティを設定すると、ジオメトリ表現のバイトオーダーを変更できます。
バイトオーダーの値
説明
0
ビッグエンディアン (例: RISC システムと互換性あり)
1
リトルエンディアン (例: x86 システムと互換性あり)
例:
>>> 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'
This property may be set to change the output dimension of the geometry representation. In other words, if you have a 3D geometry then set to 3 so that the Z value is included in the WKB.
Outdim 値
説明
2
デフォルトで、2次元のWKBを出力します。
3
3D の WKB を出力します。
例:
>>> 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'
Set this property with a boolean to indicate whether the SRID of the geometry should be included with the WKB representation. Example:
>>> 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)[ソース]¶
このクラスを使用すると、ジオメトリの WKT 表現を出力できます。コンストラクタの引数の詳細については
WKBWriter.outdim,trim,precision属性を参照してください。与えられたジオメトリのWKTを返します。例:
>>> from django.contrib.gis.geos import Point, WKTWriter >>> pnt = Point(1, 1) >>> wkt_w = WKTWriter() >>> wkt_w.write(pnt) 'POINT (1.0000000000000000 1.0000000000000000)'
- outdim[ソース]¶
WKBWriter.outdimを参照。
このプロパティは、不要な小数のトリミングを有効または無効にするために使用されます。
>>> 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)'
このプロパティは座標の丸め精度をコントロールします。もし
Noneに設定すると丸めは無効になります。>>> 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)'
脚注
設定¶
GEOS_LIBRARY_PATH¶
A string specifying the location of the GEOS C library. Typically,
this setting is only used if the GEOS C library is in a non-standard
location (e.g., /home/bob/lib/libgeos_c.so).
注釈
設定は C 共有ライブラリの フル パスである必要があります。つまり、 libgeos.so ではなく libgeos_c.so を使用することが望まれます。