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, GEOSGeometry objects
may be used outside of a Django project/application. In other words,
no need to have DJANGO_SETTINGS_MODULE set 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"))
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¶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になります。
与えられたGML文字列から GEOSGeometry を構築します。
ジオメトリの座標をタプルで返します。
ジオメトリの次元を返します:
Point および MultiPoint に対しては 0
LineString および MultiLineString に対しては 1
Polygon および MultiPolygon に対しては 2 です。
GeometryCollection が空の場合は -1 を返します。
空ではない GeometryCollection の要素の最大次元
ジオメトリ内の点の集合が空であるかどうかを返します。
Returns a string corresponding to the type of geometry. For example:
>>> pnt = GEOSGeometry("POINT(5 23)")
>>> pnt.geom_type
'Point'
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 |
ジオメトリ内の座標の数を返します。
Returns the number of geometries in this geometry. In other words, will return 1 on anything but geometry collections.
Returns a boolean indicating whether the geometry has the Z dimension.
Returns a boolean indicating whether the geometry has the M dimension. Requires GEOS 3.12.
ジオメトリが LinearRing であるかどうかを示す真偽値を返します。
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 LineString object is not simple if it
intersects itself. Thus, LinearRing and Polygon objects
are always simple because they cannot intersect themselves, by 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
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.
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情報は含まれません。
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.hexewkb property instead).
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.
ジオメトリの GeoJSON 表現を返します。結果は完全な GeoJSON 構造ではなく、GeoJSON 構造の geometry キーの内容のみです。 GeoJSON シリアライザ も参照してください。
GEOSGeometry.json のエイリアス。
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.
GEOS ジオメトリに対応する OGRGeometry オブジェクトを返します。
Returns the WKB (Well-Known Binary) representation of this Geometry
as a Python buffer. SRID value is not included, use the
GEOSGeometry.ewkb property instead.
このジオメトリの EWKB 表現を Python バッファとして返します。これは、このジオメトリの一部であるすべての SRID 値を含む WKB 仕様の拡張です。
ジオメトリの Well-Known Text (OGC標準) を返します。
以下の空間述語 (predicate) メソッドは、別の GEOSGeometry インスタンス (other) をパラメータとして受け取り、真偽値を返します。
other.within(this) が True を返した場合に True を返します。
このジオメトリが指定したジオメトリをカバーしている場合は True を返します。
covers predicate は以下の定義と等価です:
もう一方のジオメトリのすべての点は、このジオメトリの点である。
2つのジオメトリの DE-9IM 交差行列は T*****FF*, *T****FF*, ***T**FF*, または ****T*FF* である。
どちらかのジオメトリが空の場合、False を返します。
この predicate は GEOSGeometry.contains() に似ていますが、より包括的です (つまり、より多くの場合に True を返します) 。特に、 contains() とは異なり、ジオメトリの境界と内部の点を区別しません。ほとんどの場合、 contains() よりも covers() を優先すべきです。さらに、 covers() は最適化しやすいので、 contains() よりも優れています。
2つのジオメトリの DE-9IM 交差行列が T*T******* (点と曲線、点と面積、線と面積の場合) 0******** (2つの曲線の場合) である場合に True を返します。
2つのジオメトリのDE-9IM交差行列が FF*FF**** である場合に True を返します。
2つのジオメトリの DE-9IM 交差行列が T*F**FFF* である場合に True を返します。
Returns true if the two geometries are exactly equal, up to a
specified tolerance. The tolerance value 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.
すべての次元において、すべての頂点の構造、順序、および値が同じであることをチェックすることにより、2つのジオメトリが点的に等価である場合に True を返します。 NaN 値は他の NaN 値と等しいとみなされます。GEOS 3.12が必要です。
GEOSGeometry.disjoint() が False の場合に True を返します。
2つのジオメトリの DE-9IM 交差行列が T*T***T** (2つの点または2つの曲面の場合) 1*T***T** (2つの曲線の場合) である場合に true を返します.
このジオメトリと他のジオメトリの DE-9IM 交差行列の要素が、与えられた pattern -- アルファベットから 9 文字の文字列と一致する場合に True を返します: {T, F, *, 0} の9文字の文字列。
2つのジオメトリのDE-9IM交差行列が FT*******, F**T***** または F***T**** である場合に True を返します。
2つのジオメトリの DE-9IM 交差行列が T*F**F*** である場合に True を返します。
このジオメトリからの距離が与えられた width 以下のすべての点を表す GEOSGeometry を返す。オプションの quadsegs キーワードは、1/4円の近似に使用するセグメントの数を設定します (デフォルトは8) 。
buffer() と同じですが、バッファのスタイルをカスタマイズできます。
end_cap_style には、round (1) 、flat (2) 、square (3) を指定できます。
join_style には round (1) 、mitre (2) 、bevel (3) のいずれかを指定します。
Mitre レシオ制限 (mitre_limit) は、mitre 形式の結合スタイルにのみ影響します。
このジオメトリを構成する点のうち、他の点を構成しない点を表す GEOSGeometry を返す。
与えられた距離 (float) に対する、その距離上の点 (またはもっとも近い点) を返します。この距離は、 LineString または MultiLineString のジオメトリであり、正規化されたバージョンでは、0 (始点) から 1 (終点) の値を取る float 型として距離の値を取ります。
このジオメトリと他のジオメトリが共有する点を表す GEOSGeometry を返す。
ジオメトリ (LineString または MultiLineString) の原点から、ジオメトリに投影された点 (つまり、指定された点に最も近い線の点) までの距離 (float) を返します。正規化されたバージョンは、0 (原点) と 1 (終点) の間の浮動小数点数として距離を返します。
このジオメトリと他のジオメトリのトポロジカルな関係を表す DE-9IM 交差行列 (文字列) を返します。
新しい GEOSGeometry を返します。これは Douglas-Peucker アルゴリズムを用いて、指定した許容誤差まで単純化されます。許容誤差の値が大きいほど、出力される点は少なくなります。公差が指定されない場合、デフォルトは0です。
デフォルトでは、この関数はトポロジーを保持しません。例えば、 Polygon オブジェクトは分割されたり、線に折りたたまれたり、消えたりすることがあります。 Polygon の穴ができたり消えたり、線が交差したりすることがあります。 preserve_topology=True を指定することで、結果は入力と同じ次元と要素数になります。
このジオメトリに含まれる点のうち他のジオメトリに含まれない点と、他のジオメトリに含まれる点のうちこのジオメトリに含まれない点を結合した GEOSGeometry を返す。
このジオメトリともう一方のジオメトリのすべての点を表す GEOSGeometry を返す。
新しく割り当てられた Geometry オブジェクトとして境界を返します。
Returns a Point object representing the geometric center of
the geometry. The point is not guaranteed to be on the interior
of the geometry.
このジオメトリのすべての要素の和集合を計算します。
結果は次の規約に従います:
LineString の集合を結合することは、ラインワークを完全にノード化し、分解する効果がある。
Polygon のセットを結合すると常に Polygon または MultiPolygon ジオメトリが返されます (GEOSGeometry.union() は、トポロジーの崩壊が発生した場合、次元が低いジオメトリが返される可能性がある点が異なります)。
このプロパティは、ジオメトリの面積を返します。
このプロパティは、このジオメトリの範囲を (xmin, ymin, xmax, ymax) からなる4タプルで返します。
このメソッドは、元のジオメトリのクローンである GEOSGeometry を返します。
このジオメトリと与えられた geom (別の GEOSGeometry オブジェクト) との間の最も近い点の距離を返します。
注釈
GEOSの距離計算は線形です。言い換えると、GEOSはSRIDが地理座標系を指定していても球面計算を行いません。
このジオメトリの長さを返します (例: Point の場合は 0、LineString の長さ、または Polygon の円周)。
このジオメトリの内容の GEOS PreparedGeometry を返します。 PreparedGeometry オブジェクトは、contains、intersects、covers、crosss、disjoint、overlaps、touches、および within の操作に最適化されています。詳細は 準備された (Prepared) ジオメトリ のドキュメントを参照してください。
ジオメトリの SRID に対応する SpatialReference オブジェクト、または None を返します。
与えられた座標変換パラメータ (ct) に従ってジオメトリを変換します。座標変換パラメータは、整数の SRID、空間参照の WKT 文字列、PROJ 文字列、 SpatialReference オブジェクト、 CoordTransform オブジェクトのいずれかです。デフォルトでは、ジオメトリはその場で変換され、何も返されません。しかし、 clone キーワードが設定されている場合、ジオメトリは変更されず、変換されたジオメトリのクローンが返されます。
注釈
GDALが利用できないか、ジオメトリのSRIDが None または0未満の場合に GEOSException を発生させます。 CoordTransform オブジェクトを使用して呼び出される場合、ジオメトリのSRIDには制約を与えません。
入力された頂点を失わず、有効な GEOSGeometry に変換して返します。既に有効なジオメトリの場合、そのまま返されます。これは MakeValid データベース関数に類似しています。GEOS 3.8が必要です。
このジオメトリを正規形に変換します。 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¶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([])
この LineString が閉じているかどうかを返します。
LinearRing¶LinearRing オブジェクトは、LineString オブジェクトとまったく同じ方法で構築されますが、座標は 閉じている 必要があります。つまり、最初の座標と最後の座標が同じである必要があります。例:
>>> ls = LinearRing((0, 0), (0, 1), (1, 1), (0, 0))
(0, 0) は最初で最後の座標です。もし等しくなければ、エラーが発生します。
Polygon¶Polygon objects may be instantiated by passing in parameters that
represent the rings of the polygon. The parameters must either be
LinearRing instances, or a sequence that may be used to construct
a LinearRing:
>>> 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¶MultiLineString オブジェクトは、 LineString オブジェクトを引数として渡すか、1つの LineString オブジェクトのシーケンスを渡すことでインスタンス化が可能です。
>>> ls1 = LineString((0, 0), (1, 1))
>>> ls2 = LineString((2, 2), (3, 3))
>>> mls = MultiLineString(ls1, ls2)
>>> mls = MultiLineString([ls1, ls2])
この MultiLineString のすべてのコンポーネントを結合した線を表す LineString を返します。
すべての要素が閉じられている場合にのみ True を返します。
MultiPolygon¶GeometryCollection¶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))
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¶file_h (a Python file object or a string path to the file) -- 空間データを含む入力ファイル
ファイル内の空間データに対応する GEOSGeometry
例:
>>> from django.contrib.gis.geos import fromfile
>>> g = fromfile("/home/bob/geom.wkt")
文字列内の空間データに対応する GEOSGeometry
fromstr(string, srid) は、 GEOSGeometry(string, srid) と同等です。
例:
>>> from django.contrib.gis.geos import fromstr
>>> pnt = fromstr("POINT(-90.5 29.5)", srid=4326)
Reader I/Oクラスは、 read(geom) メソッドに渡されたWKBおよび/またはWKT入力から GEOSGeometry インスタンスを返します。
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).
WKBWriter provides the most control over its output. By default it
returns OGC-compliant WKB when its write method is called. However,
it has properties that allow for the creation of EWKB, a superset of the
WKB standard that includes additional information. See the
WKBWriter.outdim documentation for more details about the dim
argument.
与えられたジオメトリの 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'
このプロパティを設定すると、ジオメトリ表現のバイトオーダーを変更できます。
バイトオーダーの値 |
説明 |
|---|---|
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'
このクラスを使用すると、ジオメトリの 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)'
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 を使用することが望まれます。
12月 03, 2025