API GEOSLink to this heading
Latar belakangLink to this heading
Apa itu 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.
FiturLink to this heading
GeoDjango menerapkan pembungkus Python tingkat-tinggi untuk pustaka GEOS, fitur-fiturnya termasuk:
A BSD-licensed interface to the GEOS geometry routines, implemented purely in Python using
ctypes.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.Berubah-ubah: obyek
GEOSGeometrymungkin dirubah.Cross-platform and tested; compatible with Windows, Linux, Solaris, and macOS platforms.
TutorialLink to this heading
Bagian ini mengandung perkenalan singkat dan tutorial menggunakan obyek GEOSGeometry.
Membuat GeometriLink 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(buffer('\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x007@'))
>>> 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)
All these constructors take the keyword argument srid. For example:
>>> 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)
Finally, there is the fromfile() factory method which returns a
GEOSGeometry object from a file:
>>> from django.contrib.gis.geos import fromfile
>>> pnt = fromfile('/path/to/pnt.wkt')
>>> pnt = fromfile(open('/path/to/pnt.wkt'))
Geometries are PythonicLink to this heading
GEOSGeometry objects are 'Pythonic', in other words components may
be accessed, modified, and iterated over using standard Python conventions.
For example, you can iterate over the coordinates in a Point:
>>> pnt = Point(5, 23)
>>> [coord for coord in pnt]
[5.0, 23.0]
With any geometry object, the GEOSGeometry.coords property
may be used to get the geometry coordinates as a Python tuple:
>>> 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)
Whereas indexing on a Polygon will return the ring
(a LinearRing object) corresponding to the index:
>>> 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)
In addition, coordinates/components of the geometry may added or modified, just like a Python list:
>>> 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))
Geometries support set-like operators:
>>> 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))
Obyek GeometriLink to this heading
GEOSGeometryLink to this heading
- class GEOSGeometry(geo_input, srid=None)Link to this definition
- Parameter:
geo_input -- Geometry input value (string or buffer)
srid (int) -- spatial reference identifier
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).
The following input formats, along with their corresponding Python types, are accepted:
Bentuk |
Jenis Masukan |
|---|---|
WKT / EWKT |
|
HEX / HEXEWKB |
|
WKB / EWKB |
|
GeoJSON |
|
- classmethod GEOSGeometry.from_gml(gml_string)Link to this definition
New in Django 1.11
Constructs a
GEOSGeometryfrom the given GML string.
PropertiesLink to this heading
- GEOSGeometry.coordsLink to this definition
Mengembalikan kordinat dari geometri sebagai tuple.
- GEOSGeometry.dimsLink to this definition
Mengembalikan dimensi dari geometri:
0untukPointdanMultiPoint1untukLineStringdanMultiLineString2untukPolygondanMultiPolygon-1untukGeometryCollectionkosongthe maximum dimension of its elements for non-empty
GeometryCollections
- GEOSGeometry.emptyLink to this definition
Returns whether or not the set of points in the geometry is empty.
- 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:
Geometri
ID
0
1
2
3
4
5
6
7
- GEOSGeometry.num_coordsLink to this definition
Mengembalikan angka dari kordinat di geometri.
- 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 is three-dimensional.
- GEOSGeometry.ringLink to this definition
Returns a boolean indicating whether the geometry is a
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 do cannot intersect themselves, by definition.
- GEOSGeometry.validLink to this definition
Returns a boolean indicating whether the geometry is valid.
- GEOSGeometry.valid_reasonLink to this definition
Mengembalikan deretan kalimat menggambarkan alasan mengapa geometri sah.
- 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
Output PropertiesLink 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).Catatan
The output from this property does not include the 3dm, 3dz, and 4d information that PostGIS supports in its EWKT representations.
- 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
Returns the GeoJSON representation of the geometry. Note that the result is not a complete GeoJSON structure but only the
geometrykey content of a GeoJSON structure. See also Penserial GeoJSON.
- GEOSGeometry.geojsonLink to this definition
Nama lain dari
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
Mengembalikan obyek
OGRGeometryterkait pada permintaan pada geometri GEOS.
- 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
Return the EWKB representation of this Geometry as a Python buffer. This is an extension of the WKB specification that includes any SRID value that are a part of this geometry.
- GEOSGeometry.wktLink to this definition
Returns the Well-Known Text of the geometry (an OGC standard).
Changed in Django 1.10
Non-significant zeros are stripped from the output.
Spatial Predicate MethodsLink to this heading
All of the following spatial predicate methods take another
GEOSGeometry instance (other) as a parameter, and
return a boolean.
- GEOSGeometry.contains(other)Link to this definition
Returns
Trueifother.within(this)returnsTrue.
- GEOSGeometry.covers(other)Link to this definition
New in Django 1.10
Mengembalikan
Truejika geometri mencangkup geometri tertentu.The
coverspredicate has the following equivalent definitions:Every point of the other geometry is a point of this geometry.
The DE-9IM Intersection Matrix for the two geometries is
T*****FF*,*T****FF*,***T**FF*, or****T*FF*.
Jika salah satu geometri adalah kosong, kembalikan
False.This predicate is similar to
GEOSGeometry.contains(), but is more inclusive (i.e. returnsTruefor more cases). In particular, unlikecontains()it does not distinguish between points in the boundary and in the interior of geometries. For most situations,covers()should be preferred tocontains(). As an added benefit,covers()is more amenable to optimization and hence should outperformcontains().
- GEOSGeometry.crosses(other)Link to this definition
Returns
Trueif the DE-9IM intersection matrix for the two Geometries isT*T******(for a point and a curve,a point and an area or a line and an area)0********(for two curves).
- GEOSGeometry.disjoint(other)Link to this definition
Returns
Trueif the DE-9IM intersection matrix for the two geometries isFF*FF****.
- GEOSGeometry.equals(other)Link to this definition
Returns
Trueif the DE-9IM intersection matrix for the two geometries isT*F**FFF*.
- 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.intersects(other)Link to this definition
Mengembalikan
TruejikaGEOSGeometry.disjoint()adalahFalse.
- GEOSGeometry.overlaps(other)Link to this definition
Returns true if the DE-9IM intersection matrix for the two geometries is
T*T***T**(for two points or two surfaces)1*T***T**(for two curves).
- GEOSGeometry.relate_pattern(other, pattern)Link to this definition
Returns
Trueif the elements in the DE-9IM intersection matrix for this geometry and the other matches the givenpattern-- a string of nine characters from the alphabet: {T,F,*,0}.
- GEOSGeometry.touches(other)Link to this definition
Returns
Trueif the DE-9IM intersection matrix for the two geometries isFT*******,F**T*****orF***T****.
- GEOSGeometry.within(other)Link to this definition
Returns
Trueif the DE-9IM intersection matrix for the two geometries isT*F**F***.
Topological MethodsLink to this heading
- GEOSGeometry.buffer(width, quadsegs=8)Link to this definition
Returns a
GEOSGeometrythat represents all points whose distance from this geometry is less than or equal to the givenwidth. The optionalquadsegskeyword sets the number of segments used to approximate a quarter circle (defaults is 8).
- GEOSGeometry.difference(other)Link to this definition
Returns a
GEOSGeometryrepresenting the points making up this geometry that do not make up other.
- GEOSGeometry.interpolate(distance)Link to this definition
- GEOSGeometry.interpolate_normalized(distance)Link to this definition
Given a distance (float), returns the point (or closest point) within the geometry (
LineStringorMultiLineString) at that distance. The normalized version takes the distance as a float between 0 (origin) and 1 (endpoint).Membalikkan dari
GEOSGeometry.project().
- GEOSGeometry.intersection(other)Link to this definition
Returns a
GEOSGeometryrepresenting the points shared by this geometry and other.
- GEOSGeometry.project(point)Link to this definition
- GEOSGeometry.project_normalized(point)Link to this definition
Returns the distance (float) from the origin of the geometry (
LineStringorMultiLineString) to the point projected on the geometry (that is to a point of the line the closest to the given point). The normalized version returns the distance as a float between 0 (origin) and 1 (endpoint).Membalikkan dari
GEOSGeometry.interpolate().
- GEOSGeometry.relate(other)Link to this definition
Returns the DE-9IM intersection matrix (a string) representing the topological relationship between this geometry and the other.
- GEOSGeometry.simplify(tolerance=0.0, preserve_topology=False)Link to this definition
Returns a new
GEOSGeometry, simplified to the specified tolerance using the Douglas-Peucker algorithm. A higher tolerance value implies fewer points in the output. If no tolerance is provided, it defaults to 0.By default, this function does not preserve topology. For example,
Polygonobjects can be split, be collapsed into lines, or disappear.Polygonholes can be created or disappear, and lines may cross. By specifyingpreserve_topology=True, the result will have the same dimension and number of components as the input; this is significantly slower, however.
- GEOSGeometry.sym_difference(other)Link to this definition
Returns a
GEOSGeometrycombining the points in this geometry not in other, and the points in other not in this geometry.
- GEOSGeometry.union(other)Link to this definition
Returns a
GEOSGeometryrepresenting all the points in this geometry and the other.
Topological PropertiesLink to this heading
- GEOSGeometry.boundaryLink to this definition
Returns the boundary as a newly allocated Geometry object.
- 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
Returns the smallest
Polygonthat contains all the points in the geometry.
- GEOSGeometry.envelopeLink to this definition
Returns a
Polygonthat represents the bounding envelope of this geometry. Note that it can also return aPointif the input geometry is a point.
- GEOSGeometry.point_on_surfaceLink to this definition
Computes and returns a
Pointguaranteed to be on the interior of this geometry.
- GEOSGeometry.unary_unionLink to this definition
New in Django 1.10
Computes the union of all the elements of this geometry.
The result obeys the following contract:
Unioning a set of
LineStrings has the effect of fully noding and dissolving the linework.Unioning a set of
Polygons will always return aPolygonorMultiPolygongeometry (unlikeGEOSGeometry.union(), which may return geometries of lower dimension if a topology collapse occurs).
Other Properties & MethodsLink to this heading
- GEOSGeometry.areaLink to this definition
This property returns the area of the Geometry.
- GEOSGeometry.extentLink to this definition
This property returns the extent of this geometry as a 4-tuple, consisting of
(xmin, ymin, xmax, ymax).
- GEOSGeometry.clone()Link to this definition
This method returns a
GEOSGeometrythat is a clone of the original.
- GEOSGeometry.distance(geom)Link to this definition
Returns the distance between the closest points on this geometry and the given
geom(anotherGEOSGeometryobject).Catatan
GEOS distance calculations are linear -- in other words, GEOS does not perform a spherical calculation even if the SRID specifies a geographic coordinate system.
- GEOSGeometry.lengthLink to this definition
Returns the length of this geometry (e.g., 0 for a
Point, the length of aLineString, or the circumference of aPolygon).
- GEOSGeometry.preparedLink to this definition
Returns a GEOS
PreparedGeometryfor the contents of this geometry.PreparedGeometryobjects are optimized for the contains, intersects, covers, crosses, disjoint, overlaps, touches and within operations. Refer to the Prepared Geometry documentation for more information.
- GEOSGeometry.srsLink to this definition
Returns a
SpatialReferenceobject corresponding to the SRID of the geometry orNone.
- GEOSGeometry.transform(ct, clone=False)Link to this definition
Transforms the geometry according to the given coordinate transformation parameter (
ct), which may be an integer SRID, spatial reference WKT string, a PROJ.4 string, aSpatialReferenceobject, or aCoordTransformobject. By default, the geometry is transformed in-place and nothing is returned. However if theclonekeyword is set, then the geometry is not modified and a transformed clone of the geometry is returned instead.Catatan
Raises
GEOSExceptionif GDAL is not available or if the geometry's SRID isNoneor less than 0. It doesn't impose any constraints on the geometry's SRID if called with aCoordTransformobject.Changed in Django 1.10
In previous versions, it required the geometry's SRID to be a positive integer even if it was called with a
CoordTransformobject.
- GEOSGeometry.normalize()Link to this definition
Converts this geometry to canonical form:
>>> 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
Pointobjects are instantiated using arguments that represent the component coordinates of the point or with a single sequence coordinates. For example, the following are equivalent:>>> pnt = Point(5, 23) >>> pnt = Point([5, 23])Empty
Pointobjects may be instantiated by passing no arguments or an empty sequence. The following are equivalent:>>> pnt = Point() >>> pnt = Point([])Changed in Django 1.10
Di versi sebelumnya, sebuah
Pointkosong tidak dapat diinstasiasikan.
LineStringLink to this heading
- class LineString(*args, **kwargs)Link to this definition
LineStringobjects are instantiated using arguments that are either a sequence of coordinates orPointobjects. For example, the following are equivalent:>>> ls = LineString((0, 0), (1, 1)) >>> ls = LineString(Point(0, 0), Point(1, 1))In addition,
LineStringobjects may also be created by passing in a single sequence of coordinate orPointobjects:>>> ls = LineString( ((0, 0), (1, 1)) ) >>> ls = LineString( [Point(0, 0), Point(1, 1)] )Empty
LineStringobjects may be instantiated by passing no arguments or an empty sequence. The following are equivalent:>>> ls = LineString() >>> ls = LineString([])Changed in Django 1.10
Di versi sebelumnya, sebuah
LineStringkosong tidak dapat diinstasiasikan.- closedLink to this definition
New in Django 1.10
Mengembalikan apakah atau tidak
LineStringini ditutup.
LinearRingLink to this heading
- class LinearRing(*args, **kwargs)Link to this definition
LinearRingobjects are constructed in the exact same way asLineStringobjects, however the coordinates must be closed, in other words, the first coordinates must be the same as the last coordinates. For example:>>> ls = LinearRing((0, 0), (0, 1), (1, 1), (0, 0))Perhatikan bahwa
(0, 0)adalah kordinat pertama dan terakhir -- jika mereka tidak setara, sebuah kesalahan akan dimunculkan.
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))Changed in Django 1.10
Di versi sebelumnya, sebuah
Polygonkosong tidak dapat diinstasiasikan.- classmethod from_bbox(bbox)Link to this definition
Mengembalikan sebuah obyek poligon dari kotak-dikelilingi diberikan, 4-tuple meliputi
(xmin, ymin, xmax, ymax).
- num_interior_ringsLink to this definition
Mengembalikan sejumlah lingkaran interior di geometri ini.
Membandingkan Polygon
Note that it is possible to compare Polygon objects directly with <
or >, but as the comparison is made through Polygon's
LineString, it does not mean much (but is consistent and quick).
You can always force the comparison with the area
property:
>>> if poly_1.area > poly_2.area:
>>> pass
Kumpulan GeometriLink to this heading
MultiPointLink to this heading
- class MultiPoint(*args, **kwargs)Link to this definition
MultiPointobjects may be instantiated by passing inPointobjects as arguments, or a single sequence ofPointobjects:>>> mp = MultiPoint(Point(0, 0), Point(1, 1)) >>> mp = MultiPoint( (Point(0, 0), Point(1, 1)) )Changed in Django 1.10
Di versi sebelumnya, sebuah
MultiPointkosong tidak dapat diinstasiasikan.
MultiLineStringLink to this heading
- class MultiLineString(*args, **kwargs)Link to this definition
MultiLineStringobjects may be instantiated by passing inLineStringobjects as arguments, or a single sequence ofLineStringobjects:>>> ls1 = LineString((0, 0), (1, 1)) >>> ls2 = LineString((2, 2), (3, 3)) >>> mls = MultiLineString(ls1, ls2) >>> mls = MultiLineString([ls1, ls2])Changed in Django 1.10
Di versi sebelumnya, sebuah
MultiLineStringkosong tidak dapat diinstasiasikan.- mergedLink to this definition
Mengembalikan sebuah
LineStringmewakili baris menggabungkan semua komponen diMultiLineStringini.
- closedLink to this definition
New in Django 1.10
Mengembalikan
Truejika dan hanya jika semua unsur ditutup. Membutuhkan GEOS 3.5.
MultiPolygonLink to this heading
- class MultiPolygon(*args, **kwargs)Link to this definition
MultiPolygonobjects may be instantiated by passingPolygonobjects as arguments, or a single sequence ofPolygonobjects:>>> 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])Changed in Django 1.10
Di versi sebelumnya, sebuah
MultiPolygonkosong tidak dapat diinstasiasikan.- cascaded_unionLink to this definition
Deprecated since Django 1.10
Ditinggalkan sejak versi 1.10: Gunakan sifat
GEOSGeometry.unary_unionsebagai gantinya.Returns a
Polygonthat is the union of all of the component polygons in this collection. The algorithm employed is significantly more efficient (faster) than trying to union the geometries together individually. [2]
GeometryCollectionLink to this heading
- class GeometryCollection(*args, **kwargs)Link to this definition
GeometryCollectionobjects may be instantiated by passing in otherGEOSGeometryas arguments, or a single sequence ofGEOSGeometryobjects:>>> 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))Changed in Django 1.10
Di versi sebelumnya, sebuah
GeometryCollectionkosong tidak dapat diinstasiasikan.
Prepared GeometryLink to this heading
In order to obtain a prepared geometry, just 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.
Sebagai contoh:
>>> 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
Semua metode pada
PreparedGeometrymengambil sebuah argumenother, yang harus berupa instanceGEOSGeometry.- 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
Pabrik GeometriLink to this heading
- fromfile(file_h)Link to this definition
- Parameter:
file_h (a Python
fileobject or a string path to the file) -- masukan berkas yang mengandung data spasial- Jenis Kembalian:
GEOSGeometryberhubungan ke data spasial dalam berkas
Contoh:
>>> from django.contrib.gis.geos import fromfile >>> g = fromfile('/home/bob/geom.wkt')
- fromstr(string, srid=None)Link to this definition
- Parameter:
- Jenis Kembalian:
GEOSGeometryterkait pada data spasial di deretan karakter
fromstr(string, srid)setara denganGEOSGeometry(string, srid).Contoh:
>>> from django.contrib.gis.geos import fromstr >>> pnt = fromstr('POINT(-90.5 29.5)', srid=4326)
Obyek I/OLink to this heading
Obyek PembacaLink to this heading
The reader I/O classes simply return a GEOSGeometry instance from the
WKB and/or WKT input given to their read(geom) method.
- class WKBReaderLink to this definition
Contoh:
>>> from django.contrib.gis.geos import WKBReader >>> wkb_r = WKBReader() >>> wkb_r.read('0101000000000000000000F03F000000000000F03F') <Point object at 0x103a88910>
- class WKTReaderLink to this definition
Contoh:
>>> from django.contrib.gis.geos import WKTReader >>> wkt_r = WKTReader() >>> wkt_r.read('POINT(1 1)') <Point object at 0x103a88b50>
Obyek PenulisLink 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.Changed in Django 1.10
Kemampuan meloloskan argumen
dimke pembangun telah ditambahkan.- write(geom)Link to this definition
Returns the WKB of the given geometry as a Python
bufferobject. Example:>>> 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
Mengembalikan WKB dari geometri di heksadesimal. Contoh:
>>> 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
This property may be set to change the byte-order of the geometry representation.
Nilai Byteorder
Deskripsi
0
Big Endian (sebagai contoh, cocok dengan sistem RISC)
1
Little Endian (sebagai contoh, cocok dengan sistem x86)
Contoh:
>>> 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.
Nilai Outdim
Deskripsi
2
Awalan, keluaran 2D WKB.
3
Keluaran 3D WKB.
Contoh:
>>> 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
This class allows outputting the WKT representation of a geometry. See the
WKBWriter.outdim,trim, andprecisionattributes for details about the constructor arguments.Changed in Django 1.10
Kemampuan melewatkan argumen
dim,trim, danprecisionke pembangun telah ditambahkan.- write(geom)Link to this definition
Mengembalikan WKT dari geometri diberikan. Contoh:
>>> 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
Lihat
WKBWriter.outdim.
New in Django 1.10
Sifat ini digunakan untuk mengadakan atau meniadakan memangkas dari desimal yang tidak diperlukan.
>>> 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
New in Django 1.10
Sifat ini mengendalikan ketelitian pembulatan dari kordinat; jika disetel menjadi
Nonepembulatan adalah ditiadakan.>>> 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)'
Catatan kaki
See PostGIS EWKB, EWKT and Canonical Forms, PostGIS documentation at Ch. 4.1.2.
Untuk informasi lebih, baca penempatan blog Paul Ramsey tentang (Much) Faster Unions in PostGIS 1.4 dan penempatan blog Martin Davis pada Fast polygon merging in JTS using Cascaded Union.
PengaturanLink to this heading
GEOS_LIBRARY_PATHLink to this heading
Sebuah string menentukan tempat dari pustaka C GEOS. Khususnya, pengaturan ini hanya digunakan jika pustaka C GEOS adalah di tempat bukan-standar (sebagai contoh, /home/bob/lib/libgeos_c.so).
Catatan
Pengaturan harus berupa jalur penuh pada pustaka berbagi C; dengan kata lain anda ingin menggunakan libgeos_c.so, bukan libgeos.so.
PengecualianLink to this heading
- exception GEOSExceptionLink to this definition
Pengecualian GEOS dasar, menunjukkan kesalahan terkait-GEOS.