GeoQuerySet
(model=None)¶The spatial lookups in this section are available for GeometryField
.
For an introduction, see the spatial lookups introduction. For an overview of what lookups are compatible with a particular spatial backend, refer to the spatial lookup compatibility table.
bbcontains
¶Tersedia: PostGIS, MySQL, SpatiaLite
Tests if the geometry field’s bounding box completely contains the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__bbcontains=geom)
Backend | Setara SQL |
---|---|
PostGIS | poly ~ geom |
MySQL | MBRContains(poly, geom) |
SpatiaLite | MbrContains(poly, geom) |
bboverlaps
¶Tersedia: PostGIS, MySQL, SpatiaLite
Tests if the geometry field’s bounding box overlaps the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__bboverlaps=geom)
Backend | Setara SQL |
---|---|
PostGIS | poly && geom |
MySQL | MBROverlaps(poly, geom) |
SpatiaLite | MbrOverlaps(poly, geom) |
contained
¶Tersedia: PostGIS, MySQL, SpatiaLite
Tests if the geometry field’s bounding box is completely contained by the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__contained=geom)
Backend | Setara SQL |
---|---|
PostGIS | poly @ geom |
MySQL | MBRWithin(poly, geom) |
SpatiaLite | MbrWithin(poly, geom) |
contains
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
Tests if the geometry field spatially contains the lookup geometry.
Contoh:
Zipcode.objects.filter(poly__contains=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_Contains(poly, geom) |
Oracle | SDO_CONTAINS(poly, geom) |
MySQL | MBRContains(poly, geom) |
SpatiaLite | Contains(poly, geom) |
contains_properly
¶Tersedia: PostGIS
Returns true if the lookup geometry intersects the interior of the geometry field, but not the boundary (or exterior). [4]
Contoh:
Zipcode.objects.filter(poly__contains_properly=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_ContainsProperly(poly, geom) |
coveredby
¶Tersedia: PostGIS, Oracle
Tests if no point in the geometry field is outside the lookup geometry. [3]
Contoh:
Zipcode.objects.filter(poly__coveredby=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_CoveredBy(poly, geom) |
Oracle | SDO_COVEREDBY(poly, geom) |
covers
¶Tersedia: PostGIS, Oracle
Tests if no point in the lookup geometry is outside the geometry field. [3]
Contoh:
Zipcode.objects.filter(poly__covers=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_Covers(poly, geom) |
Oracle | SDO_COVERS(poly, geom) |
crosses
¶Tersedia: PostGIS, SpatiaLite
Tests if the geometry field spatially crosses the lookup geometry.
Contoh:
Zipcode.objects.filter(poly__crosses=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_Crosses(poly, geom) |
SpatiaLite | Crosses(poly, geom) |
disjoint
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
Tests if the geometry field is spatially disjoint from the lookup geometry.
Contoh:
Zipcode.objects.filter(poly__disjoint=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_Disjoint(poly, geom) |
Oracle | SDO_GEOM.RELATE(poly, 'DISJOINT', geom, 0.05) |
MySQL | MBRDisjoint(poly, geom) |
SpatiaLite | Disjoint(poly, geom) |
equals
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
exact
, same_as
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
intersects
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
Tests if the geometry field spatially intersects the lookup geometry.
Contoh:
Zipcode.objects.filter(poly__intersects=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_Intersects(poly, geom) |
Oracle | SDO_OVERLAPBDYINTERSECT(poly, geom) |
MySQL | MBRIntersects(poly, geom) |
SpatiaLite | Intersects(poly, geom) |
overlaps
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
relate
¶Tersedia: PostGIS, Oracle, SpatiaLite
Tests if the geometry field is spatially related to the lookup geometry by
the values given in the given pattern. This lookup requires a tuple parameter,
(geom, pattern)
; the form of pattern
will depend on the spatial backend:
On these spatial backends the intersection pattern is a string comprising
nine characters, which define intersections between the interior, boundary,
and exterior of the geometry field and the lookup geometry.
The intersection pattern matrix may only use the following characters:
1
, 2
, T
, F
, or *
. This lookup type allows users to “fine tune”
a specific geometric relationship consistent with the DE-9IM model. [1]
Contoh:
# A tuple lookup parameter is used to specify the geometry and
# the intersection pattern (the pattern here is for 'contains').
Zipcode.objects.filter(poly__relate=(geom, 'T*T***FF*'))
PostGIS SQL Setara:
SELECT ... WHERE ST_Relate(poly, geom, 'T*T***FF*')
SpatiaLite SQL setara:
SELECT ... WHERE Relate(poly, geom, 'T*T***FF*')
Here the relation pattern is comprised of at least one of the nine relation
strings: TOUCH
, OVERLAPBDYDISJOINT
, OVERLAPBDYINTERSECT
,
EQUAL
, INSIDE
, COVEREDBY
, CONTAINS
, COVERS
, ON
, and
ANYINTERACT
. Multiple strings may be combined with the logical Boolean
operator OR, for example, 'inside+touch'
. [2] The relation
strings are case-insensitive.
Contoh:
Zipcode.objects.filter(poly__relate=(geom, 'anyinteract'))
Oracle SQL setara:
SELECT ... WHERE SDO_RELATE(poly, geom, 'anyinteract')
touches
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
Tests if the geometry field spatially touches the lookup geometry.
Contoh:
Zipcode.objects.filter(poly__touches=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_Touches(poly, geom)`` |
MySQL | MBRTouches(poly, geom) |
Oracle | SDO_TOUCH(poly, geom) |
SpatiaLite | Touches(poly, geom) |
within
¶Tersedia: PostGIS, Oracle, MySQL, SpatiaLite
Tests if the geometry field is spatially within the lookup geometry.
Contoh:
Zipcode.objects.filter(poly__within=geom)
Backend | Setara SQL |
---|---|
PostGIS | ST_Within(poly, geom) |
MySQL | MBRWithin(poly, geom) |
Oracle | SDO_INSIDE(poly, geom) |
SpatiaLite | Within(poly, geom) |
left
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box is strictly to the left of the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__left=geom)
PostGIS Setara:
SELECT ... WHERE poly << geom
right
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box is strictly to the right of the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__right=geom)
PostGIS Setara:
SELECT ... WHERE poly >> geom
overlaps_left
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box overlaps or is to the left of the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__overlaps_left=geom)
PostGIS Setara:
SELECT ... WHERE poly &< geom
overlaps_right
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box overlaps or is to the right of the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__overlaps_right=geom)
PostGIS Setara:
SELECT ... WHERE poly &> geom
overlaps_above
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box overlaps or is above the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__overlaps_above=geom)
PostGIS Setara:
SELECT ... WHERE poly |&> geom
overlaps_below
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box overlaps or is below the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__overlaps_below=geom)
PostGIS Setara:
SELECT ... WHERE poly &<| geom
strictly_above
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box is strictly above the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__strictly_above=geom)
PostGIS Setara:
SELECT ... WHERE poly |>> geom
strictly_below
¶Tersedia: PostGIS
Tests if the geometry field’s bounding box is strictly below the lookup geometry’s bounding box.
Contoh:
Zipcode.objects.filter(poly__strictly_below=geom)
PostGIS Setara:
SELECT ... WHERE poly <<| geom
Tersedia: PostGIS, Oracle, SpatiaLite
For an overview on performing distance queries, please refer to the distance queries introduction.
Pencarian jarak mengambil formulir berikut:
<field>__<distance lookup>=(<geometry>, <distance value>[, 'spheroid'])
The value passed into a distance lookup is a tuple; the first two
values are mandatory, and are the geometry to calculate distances to,
and a distance value (either a number in units of the field or a
Distance
object). On every
distance lookup but dwithin
, an optional
third element, 'spheroid'
, may be included to tell GeoDjango
to use the more accurate spheroid distance calculation functions on
fields with a geodetic coordinate system (e.g., ST_Distance_Spheroid
would be used instead of ST_Distance_Sphere
). The simpler ST_Distance
function is used with projected coordinate systems.
distance_gt
¶Returns models where the distance to the geometry field from the lookup geometry is greater than the given distance value.
Contoh:
Zipcode.objects.filter(poly__distance_gt=(geom, D(m=5)))
Backend | Setara SQL |
---|---|
PostGIS | ST_Distance/ST_Distance_Sphere(poly, geom) > 5 |
Oracle | SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) > 5 |
SpatiaLite | Distance(poly, geom) > 5 |
distance_gte
¶Returns models where the distance to the geometry field from the lookup geometry is greater than or equal to the given distance value.
Contoh:
Zipcode.objects.filter(poly__distance_gte=(geom, D(m=5)))
Backend | Setara SQL |
---|---|
PostGIS | ST_Distance/ST_Distance_Sphere(poly, geom) >= 5 |
Oracle | SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) >= 5 |
SpatiaLite | Distance(poly, geom) >= 5 |
distance_lt
¶Returns models where the distance to the geometry field from the lookup geometry is less than the given distance value.
Contoh:
Zipcode.objects.filter(poly__distance_lt=(geom, D(m=5)))
Backend | Setara SQL |
---|---|
PostGIS | ST_Distance/ST_Distance_Sphere(poly, geom) < 5 |
Oracle | SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) < 5 |
SpatiaLite | Distance(poly, geom) < 5 |
distance_lte
¶Returns models where the distance to the geometry field from the lookup geometry is less than or equal to the given distance value.
Contoh:
Zipcode.objects.filter(poly__distance_lte=(geom, D(m=5)))
Backend | Setara SQL |
---|---|
PostGIS | ST_Distance/ST_Distance_Sphere(poly, geom) <= 5 |
Oracle | SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) <= 5 |
SpatiaLite | Distance(poly, geom) <= 5 |
dwithin
¶Returns models where the distance to the geometry field from the lookup
geometry are within the given distance from one another. Note that you can only
provide Distance
objects if the targeted
geometries are in a projected system. For geographic geometries, you should use
units of the geometry field (e.g. degrees for WGS84
) .
Contoh:
Zipcode.objects.filter(poly__dwithin=(geom, D(m=5)))
Backend | Setara SQL |
---|---|
PostGIS | ST_DWithin(poly, geom, 5) |
Oracle | SDO_WITHIN_DISTANCE(poly, geom, 5) |
Catatan
Pencarian tidak tersedia pada SpatiaLite.
GeoQuerySet
¶Ditinggalkan sejak versi 1.9: Using GeoQuerySet
methods is now deprecated in favor of the new
Fungsi Basisdata Geografis. Albeit a little more verbose, they are much more powerful
in how it is possible to combine them to build more complex queries.
GeoQuerySet
methods specify that a spatial operation be performed
on each spatial operation on each geographic
field in the queryset and store its output in a new attribute on the model
(which is generally the name of the GeoQuerySet
method).
There are also aggregate GeoQuerySet
methods which return a single value
instead of a queryset. This section will describe the API and availability
of every GeoQuerySet
method available in GeoDjango.
Catatan
What methods are available depend on your spatial backend. See the compatibility table for more details.
With a few exceptions, the following keyword arguments may be used with all
GeoQuerySet
methods:
Keyword Argument | Deskripsi |
---|---|
field_name |
By default, On PostGIS, the |
model_att |
By default, This keyword is required if
a method name clashes with an existing
|
Tersedia: PostGIS, Oracle, SpatiaLite
area
¶GeoQuerySet.
area
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Area
sebagai gantinya.
Returns the area of the geographic field in an area
attribute on
each element of this GeoQuerySet.
distance
¶GeoQuerySet.
distance
(geom, **kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Distance
sebagai gantinya.
This method takes a geometry as a parameter, and attaches a distance
attribute to every model in the returned queryset that contains the
distance (as a Distance
object) to the given geometry.
In the following example (taken from the GeoDjango distance tests),
the distance from the Tasmanian city of Hobart to every other
PointField
in the AustraliaCity
queryset is calculated:
>>> pnt = AustraliaCity.objects.get(name='Hobart').point
>>> for city in AustraliaCity.objects.distance(pnt): print(city.name, city.distance)
Wollongong 990071.220408 m
Shellharbour 972804.613941 m
Thirroul 1002334.36351 m
Mittagong 975691.632637 m
Batemans Bay 834342.185561 m
Canberra 598140.268959 m
Melbourne 575337.765042 m
Sydney 1056978.87363 m
Hobart 0.0 m
Adelaide 1162031.83522 m
Hillsdale 1049200.46122 m
Catatan
Because the distance
attribute is a
Distance
object, you can easily express
the value in the units of your choice. For example, city.distance.mi
is
the distance value in miles and city.distance.km
is the distance value
in kilometers. See Obyek Pengukuran for usage details and the list of
Satuan Didukung.
The following methods take no arguments, and attach geometry objects
each element of the GeoQuerySet
that is the result of relationship
function evaluated on the geometry field.
centroid
¶GeoQuerySet.
centroid
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Centroid
.
Tersedia: PostGIS, Oracle, SpatiaLite
Returns the centroid
value for the geographic field in a centroid
attribute on each element of the GeoQuerySet
.
envelope
¶GeoQuerySet.
envelope
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Envelope
.
Tersedia: PostGIS, SpatiaLite
Returns a geometry representing the bounding box of the geometry field in
an envelope
attribute on each element of the GeoQuerySet
.
point_on_surface
¶GeoQuerySet.
point_on_surface
(**kwargs)¶Ditinggalkan sejak versi 1.9: Use the PointOnSurface
function instead.
Tersedia: PostGIS, Oracle, SpatiaLite
Returns a Point geometry guaranteed to lie on the surface of the
geometry field in a point_on_surface
attribute on each element
of the queryset; otherwise sets with None.
force_rhr
¶GeoQuerySet.
force_rhr
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi ForceRHR
.
Tersedia: PostGIS
Returns a modified version of the polygon/multipolygon in which all
of the vertices follow the Right-Hand-Rule, and attaches as a
force_rhr
attribute on each element of the queryset.
reverse_geom
¶GeoQuerySet.
reverse_geom
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Reverse
.
Tersedia: PostGIS, Oracle
Reverse the coordinate order of the geometry field, and attaches as a
reverse
attribute on each element of the queryset.
scale
¶GeoQuerySet.
scale
(x, y, z=0.0, **kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Scale
sebagai gantinya.
Tersedia: PostGIS, SpatiaLite
snap_to_grid
¶GeoQuerySet.
snap_to_grid
(*args, **kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi SnapToGrid
.
Snap all points of the input geometry to the grid. How the geometry is snapped to the grid depends on how many numeric (either float, integer, or long) arguments are given.
Jumlah Argumen |
Deskripsi |
---|---|
1 | A single size to snap bot the X and Y grids to. |
2 | X and Y sizes to snap the grid to. |
4 | X, Y sizes and the corresponding X, Y origins. |
transform
¶GeoQuerySet.
transform
(srid=4326, **kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Transform
sebagai gantinya.
Tersedia: PostGIS, Oracle, SpatiaLite
The transform
method transforms the geometry field of a model to the spatial
reference system specified by the srid
parameter. If no srid
is given,
then 4326 (WGS84) is used by default.
Catatan
Unlike other GeoQuerySet
methods, transform
stores its output
“in-place”. In other words, no new attribute for the transformed
geometry is placed on the models.
Catatan
What spatial reference system an integer SRID corresponds to may depend on the spatial database used. In other words, the SRID numbers used for Oracle are not necessarily the same as those used by PostGIS.
Contoh:
>>> qs = Zipcode.objects.all().transform() # Transforms to WGS84
>>> qs = Zipcode.objects.all().transform(32140) # Transforming to "NAD83 / Texas South Central"
>>> print(qs[0].poly.srid)
32140
>>> print(qs[0].poly)
POLYGON ((234055.1698884720099159 4937796.9232223574072123 ...
Tersedia: PostGIS, Oracle, SpatiaLite
The following methods all take a geometry as a parameter and attach a geometry
to each element of the GeoQuerySet
that is the result of the operation.
difference
¶GeoQuerySet.
difference
(geom)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Difference
.
Returns the spatial difference of the geographic field with the given
geometry in a difference
attribute on each element of the
GeoQuerySet
.
intersection
¶GeoQuerySet.
intersection
(geom)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi Intersection
sebagai gantinya.
Returns the spatial intersection of the geographic field with the
given geometry in an intersection
attribute on each element of the
GeoQuerySet
.
sym_difference
¶GeoQuerySet.
sym_difference
(geom)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi SymDifference
sebagai gantinya.
Returns the symmetric difference of the geographic field with the
given geometry in a sym_difference
attribute on each element of the
GeoQuerySet
.
The following GeoQuerySet
methods will return an attribute that has the value
of the geometry field in each model converted to the requested output format.
geohash
¶GeoQuerySet.
geohash
(precision=20, **kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi GeoHash
.
Attaches a geohash
attribute to every model the queryset
containing the GeoHash representation of the geometry.
geojson
¶GeoQuerySet.
geojson
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi AsGeoJSON
.
Tersedia: PostGIS, SpatiaLite
Attaches a geojson
attribute to every model in the queryset that contains the
GeoJSON representation of the geometry.
Keyword Argument | Deskripsi |
---|---|
|
It may be used to specify the number of significant digits for the coordinates in the GeoJSON representation – the default value is 8. |
crs |
Set this to True if you want the coordinate
reference system to be included in the returned
GeoJSON. |
bbox |
Set this to True if you want the bounding box
to be included in the returned GeoJSON. |
gml
¶GeoQuerySet.
gml
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi AsGML
.
Tersedia: PostGIS, Oracle, SpatiaLite
Attaches a gml
attribute to every model in the queryset that contains the
Geographic Markup Language (GML) representation of the geometry.
Contoh:
>>> qs = Zipcode.objects.all().gml()
>>> print(qs[0].gml)
<gml:Polygon srsName="EPSG:4326"><gml:OuterBoundaryIs>-147.78711,70.245363 ... -147.78711,70.245363</gml:OuterBoundaryIs></gml:Polygon>
Keyword Argument | Deskripsi |
---|---|
|
This keyword is for PostGIS only. It may be used to specify the number of significant digits for the coordinates in the GML representation – the default value is 8. |
|
This keyword is for PostGIS only. It may be used to specify the GML version used, and may only be values of 2 or 3. The default value is 2. |
kml
¶GeoQuerySet.
kml
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi AsKML
sebagai gantinya.
Tersedia: PostGIS, SpatiaLite
Attaches a kml
attribute to every model in the queryset that contains the
Keyhole Markup Language (KML) representation of the geometry fields. It
should be noted that the contents of the KML are transformed to WGS84 if
necessary.
Contoh:
>>> qs = Zipcode.objects.all().kml()
>>> print(qs[0].kml)
<Polygon><outerBoundaryIs><LinearRing><coordinates>-103.04135,36.217596,0 ... -103.04135,36.217596,0</coordinates></LinearRing></outerBoundaryIs></Polygon>
Keyword Argument | Deskripsi |
---|---|
|
This keyword may be used to specify the number of significant digits for the coordinates in the KML representation – the default value is 8. |
svg
¶GeoQuerySet.
svg
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi AsSVG
sebagai gantinya.
Tersedia: PostGIS, SpatiaLite
Attaches a svg
attribute to every model in the queryset that contains
the Scalable Vector Graphics (SVG) path data of the geometry fields.
Keyword Argument | Deskripsi |
---|---|
relative |
If set to True , the path data will be implemented
in terms of relative moves. Defaults to False ,
meaning that absolute moves are used instead. |
|
This keyword may be used to specify the number of significant digits for the coordinates in the SVG representation – the default value is 8. |
mem_size
¶GeoQuerySet.
mem_size
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi MemSize
sebagai gantinya.
Tersedia: PostGIS
Returns the memory size (number of bytes) that the geometry field takes
in a mem_size
attribute on each element of the GeoQuerySet
.
num_geom
¶GeoQuerySet.
num_geom
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi NumGeometries
sebagai gantinya.
Tersedia: PostGIS, Oracle, SpatiaLite
Returns the number of geometries in a num_geom
attribute on
each element of the GeoQuerySet
if the geometry field is a
collection (e.g., a GEOMETRYCOLLECTION
or MULTI*
field);
otherwise sets with None
.
num_points
¶GeoQuerySet.
num_points
(**kwargs)¶Ditinggalkan sejak versi 1.9: Gunakan fungsi NumPoints
.
Tersedia: PostGIS, Oracle, SpatiaLite
Returns the number of points in the first linestring in the
geometry field in a num_points
attribute on each element of
the GeoQuerySet
; otherwise sets with None
.
Ditinggalkan sejak versi 1.8: Aggregate methods are now deprecated. Prefer using their function-based equivalents.
collect
¶GeoQuerySet.
collect
(**kwargs)¶Ditinggalkan sejak versi 1.8: Gunakan kumpulan Collect
sebagai gantinya.
Jalan pintas untuk aggregate(Collect(<field>))
.
extent
¶GeoQuerySet.
extent
(**kwargs)¶Ditinggalkan sejak versi 1.8: Gunakan kumpulan Extent
sebagai gantinya.
Jalan pintas untuk aggregate(Extent(<field>))
.
extent3d
¶GeoQuerySet.
extent3d
(**kwargs)¶Ditinggalkan sejak versi 1.8: Gunakan kumpulan Extent
sebagai gantinya.
Jalan pintas untuk aggregate(Extent3D(<field>))
.
Django provides some GIS-specific aggregate functions. For details on how to use these aggregate functions, see the topic guide on aggregation.
Keyword Argument | Deskripsi |
---|---|
tolerance |
This keyword is for Oracle only. It is for the
tolerance value used by the SDOAGGRTYPE
procedure; the Oracle documentation has more
details. |
Contoh:
>>> from django.contrib.gis.db.models import Extent, Union
>>> WorldBorder.objects.aggregate(Extent('mpoly'), Union('mpoly'))
Collect
¶Collect
(geo_field)¶Tersedia: PostGIS, Spatialite (≥ 3.0)
Returns a GEOMETRYCOLLECTION
or a MULTI
geometry object from the geometry
column. This is analogous to a simplified version of the Union
aggregate, except it can be several orders of magnitude faster than performing
a union because it simply rolls up geometries into a collection or multi object,
not caring about dissolving boundaries.
Extent
¶Extent
(geo_field)¶Tersedia: PostGIS, Oracle, Spatialite (≥3.0)
Returns the extent of all geo_field
in the QuerySet
as a four-tuple,
comprising the lower left coordinate and the upper right coordinate.
Contoh:
>>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent('poly'))
>>> print(qs['poly__extent'])
(-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820)
Extent3D
¶Extent3D
(geo_field)¶Tersedia: PostGIS
Returns the 3D extent of all geo_field
in the QuerySet
as a six-tuple,
comprising the lower left coordinate and upper right coordinate (each with x, y,
and z coordinates).
Contoh:
>>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent3D('poly'))
>>> print(qs['poly__extent3d'])
(-96.8016128540039, 29.7633724212646, 0, -95.3631439208984, 32.782058715820, 0)
MakeLine
¶MakeLine
(geo_field)¶Tersedia: PostGIS
Returns a LineString
constructed from the point field geometries in the
QuerySet
. Currently, ordering the queryset has no effect.
Contoh:
>>> print(City.objects.filter(name__in=('Houston', 'Dallas')
... ).aggregate(MakeLine('poly'))['poly__makeline']
LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018)
Union
¶Union
(geo_field)¶Tersedia: PostGIS, Oracle, SpatiaLite
This method returns a GEOSGeometry
object
comprising the union of every geometry in the queryset. Please note that use of
Union
is processor intensive and may take a significant amount of time on
large querysets.
Catatan
If the computation time for using this method is too expensive, consider
using Collect
instead.
Contoh:
>>> u = Zipcode.objects.aggregate(Union(poly)) # This may take a long time.
>>> u = Zipcode.objects.filter(poly__within=bbox).aggregate(Union(poly)) # A more sensible approach.
Catatan kaki
[1] | See OpenGIS Simple Feature Specification For SQL, at Ch. 2.1.13.2, p. 2-13 (The Dimensionally Extended Nine-Intersection Model). |
[2] | Lihat SDO_RELATE documentation, dari Bab 11 dari Panduan dan Manual Pengguna Oracle Spatial. |
[3] | (1, 2) For an explanation of this routine, read Quirks of the “Contains” Spatial Predicate by Martin Davis (a PostGIS developer). |
[4] | Refer to the PostGIS ST_ContainsProperly documentation for more details. |
Agt 01, 2016