GEOS APILink to this heading
背景Link to this heading
GEOS とは?Link to this heading
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.
特徴Link to this heading
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オブジェクトは変更可能です。クロスプラットフォームでテストされています。
チュートリアルLink to this heading
このセクションには、 GEOSGeometry オブジェクトの簡単な紹介とチュートリアルが含まれています。
ジオメトリを作成するLink to this heading
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 ですLink to this heading
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))
ジオメトリ・オブジェクト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
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)Link to this definition
与えられたGML文字列から
GEOSGeometryを構築します。
プロパティLink to this heading
- GEOSGeometry.coordsLink to this definition
ジオメトリの座標をタプルで返します。
- GEOSGeometry.dimsLink to this definition
ジオメトリの次元を返します:
PointおよびMultiPointに対しては0LineStringおよびMultiLineStringに対しては1PolygonおよびMultiPolygonに対しては2です。GeometryCollectionが空の場合は-1を返します。空ではない
GeometryCollectionの要素の最大次元
- GEOSGeometry.emptyLink to this definition
ジオメトリ内の点の集合が空であるかどうかを返します。
- GEOSGeometry.geom_typeLink to this definition
Returns a string corresponding to the type of geometry. For example:
>>> pnt = GEOSGeometry("POINT(5 23)") >>> pnt.geom_type 'Point'
- GEOSGeometry.geom_typeidLink to this definition
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_coordsLink to this definition
ジオメトリ内の座標の数を返します。
- GEOSGeometry.num_geomLink to this definition
Returns the number of geometries in this geometry. In other words, will return 1 on anything but geometry collections.
- GEOSGeometry.haszLink to this definition
Returns a boolean indicating whether the geometry has the Z dimension.
- GEOSGeometry.hasmLink to this definition
-
Returns a boolean indicating whether the geometry has the M dimension. Requires GEOS 3.12.
- GEOSGeometry.ringLink to this definition
ジオメトリが
LinearRingであるかどうかを示す真偽値を返します。
- GEOSGeometry.simpleLink to this definition
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.validLink to this definition
ジオメトリが有効かどうかを示すブール値を返します。
- GEOSGeometry.valid_reasonLink to this definition
ジオメトリが無効である理由を表す文字列を返します。
- GEOSGeometry.sridLink to this definition
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
出力プロパティLink to this heading
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.ewktLink to this definition
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).
- GEOSGeometry.hexLink to this definition
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.hexewkbLink to this definition
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.jsonLink to this definition
ジオメトリの GeoJSON 表現を返します。結果は完全な GeoJSON 構造ではなく、GeoJSON 構造の
geometryキーの内容のみです。 GeoJSON シリアライザ も参照してください。
- GEOSGeometry.geojsonLink to this definition
GEOSGeometry.jsonのエイリアス。
- GEOSGeometry.kmlLink to this definition
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.ogrLink to this definition
GEOS ジオメトリに対応する
OGRGeometryオブジェクトを返します。
- GEOSGeometry.wkbLink to this definition
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.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を返します。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)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
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)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.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.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
Returns a
Pointobject representing the geometric center of the geometry. The point is not guaranteed to be on the interior of the geometry.
- GEOSGeometry.convex_hullLink to this definition
ジオメトリ内のすべての点を含む最小の
Polygonを返す。
- GEOSGeometry.envelopeLink to this definition
- 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キーワードがセットされている場合、ジオメトリは変更されず、代わりにジオメトリの正規化されたクローンが返されます:>>> 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 つのシーケンス座標でインスタンス化されたりします。例えば、以下は同等です:>>> pnt = Point(5, 23) >>> pnt = Point([5, 23])空の
Pointオブジェクトを引数なしまたは空のシーケンスを渡すことでインスタンス化できます。以下は同等です:>>> pnt = Point() >>> pnt = Point([])
LineStringLink to this heading
- class LineString(*args, **kwargs)Link to this definition
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([])- closedLink to this definition
この
LineStringが閉じているかどうかを返します。
LinearRingLink to this heading
- class LinearRing(*args, **kwargs)Link to this definition
LinearRingオブジェクトは、LineStringオブジェクトとまったく同じ方法で構築されますが、座標は 閉じている 必要があります。つまり、最初の座標と最後の座標が同じである必要があります。例:>>> 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
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))- 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オブジェクトのシーケンスを渡すことでインスタンス化できます。>>> 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オブジェクトのシーケンスを渡すことでインスタンス化が可能です。>>> 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オブジェクトのシーケンスを渡すことでインスタンス化できます。>>> 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オブジェクトのシーケンスを引数として渡すことでインスタンス化できます:>>> 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
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
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
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)Link to this definition
- パラメータ:
- 戻り値の型:
文字列内の空間データに対応する
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 オブジェクトLink to this heading
Reader オブジェクトLink to this heading
Reader I/Oクラスは、 read(geom) メソッドに渡されたWKBおよび/またはWKT入力から GEOSGeometry インスタンスを返します。
- class WKBReaderLink to this definition
例:
>>> from django.contrib.gis.geos import WKBReader >>> wkb_r = WKBReader() >>> wkb_r.read("0101000000000000000000F03F000000000000F03F") <Point object at 0x103a88910>
- class WKTReaderLink to this definition
例:
>>> 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
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)Link to this definition
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.- write(geom)Link to this definition
与えられたジオメトリの 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>- write_hex(geom)Link to this definition
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'- byteorderLink to this definition
このプロパティを設定すると、ジオメトリ表現のバイトオーダーを変更できます。
バイトオーダーの値
説明
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'- outdimLink to this definition
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)Link to this definition
このクラスを使用すると、ジオメトリの WKT 表現を出力できます。コンストラクタの引数の詳細については
WKBWriter.outdim,trim,precision属性を参照してください。- write(geom)Link to this definition
与えられたジオメトリの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)'- outdimLink to this definition
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)'- precisionLink to this definition
このプロパティは座標の丸め精度をコントロールします。もし
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)'
脚注
設定Link to this heading
GEOS_LIBRARY_PATHLink to this heading
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 を使用することが望まれます。
例外Link to this heading
- exception GEOSExceptionLink to this definition
ベースとなるGEOS例外。GEOS関連のエラーを示します。