“Django/docs/2.2.x/ref/contrib/gis/geoquerysets”的版本间差异

来自菜鸟教程
Django/docs/2.2.x/ref/contrib/gis/geoquerysets
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:GIS QuerySet API 参考 — Django 文档}}
 
<div id="gis-queryset-api-reference" class="section">
 
<div id="gis-queryset-api-reference" class="section">
  
= GIS QuerySet API Reference =
+
= GIS QuerySet API 参考 =
  
 
<div id="spatial-lookups" class="section">
 
<div id="spatial-lookups" class="section">
  
 
<span id="id1"></span>
 
<span id="id1"></span>
== Spatial Lookups ==
+
== 空间查找 ==
  
The spatial lookups in this section are available for [[../model-api#django.contrib.gis.db.models|<code>GeometryField</code>]]
+
本节中的空间查找可用于 [[../model-api#django.contrib.gis.db.models|GeometryField]] [[../model-api#django.contrib.gis.db.models|RasterField]]
and [[../model-api#django.contrib.gis.db.models|<code>RasterField</code>]].
 
  
For an introduction, see the [[../db-api#spatial-lookups-intro|<span class="std std-ref">spatial lookups introduction</span>]]. For an overview of what lookups are
+
有关介绍,请参阅 [[../db-api#spatial-lookups-intro|空间查找介绍]] 。 有关哪些查找与特定空间后端兼容的概述,请参阅 [[../db-api#spatial-lookup-compatibility|空间查找兼容性表]]
compatible with a particular spatial backend, refer to the
 
[[../db-api#spatial-lookup-compatibility|<span class="std std-ref">spatial lookup compatibility table</span>]].
 
  
 
<div id="lookups-with-rasters" class="section">
 
<div id="lookups-with-rasters" class="section">
  
=== Lookups with rasters ===
+
=== 使用栅格查找 ===
  
All examples in the reference below are given for geometry fields and inputs,
+
下面参考中的所有示例都是针对几何字段和输入给出的,但查找可以以相同的方式用于两侧的栅格。 每当查找不支持栅格输入时,输入会在必要时使用 [https://postgis.net/docs/RT_ST_Polygon.html ST_Polygon] 函数自动转换为几何图形。 另请参阅 [[../db-api#spatial-lookup-raster|对栅格查找的介绍]]
but the lookups can be used the same way with rasters on both sides. Whenever
 
a lookup doesn't support raster input, the input is automatically
 
converted to a geometry where necessary using the [https://postgis.net/docs/RT_ST_Polygon.html ST_Polygon] function. See also the
 
[[../db-api#spatial-lookup-raster|<span class="std std-ref">introduction to raster lookups</span>]].
 
  
The database operators used by the lookups can be divided into three categories:
+
查找使用的数据库运算符可以分为三类:
  
* Native raster support <code>N</code>: the operator accepts rasters natively on both sides of the lookup, and raster input can be mixed with geometry inputs.
+
* 原生栅格支持 <code>N</code>:运算符在查找的两侧原生接受栅格,并且栅格输入可以与几何输入混合。
* Bilateral raster support <code>B</code>: the operator supports rasters only if both sides of the lookup receive raster inputs. Raster data is automatically converted to geometries for mixed lookups.
+
* 双边栅格支持 <code>B</code>:仅当查找的两侧都接收栅格输入时,运算符才支持栅格。 栅格数据会自动转换为几何图形以进行混合查找。
* Geometry conversion support <code>C</code>. The lookup does not have native raster support, all raster data is automatically converted to geometries.
+
* 几何转换支持 <code>C</code>。 查找没有原生栅格支持,所有栅格数据都会自动转换为几何图形。
  
The examples below show the SQL equivalent for the lookups in the different
+
下面的示例显示了在不同类型的栅格支持中查找的 SQL 等效项。 相同的模式适用于所有空间查找。
types of raster support. The same pattern applies to all spatial lookups.
 
  
 
{|
 
{|
!width="4%"| Case
+
!width="4%"| 案件
!width="34%"| Lookup
+
!width="34%"| 查找
!width="62%"| SQL Equivalent
+
!width="62%"| SQL 等价于:
 
|-
 
|-
 
| N, B
 
| N, B
第80行: 第73行:
 
|}
 
|}
  
Spatial lookups with rasters are only supported for PostGIS backends
+
PostGIS 后端(在本节中称为 PGRaster)支持使用栅格进行空间查找。
(denominated as PGRaster in this section).
 
  
  
第87行: 第79行:
 
<div id="bbcontains" class="section">
 
<div id="bbcontains" class="section">
  
<span id="std-fieldlookup-bbcontains"></span><span id="std:fieldlookup-bbcontains"></span>
+
=== bbcontains ===
=== <code>bbcontains</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Contain.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Contain.html PostGIS]、MySQL、SpatiaLite、PGRaster(原生)
MySQL, SpatiaLite, PGRaster (Native)
 
  
Tests if the geometry or raster field's bounding box completely contains the
+
测试几何或栅格字段的边界框是否完全包含查找几何的边界框。
lookup geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第102行: 第91行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__bbcontains=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__bbcontains=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第108行: 第97行:
 
</div>
 
</div>
 
{|
 
{|
!width="27%"| Backend
+
!width="27%"| 后端
!width="73%"| SQL Equivalent
+
!width="73%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第125行: 第114行:
 
<div id="bboverlaps" class="section">
 
<div id="bboverlaps" class="section">
  
<span id="std-fieldlookup-bboverlaps"></span><span id="std:fieldlookup-bboverlaps"></span>
+
=== bboverlaps ===
=== <code>bboverlaps</code> ===
 
  
''Availability'': [https://postgis.net/docs/geometry_overlaps.html PostGIS],
+
''可用性''[https://postgis.net/docs/geometry_overlaps.html PostGIS]、MySQL、SpatiaLite、PGRaster(原生)
MySQL, SpatiaLite, PGRaster (Native)
 
  
Tests if the geometry field's bounding box overlaps the lookup geometry's
+
测试几何字段的边界框是否与查找几何的边界框重叠。
bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第140行: 第126行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__bboverlaps=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__bboverlaps=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第146行: 第132行:
 
</div>
 
</div>
 
{|
 
{|
!width="27%"| Backend
+
!width="27%"| 后端
!width="73%"| SQL Equivalent
+
!width="73%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第163行: 第149行:
 
<div id="contained" class="section">
 
<div id="contained" class="section">
  
<span id="std-fieldlookup-contained"></span><span id="std:fieldlookup-contained"></span>
+
=== contained ===
=== <code>contained</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Contained.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Contained.html PostGIS]、MySQL、SpatiaLite、PGRaster(原生)
MySQL, SpatiaLite, PGRaster (Native)
 
  
Tests if the geometry field's bounding box is completely contained by the
+
测试几何字段的边界框是否完全包含在查找几何的边界框内。
lookup geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第178行: 第161行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__contained=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__contained=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第184行: 第167行:
 
</div>
 
</div>
 
{|
 
{|
!width="28%"| Backend
+
!width="28%"| 后端
!width="72%"| SQL Equivalent
+
!width="72%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第201行: 第184行:
 
<div id="contains" class="section">
 
<div id="contains" class="section">
  
<span id="std-fieldlookup-gis-contains"></span><span id="std:fieldlookup-gis-contains"></span>
+
=== contains ===
=== <code>contains</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Contains.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Contains.html PostGIS]、Oracle、MySQL、SpatiaLite、PGRaster(双边)
Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
 
  
Tests if the geometry field spatially contains the lookup geometry.
+
测试几何字段在空间上是否包含查找几何。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第215行: 第196行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__contains=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__contains=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第221行: 第202行:
 
</div>
 
</div>
 
{|
 
{|
!width="26%"| Backend
+
!width="26%"| 后端
!width="74%"| SQL Equivalent
+
!width="74%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第241行: 第222行:
 
<div id="contains-properly" class="section">
 
<div id="contains-properly" class="section">
  
<span id="std-fieldlookup-contains_properly"></span><span id="std:fieldlookup-contains_properly"></span>
+
=== contains_properly ===
=== <code>contains_properly</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_ContainsProperly.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_ContainsProperly.html PostGIS],PGRaster(双边)
PGRaster (Bilateral)
 
  
Returns true if the lookup geometry intersects the interior of the
+
如果查找几何与几何字段的内部相交,但不与边界(或外部)相交,则返回 true。
geometry field, but not the boundary (or exterior).
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第256行: 第234行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__contains_properly=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__contains_properly=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第262行: 第240行:
 
</div>
 
</div>
 
{|
 
{|
!width="22%"| Backend
+
!width="22%"| 后端
!width="78%"| SQL Equivalent
+
!width="78%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第273行: 第251行:
 
<div id="coveredby" class="section">
 
<div id="coveredby" class="section">
  
<span id="std-fieldlookup-coveredby"></span><span id="std:fieldlookup-coveredby"></span>
+
=== coveredby ===
=== <code>coveredby</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_CoveredBy.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_CoveredBy.html PostGIS]、Oracle、PGRaster(双边)、SpatiaLite
Oracle, PGRaster (Bilateral), SpatiaLite
 
  
Tests if no point in the geometry field is outside the lookup geometry.
+
测试几何字段中是否没有点位于查找几何之外。 [[#fncovers|3]]
[[#fncovers|3]]
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第288行: 第263行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__coveredby=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__coveredby=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第295行: 第270行:
 
<div class="versionchanged">
 
<div class="versionchanged">
  
SpatiaLite support was added.
+
<span class="versionmodified changed"> 2.2 版更改:添加了 </span> SpatiaLite 支持。
  
  
 
</div>
 
</div>
 
{|
 
{|
!width="26%"| Backend
+
!width="26%"| 后端
!width="74%"| SQL Equivalent
+
!width="74%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第317行: 第292行:
 
<div id="covers" class="section">
 
<div id="covers" class="section">
  
<span id="std-fieldlookup-covers"></span><span id="std:fieldlookup-covers"></span>
+
=== covers ===
=== <code>covers</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Covers.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Covers.html PostGIS]、Oracle、PGRaster(双边)、SpatiaLite
Oracle, PGRaster (Bilateral), SpatiaLite
 
  
Tests if no point in the lookup geometry is outside the geometry field.
+
测试查找几何中是否没有点位于几何字段之外。 [[#fncovers|3]]
[[#fncovers|3]]
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第332行: 第304行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__covers=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__covers=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第339行: 第311行:
 
<div class="versionchanged">
 
<div class="versionchanged">
  
SpatiaLite support was added.
+
<span class="versionmodified changed"> 2.2 版更改:添加了 </span> SpatiaLite 支持。
  
  
 
</div>
 
</div>
 
{|
 
{|
!width="28%"| Backend
+
!width="28%"| 后端
!width="72%"| SQL Equivalent
+
!width="72%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第361行: 第333行:
 
<div id="crosses" class="section">
 
<div id="crosses" class="section">
  
<span id="std-fieldlookup-crosses"></span><span id="std:fieldlookup-crosses"></span>
+
=== crosses ===
=== <code>crosses</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Crosses.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Crosses.html PostGIS]、SpatiaLite、PGRaster(转换)
SpatiaLite, PGRaster (Conversion)
 
  
Tests if the geometry field spatially crosses the lookup geometry.
+
测试几何字段是否与查找几何在空间上交叉。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第375行: 第345行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__crosses=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__crosses=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第381行: 第351行:
 
</div>
 
</div>
 
{|
 
{|
!width="28%"| Backend
+
!width="28%"| 后端
!width="72%"| SQL Equivalent
+
!width="72%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第395行: 第365行:
 
<div id="disjoint" class="section">
 
<div id="disjoint" class="section">
  
<span id="std-fieldlookup-disjoint"></span><span id="std:fieldlookup-disjoint"></span>
+
=== disjoint ===
=== <code>disjoint</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Disjoint.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Disjoint.html PostGIS]、Oracle、MySQL、SpatiaLite、PGRaster(双边)
Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
 
  
Tests if the geometry field is spatially disjoint from the lookup geometry.
+
测试几何字段是否与查找几何在空间上不相交。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第409行: 第377行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__disjoint=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__disjoint=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第415行: 第383行:
 
</div>
 
</div>
 
{|
 
{|
!width="17%"| Backend
+
!width="17%"| 后端
!width="83%"| SQL Equivalent
+
!width="83%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第435行: 第403行:
 
<div id="equals" class="section">
 
<div id="equals" class="section">
  
<span id="std-fieldlookup-equals"></span><span id="std:fieldlookup-equals"></span>
+
=== equals ===
=== <code>equals</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Equals.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Equals.html PostGIS]、Oracle、MySQL、SpatiaLite、PGRaster(转换)
Oracle, MySQL, SpatiaLite, PGRaster (Conversion)
 
  
Tests if the geometry field is spatially equal to the lookup geometry.
+
测试几何字段在空间上是否等于查找几何。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第449行: 第415行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__equals=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__equals=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第455行: 第421行:
 
</div>
 
</div>
 
{|
 
{|
!width="17%"| Backend
+
!width="17%"| 后端
!width="83%"| SQL Equivalent
+
!width="83%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第471行: 第437行:
 
|}
 
|}
  
<span id="std-fieldlookup-exact-noindex" class="target"><span id="std:fieldlookup-exact :noindex:"></span></span>
 
  
 
</div>
 
</div>
 
<div id="exact-same-as" class="section">
 
<div id="exact-same-as" class="section">
  
<span id="std-fieldlookup-same_as"></span><span id="std:fieldlookup-same_as"></span>
+
=== exact、same_as ===
=== <code>exact</code>, <code>same_as</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Same.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Same.html PostGIS]、Oracle、MySQL、SpatiaLite、PGRaster(双边)
Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
 
  
Tests if the geometry field is &quot;equal&quot; to the lookup geometry. On Oracle and
+
测试几何字段是否“等于”查找几何。 在 Oracle SpatiaLite 上它测试空间相等性,而在 MySQL PostGIS 上它测试边界框的相等性。
SpatiaLite it tests spatial equality, while on MySQL and PostGIS it tests
 
equality of bounding boxes.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第492行: 第453行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第498行: 第459行:
 
</div>
 
</div>
 
{|
 
{|
!width="17%"| Backend
+
!width="17%"| 后端
!width="83%"| SQL Equivalent
+
!width="83%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第518行: 第479行:
 
<div id="intersects" class="section">
 
<div id="intersects" class="section">
  
<span id="std-fieldlookup-intersects"></span><span id="std:fieldlookup-intersects"></span>
+
=== intersects ===
=== <code>intersects</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Intersects.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Intersects.html PostGIS]、Oracle、MySQL、SpatiaLite、PGRaster(双边)
Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
 
  
Tests if the geometry field spatially intersects the lookup geometry.
+
测试几何字段是否与查找几何在空间上相交。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第532行: 第491行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__intersects=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__intersects=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第538行: 第497行:
 
</div>
 
</div>
 
{|
 
{|
!width="17%"| Backend
+
!width="17%"| 后端
!width="83%"| SQL Equivalent
+
!width="83%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第558行: 第517行:
 
<div id="isvalid" class="section">
 
<div id="isvalid" class="section">
  
<span id="std-fieldlookup-isvalid"></span><span id="std:fieldlookup-isvalid"></span>
+
=== isvalid ===
=== <code>isvalid</code> ===
 
  
''Availability'': MySQL (≥ 5.7.5), [https://postgis.net/docs/ST_IsValid.html PostGIS], Oracle, SpatiaLite
+
''可用性'':MySQL (≥ 5.7.5)[https://postgis.net/docs/ST_IsValid.html PostGIS]、Oracle、SpatiaLite
  
Tests if the geometry is valid.
+
测试几何图形是否有效。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第571行: 第529行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__isvalid=True)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__isvalid=True)</syntaxhighlight>
  
 
</div>
 
</div>
第577行: 第535行:
 
</div>
 
</div>
 
{|
 
{|
!width="28%"| Backend
+
!width="28%"| 后端
!width="71%"| SQL Equivalent
+
!width="71%"| SQL 等价于:
 
|-
 
|-
 
| MySQL, PostGIS, SpatiaLite
 
| MySQL, PostGIS, SpatiaLite
第591行: 第549行:
 
<div id="overlaps" class="section">
 
<div id="overlaps" class="section">
  
<span id="std-fieldlookup-overlaps"></span><span id="std:fieldlookup-overlaps"></span>
+
=== overlaps ===
=== <code>overlaps</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Overlaps.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Overlaps.html PostGIS]、Oracle、MySQL、SpatiaLite、PGRaster(双边)
Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
 
  
Tests if the geometry field spatially overlaps the lookup geometry.
+
测试几何字段是否与查找几何在空间上重叠。
  
 
{|
 
{|
!width="26%"| Backend
+
!width="26%"| 后端
!width="74%"| SQL Equivalent
+
!width="74%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第620行: 第576行:
 
<div id="relate" class="section">
 
<div id="relate" class="section">
  
<span id="std-fieldlookup-relate"></span><span id="std:fieldlookup-relate"></span>
+
=== relate ===
=== <code>relate</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Relate.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Relate.html PostGIS]、Oracle、SpatiaLite、PGRaster(转换)
Oracle, SpatiaLite, PGRaster (Conversion)
 
  
Tests if the geometry field is spatially related to the lookup geometry by
+
通过给定模式中给定的值测试几何字段是否与查找几何在空间上相关。 这个查找需要一个元组参数,<code>(geom, pattern)</code><code>pattern</code> 的形式将取决于空间后端:
the values given in the given pattern. This lookup requires a tuple parameter,
 
<code>(geom, pattern)</code>; the form of <code>pattern</code> will depend on the spatial backend:
 
  
 
<div id="postgis-spatialite" class="section">
 
<div id="postgis-spatialite" class="section">
  
==== PostGIS &amp; SpatiaLite ====
+
==== PostGIS SpatiaLite ====
  
On these spatial backends the intersection pattern is a string comprising
+
在这些空间后端上,相交模式是一个由九个字符组成的字符串,用于定义几何字段与查找几何的内部、边界和外部之间的交集。 交集模式矩阵只能使用以下字符:<code>1</code><code>2</code><code>T</code><code>F</code><code>*</code>。 这种查找类型允许用户“微调”与 DE-9IM 模型一致的特定几何关系。 [[#fnde9im|1]]
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:
 
<code>1</code>, <code>2</code>, <code>T</code>, <code>F</code>, or <code>*</code>. This lookup type allows users to &quot;fine tune&quot;
 
a specific geometric relationship consistent with the DE-9IM model. [[#fnde9im|1]]
 
  
Geometry example:
+
几何示例:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第647行: 第594行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre># A tuple lookup parameter is used to specify the geometry and
+
<syntaxhighlight lang="python"># A tuple lookup parameter is used to specify the geometry and
 
# the intersection pattern (the pattern here is for 'contains').
 
# the intersection pattern (the pattern here is for 'contains').
Zipcode.objects.filter(poly__relate=(geom, 'T*T***FF*'))</pre>
+
Zipcode.objects.filter(poly__relate=(geom, 'T*T***FF*'))</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS SQL equivalent:
+
PostGIS SQL 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第660行: 第607行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE ST_Relate(poly, geom, 'T*T***FF*')</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE ST_Relate(poly, geom, 'T*T***FF*')</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
SpatiaLite SQL equivalent:
+
SpatiaLite SQL 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第671行: 第618行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE Relate(poly, geom, 'T*T***FF*')</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE Relate(poly, geom, 'T*T***FF*')</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
Raster example:
+
光栅示例:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第682行: 第629行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__relate=(rast, 1, 'T*T***FF*'))
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__relate=(rast, 1, 'T*T***FF*'))
Zipcode.objects.filter(rast__2__relate=(rast, 1, 'T*T***FF*'))</pre>
+
Zipcode.objects.filter(rast__2__relate=(rast, 1, 'T*T***FF*'))</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS SQL equivalent:
+
PostGIS SQL 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第694行: 第641行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE ST_Relate(poly, ST_Polygon(rast, 1), 'T*T***FF*')
+
<syntaxhighlight lang="python">SELECT ... WHERE ST_Relate(poly, ST_Polygon(rast, 1), 'T*T***FF*')
SELECT ... WHERE ST_Relate(ST_Polygon(rast, 2), ST_Polygon(rast, 1), 'T*T***FF*')</pre>
+
SELECT ... WHERE ST_Relate(ST_Polygon(rast, 2), ST_Polygon(rast, 1), 'T*T***FF*')</syntaxhighlight>
  
 
</div>
 
</div>
第706行: 第653行:
 
==== Oracle ====
 
==== Oracle ====
  
Here the relation pattern is comprised of at least one of the nine relation
+
这里的关系模式由以下九个关系串中的至少一个组成:<code>TOUCH</code><code>OVERLAPBDYDISJOINT</code><code>OVERLAPBDYINTERSECT</code><code>EQUAL</code><code>INSIDE</code> <code>COVEREDBY</code><code>CONTAINS</code><code>COVERS</code><code>ON</code> <code>ANYINTERACT</code>。 多个字符串可以用逻辑布尔运算符 OR 组合,例如,<code>'inside+touch'</code>[[#fnsdorelate|2]] 关系字符串不区分大小写。
strings: <code>TOUCH</code>, <code>OVERLAPBDYDISJOINT</code>, <code>OVERLAPBDYINTERSECT</code>,
 
<code>EQUAL</code>, <code>INSIDE</code>, <code>COVEREDBY</code>, <code>CONTAINS</code>, <code>COVERS</code>, <code>ON</code>, and
 
<code>ANYINTERACT</code>. Multiple strings may be combined with the logical Boolean
 
operator OR, for example, <code>'inside+touch'</code>. [[#fnsdorelate|2]] The relation
 
strings are case-insensitive.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第719行: 第661行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__relate=(geom, 'anyinteract'))</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__relate=(geom, 'anyinteract'))</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
Oracle SQL equivalent:
+
Oracle SQL 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第730行: 第672行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE SDO_RELATE(poly, geom, 'anyinteract')</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE SDO_RELATE(poly, geom, 'anyinteract')</syntaxhighlight>
  
 
</div>
 
</div>
第741行: 第683行:
 
<div id="touches" class="section">
 
<div id="touches" class="section">
  
<span id="std-fieldlookup-touches"></span><span id="std:fieldlookup-touches"></span>
+
=== touches ===
=== <code>touches</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Touches.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Touches.html PostGIS]、Oracle、MySQL、SpatiaLite
Oracle, MySQL, SpatiaLite
 
  
Tests if the geometry field spatially touches the lookup geometry.
+
测试几何字段是否在空间上接触查找几何。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第755行: 第695行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__touches=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__touches=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第761行: 第701行:
 
</div>
 
</div>
 
{|
 
{|
!width="28%"| Backend
+
!width="28%"| 后端
!width="72%"| SQL Equivalent
+
!width="72%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第781行: 第721行:
 
<div id="within" class="section">
 
<div id="within" class="section">
  
<span id="std-fieldlookup-within"></span><span id="std:fieldlookup-within"></span>
+
=== within ===
=== <code>within</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Within.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Within.html PostGIS]、Oracle、MySQL、SpatiaLite、PGRaster(双边)
Oracle, MySQL, SpatiaLite, PGRaster (Bilateral)
 
  
Tests if the geometry field is spatially within the lookup geometry.
+
测试几何字段是否在空间上查找几何。
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第795行: 第733行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__within=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__within=geom)</syntaxhighlight>
  
 
</div>
 
</div>
第801行: 第739行:
 
</div>
 
</div>
 
{|
 
{|
!width="28%"| Backend
+
!width="28%"| 后端
!width="72%"| SQL Equivalent
+
!width="72%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第821行: 第759行:
 
<div id="left" class="section">
 
<div id="left" class="section">
  
<span id="std-fieldlookup-left"></span><span id="std:fieldlookup-left"></span>
+
=== left ===
=== <code>left</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Left.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Left.html PostGIS],PGRaster(转换)
PGRaster (Conversion)
 
  
Tests if the geometry field's bounding box is strictly to the left of the
+
测试几何字段的边界框是否严格位于查找几何的边界框的左侧。
lookup geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第836行: 第771行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__left=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__left=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第847行: 第782行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly &lt;&lt; geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly << geom</syntaxhighlight>
  
 
</div>
 
</div>
第856行: 第791行:
 
<div id="right" class="section">
 
<div id="right" class="section">
  
<span id="std-fieldlookup-right"></span><span id="std:fieldlookup-right"></span>
+
=== right ===
=== <code>right</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Right.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Right.html PostGIS],PGRaster(转换)
PGRaster (Conversion)
 
  
Tests if the geometry field's bounding box is strictly to the right of the
+
测试几何字段的边界框是否严格位于查找几何的边界框的右侧。
lookup geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第871行: 第803行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__right=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__right=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第882行: 第814行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly &gt;&gt; geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly >> geom</syntaxhighlight>
  
 
</div>
 
</div>
第891行: 第823行:
 
<div id="overlaps-left" class="section">
 
<div id="overlaps-left" class="section">
  
<span id="std-fieldlookup-overlaps_left"></span><span id="std:fieldlookup-overlaps_left"></span>
+
=== overlaps_left ===
=== <code>overlaps_left</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Overleft.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Overleft.html PostGIS],PGRaster(双边)
PGRaster (Bilateral)
 
  
Tests if the geometry field's bounding box overlaps or is to the left of the lookup
+
测试几何字段的边界框是否与查找几何的边界框重叠或位于其左侧。
geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第906行: 第835行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__overlaps_left=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__overlaps_left=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第917行: 第846行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly &amp;&lt; geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly &< geom</syntaxhighlight>
  
 
</div>
 
</div>
第926行: 第855行:
 
<div id="overlaps-right" class="section">
 
<div id="overlaps-right" class="section">
  
<span id="std-fieldlookup-overlaps_right"></span><span id="std:fieldlookup-overlaps_right"></span>
+
=== overlaps_right ===
=== <code>overlaps_right</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Overright.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Overright.html PostGIS],PGRaster(双边)
PGRaster (Bilateral)
 
  
Tests if the geometry field's bounding box overlaps or is to the right of the lookup
+
测试几何字段的边界框是否与查找几何的边界框重叠或位于其右侧。
geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第941行: 第867行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__overlaps_right=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__overlaps_right=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第952行: 第878行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly &amp;&gt; geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly &> geom</syntaxhighlight>
  
 
</div>
 
</div>
第961行: 第887行:
 
<div id="overlaps-above" class="section">
 
<div id="overlaps-above" class="section">
  
<span id="std-fieldlookup-overlaps_above"></span><span id="std:fieldlookup-overlaps_above"></span>
+
=== overlaps_above ===
=== <code>overlaps_above</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Overabove.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Overabove.html PostGIS],PGRaster(转换)
PGRaster (Conversion)
 
  
Tests if the geometry field's bounding box overlaps or is above the lookup
+
测试几何字段的边界框是否与查找几何的边界框重叠或位于其上方。
geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第976行: 第899行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__overlaps_above=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__overlaps_above=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第987行: 第910行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly |&amp;&gt; geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly |&> geom</syntaxhighlight>
  
 
</div>
 
</div>
第996行: 第919行:
 
<div id="overlaps-below" class="section">
 
<div id="overlaps-below" class="section">
  
<span id="std-fieldlookup-overlaps_below"></span><span id="std:fieldlookup-overlaps_below"></span>
+
=== overlaps_below ===
=== <code>overlaps_below</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Overbelow.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Overbelow.html PostGIS],PGRaster(转换)
PGRaster (Conversion)
 
  
Tests if the geometry field's bounding box overlaps or is below the lookup
+
测试几何字段的边界框是否重叠或低于查找几何的边界框。
geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,011行: 第931行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__overlaps_below=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__overlaps_below=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,022行: 第942行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly &amp;&lt;| geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly &<| geom</syntaxhighlight>
  
 
</div>
 
</div>
第1,031行: 第951行:
 
<div id="strictly-above" class="section">
 
<div id="strictly-above" class="section">
  
<span id="std-fieldlookup-strictly_above"></span><span id="std:fieldlookup-strictly_above"></span>
+
=== strictly_above ===
=== <code>strictly_above</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Above.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Above.html PostGIS],PGRaster(转换)
PGRaster (Conversion)
 
  
Tests if the geometry field's bounding box is strictly above the lookup
+
测试几何字段的边界框是否严格高于查找几何的边界框。
geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,046行: 第963行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__strictly_above=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__strictly_above=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,057行: 第974行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly |&gt;&gt; geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly |>> geom</syntaxhighlight>
  
 
</div>
 
</div>
第1,066行: 第983行:
 
<div id="strictly-below" class="section">
 
<div id="strictly-below" class="section">
  
<span id="std-fieldlookup-strictly_below"></span><span id="std:fieldlookup-strictly_below"></span>
+
=== strictly_below ===
=== <code>strictly_below</code> ===
 
  
''Availability'': [https://postgis.net/docs/ST_Geometry_Below.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Geometry_Below.html PostGIS],PGRaster(转换)
PGRaster (Conversion)
 
  
Tests if the geometry field's bounding box is strictly below the lookup
+
测试几何字段的边界框是否严格低于查找几何的边界框。
geometry's bounding box.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,081行: 第995行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__strictly_below=geom)</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__strictly_below=geom)</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
PostGIS equivalent:
+
PostGIS 等效项:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,092行: 第1,006行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>SELECT ... WHERE poly &lt;&lt;| geom</pre>
+
<syntaxhighlight lang="python">SELECT ... WHERE poly <<| geom</syntaxhighlight>
  
 
</div>
 
</div>
第1,104行: 第1,018行:
  
 
<span id="id6"></span>
 
<span id="id6"></span>
== Distance Lookups ==
+
== 距离查找 ==
  
''Availability'': PostGIS, Oracle, MySQL, SpatiaLite, PGRaster (Native)
+
''可用性'':PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(原生)
  
For an overview on performing distance queries, please refer to
+
有关执行距离查询的概述,请参阅 [[../db-api#distance-queries|距离查询介绍]]
the [[../db-api#distance-queries|<span class="std std-ref">distance queries introduction</span>]].
 
  
Distance lookups take the following form:
+
距离查找采用以下形式:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,117行: 第1,030行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&lt;field&gt;__&lt;distance lookup&gt;=(&lt;geometry/raster&gt;, &lt;distance value&gt;[, 'spheroid'])
+
<syntaxhighlight lang="python"><field>__<distance lookup>=(<geometry/raster>, <distance value>[, 'spheroid'])
&lt;field&gt;__&lt;distance lookup&gt;=(&lt;raster&gt;, &lt;band_index&gt;, &lt;distance value&gt;[, 'spheroid'])
+
<field>__<distance lookup>=(<raster>, <band_index>, <distance value>[, 'spheroid'])
&lt;field&gt;__&lt;band_index&gt;__&lt;distance lookup&gt;=(&lt;raster&gt;, &lt;band_index&gt;, &lt;distance value&gt;[, 'spheroid'])</pre>
+
<field>__<band_index>__<distance lookup>=(<raster>, <band_index>, <distance value>[, 'spheroid'])</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
The value passed into a distance lookup is a tuple; the first two
+
传递给距离查找的值是一个元组; 前两个值是强制性的,是计算距离的几何图形和一个距离值(以字段为单位的数字,一个[[../measure#django.contrib.gis.measure|距离]]对象,或查询表达式 )。 要将波段索引传递给查找,请使用 3 元组,其中第二个条目是波段索引。
values are mandatory, and are the geometry to calculate distances to,
 
and a distance value (either a number in units of the field, a
 
[[../measure#django.contrib.gis.measure|<code>Distance</code>]] object, or a query expression
 
&lt;ref/models/expressions&gt;). To pass a band index to the lookup, use a 3-tuple
 
where the second entry is the band index.
 
  
On every distance lookup except [[#std-fieldlookup-dwithin|<code>dwithin</code>]], an optional element,
+
在除 [[#id7|:lookup:`dwithin`]] 之外的每个距离查找中,可以包含一个可选元素 <code>'spheroid'</code>,以便在具有大地坐标系的字段上使用更准确的球体距离计算函数。
<code>'spheroid'</code>, may be included to use the more accurate spheroid distance
 
calculation functions on fields with a geodetic coordinate system.
 
  
On PostgreSQL, the <code>'spheroid'</code> option uses [https://postgis.net/docs/ST_Distance_Spheroid.html ST_DistanceSpheroid] instead of
+
PostgreSQL 上,<code>'spheroid'</code> 选项使用 [https://postgis.net/docs/ST_Distance_Spheroid.html ST_DistanceSpheroid] 而不是 [https://postgis.net/docs/ST_DistanceSphere.html ST_DistanceSphere]。 更简单的 [https://postgis.net/docs/ST_Distance.html ST_Distance] 函数用于投影坐标系。 栅格被转换为几何图形以进行基于球体的查找。
[https://postgis.net/docs/ST_DistanceSphere.html ST_DistanceSphere]. The
 
simpler [https://postgis.net/docs/ST_Distance.html ST_Distance] function is
 
used with projected coordinate systems. Rasters are converted to geometries for
 
spheroid based lookups.
 
  
 
<div id="distance-gt" class="section">
 
<div id="distance-gt" class="section">
  
<span id="std-fieldlookup-distance_gt"></span><span id="std:fieldlookup-distance_gt"></span>
+
=== distance_gt ===
=== <code>distance_gt</code> ===
 
  
Returns models where the distance to the geometry field from the lookup
+
返回从查找几何到几何字段的距离大于给定距离值的模型。
geometry is greater than the given distance value.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,155行: 第1,055行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__distance_gt=(geom, D(m=5)))</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__distance_gt=(geom, D(m=5)))</syntaxhighlight>
  
 
</div>
 
</div>
第1,161行: 第1,061行:
 
</div>
 
</div>
 
{|
 
{|
!width="17%"| Backend
+
!width="17%"| 后端
!width="83%"| SQL Equivalent
+
!width="83%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第1,181行: 第1,081行:
 
<div id="distance-gte" class="section">
 
<div id="distance-gte" class="section">
  
<span id="std-fieldlookup-distance_gte"></span><span id="std:fieldlookup-distance_gte"></span>
+
=== distance_gte ===
=== <code>distance_gte</code> ===
 
  
Returns models where the distance to the geometry field from the lookup
+
返回从查找几何到几何字段的距离大于或等于给定距离值的模型。
geometry is greater than or equal to the given distance value.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,193行: 第1,091行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__distance_gte=(geom, D(m=5)))</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__distance_gte=(geom, D(m=5)))</syntaxhighlight>
  
 
</div>
 
</div>
第1,199行: 第1,097行:
 
</div>
 
</div>
 
{|
 
{|
!width="16%"| Backend
+
!width="16%"| 后端
!width="84%"| SQL Equivalent
+
!width="84%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第1,219行: 第1,117行:
 
<div id="distance-lt" class="section">
 
<div id="distance-lt" class="section">
  
<span id="std-fieldlookup-distance_lt"></span><span id="std:fieldlookup-distance_lt"></span>
+
=== distance_lt ===
=== <code>distance_lt</code> ===
 
  
Returns models where the distance to the geometry field from the lookup
+
返回从查找几何到几何字段的距离小于给定距离值的模型。
geometry is less than the given distance value.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,231行: 第1,127行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__distance_lt=(geom, D(m=5)))</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__distance_lt=(geom, D(m=5)))</syntaxhighlight>
  
 
</div>
 
</div>
第1,237行: 第1,133行:
 
</div>
 
</div>
 
{|
 
{|
!width="17%"| Backend
+
!width="17%"| 后端
!width="83%"| SQL Equivalent
+
!width="83%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第1,257行: 第1,153行:
 
<div id="distance-lte" class="section">
 
<div id="distance-lte" class="section">
  
<span id="std-fieldlookup-distance_lte"></span><span id="std:fieldlookup-distance_lte"></span>
+
=== distance_lte ===
=== <code>distance_lte</code> ===
 
  
Returns models where the distance to the geometry field from the lookup
+
返回从查找几何到几何字段的距离小于或等于给定距离值的模型。
geometry is less than or equal to the given distance value.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,269行: 第1,163行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__distance_lte=(geom, D(m=5)))</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__distance_lte=(geom, D(m=5)))</syntaxhighlight>
  
 
</div>
 
</div>
第1,275行: 第1,169行:
 
</div>
 
</div>
 
{|
 
{|
!width="16%"| Backend
+
!width="16%"| 后端
!width="84%"| SQL Equivalent
+
!width="84%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第1,295行: 第1,189行:
 
<div id="dwithin" class="section">
 
<div id="dwithin" class="section">
  
<span id="std-fieldlookup-dwithin"></span><span id="std:fieldlookup-dwithin"></span>
+
=== dwithin ===
=== <code>dwithin</code> ===
 
  
Returns models where the distance to the geometry field from the lookup
+
返回从查找几何到几何字段的距离彼此在给定距离内的模型。 请注意,如果目标几何图形在投影系统中,您只能提供 [[../measure#django.contrib.gis.measure|Distance]] 对象。 对于地理几何,您应该使用几何字段的单位(例如 <code>WGS84</code>) 的度数。
geometry are within the given distance from one another. Note that you can only
 
provide [[../measure#django.contrib.gis.measure|<code>Distance</code>]] 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 <code>WGS84</code>) .
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,310行: 第1,199行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>Zipcode.objects.filter(poly__dwithin=(geom, D(m=5)))</pre>
+
<syntaxhighlight lang="python">Zipcode.objects.filter(poly__dwithin=(geom, D(m=5)))</syntaxhighlight>
  
 
</div>
 
</div>
第1,316行: 第1,205行:
 
</div>
 
</div>
 
{|
 
{|
!width="21%"| Backend
+
!width="21%"| 后端
!width="79%"| SQL Equivalent
+
!width="79%"| SQL 等价于:
 
|-
 
|-
 
| PostGIS
 
| PostGIS
第1,333行: 第1,222行:
 
<div id="aggregate-functions" class="section">
 
<div id="aggregate-functions" class="section">
  
=== Aggregate Functions ===
+
=== 聚合函数 ===
  
Django provides some GIS-specific aggregate functions. For details on how to
+
Django 提供了一些特定于 GIS 的聚合函数。 有关如何使用这些聚合函数的详细信息,请参阅 [[../../../../topics/db/aggregation|聚合主题指南]]
use these aggregate functions, see [[../../../../topics/db/aggregation|<span class="doc">the topic guide on aggregation</span>]].
 
  
 
{|
 
{|
!width="28%"| Keyword Argument
+
!width="28%"| 关键字参数
 
!width="72%"| 描述
 
!width="72%"| 描述
 
|-
 
|-
 
| <code>tolerance</code>
 
| <code>tolerance</code>
| This keyword is for Oracle only. It is for the
+
| 此关键字仅适用于 Oracle。 用于<code>SDOAGGRTYPE</code>程序使用的公差值; [https://docs.oracle.com/en/database/oracle/oracle-database/18/spatl/spatial-concepts.html#GUID-CE10AB14-D5EA-43BA-A647-DAC9EEF41EE6 Oracle 文档] 有更多细节。
tolerance value used by the <code>SDOAGGRTYPE</code>
 
procedure; the [https://docs.oracle.com/en/database/oracle/oracle-database/18/spatl/spatial-concepts.html#GUID-CE10AB14-D5EA-43BA-A647-DAC9EEF41EE6 Oracle documentation] has more
 
details.
 
 
|}
 
|}
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,355行: 第1,240行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&gt;&gt;&gt; from django.contrib.gis.db.models import Extent, Union
+
<syntaxhighlight lang="python">>>> from django.contrib.gis.db.models import Extent, Union
&gt;&gt;&gt; WorldBorder.objects.aggregate(Extent('mpoly'), Union('mpoly'))</pre>
+
>>> WorldBorder.objects.aggregate(Extent('mpoly'), Union('mpoly'))</syntaxhighlight>
  
 
</div>
 
</div>
第1,363行: 第1,248行:
 
<div id="collect" class="section">
 
<div id="collect" class="section">
  
==== <code>Collect</code> ====
+
==== Collect ====
  
; ''class'' <code>Collect</code><span class="sig-paren">(</span>''<span class="n">geo_field</span>''<span class="sig-paren">)</span>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">Collect</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">geo_field</span></span>''<span class="sig-paren">)</span>
 
:  
 
:  
  
''Availability'': [https://postgis.net/docs/ST_Collect.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Collect.html PostGIS],SpatiaLite
SpatiaLite
 
  
Returns a <code>GEOMETRYCOLLECTION</code> or a <code>MULTI</code> geometry object from the geometry
+
从几何列返回 <code>GEOMETRYCOLLECTION</code> <code>MULTI</code> 几何对象。 这类似于 [[#django.contrib.gis.db.models.Union|Union]] 聚合的简化版本,但它可以比执行联合快几个数量级,因为它只是将几何图形汇总到一个集合或多对象中,而不关心分解边界。
column. This is analogous to a simplified version of the [[#django.contrib.gis.db.models.Union|<code>Union</code>]]
 
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.
 
  
  
第1,381行: 第1,261行:
 
<div id="extent" class="section">
 
<div id="extent" class="section">
  
==== <code>Extent</code> ====
+
==== Extent ====
  
; ''class'' <code>Extent</code><span class="sig-paren">(</span>''<span class="n">geo_field</span>''<span class="sig-paren">)</span>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">Extent</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">geo_field</span></span>''<span class="sig-paren">)</span>
 
:  
 
:  
  
''Availability'': [https://postgis.net/docs/ST_Extent.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Extent.html PostGIS]、Oracle、SpatiaLite
Oracle, SpatiaLite
 
  
Returns the extent of all <code>geo_field</code> in the <code>QuerySet</code> as a four-tuple,
+
以四元组形式返回 <code>QuerySet</code> 中所有 <code>geo_field</code> 的范围,包括左下坐标和右上坐标。
comprising the lower left coordinate and the upper right coordinate.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,398行: 第1,276行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&gt;&gt;&gt; qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent('poly'))
+
<syntaxhighlight lang="python">>>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent('poly'))
&gt;&gt;&gt; print(qs['poly__extent'])
+
>>> print(qs['poly__extent'])
(-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820)</pre>
+
(-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820)</syntaxhighlight>
  
 
</div>
 
</div>
第1,409行: 第1,287行:
 
<div id="extent3d" class="section">
 
<div id="extent3d" class="section">
  
==== <code>Extent3D</code> ====
+
==== Extent3D ====
  
; ''class'' <code>Extent3D</code><span class="sig-paren">(</span>''<span class="n">geo_field</span>''<span class="sig-paren">)</span>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">Extent3D</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">geo_field</span></span>''<span class="sig-paren">)</span>
 
:  
 
:  
  
''Availability'': [https://postgis.net/docs/ST_3DExtent.html PostGIS]
+
''可用性''[https://postgis.net/docs/ST_3DExtent.html PostGIS]
  
Returns the 3D extent of all <code>geo_field</code> in the <code>QuerySet</code> as a six-tuple,
+
以六元组形式返回 <code>QuerySet</code> 中所有 <code>geo_field</code> 的 3D 范围,包括左下坐标和右上坐标(每个坐标都有 x、y 和 z 坐标)。
comprising the lower left coordinate and upper right coordinate (each with x, y,
 
and z coordinates).
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,426行: 第1,302行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&gt;&gt;&gt; qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent3D('poly'))
+
<syntaxhighlight lang="python">>>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent3D('poly'))
&gt;&gt;&gt; print(qs['poly__extent3d'])
+
>>> print(qs['poly__extent3d'])
(-96.8016128540039, 29.7633724212646, 0, -95.3631439208984, 32.782058715820, 0)</pre>
+
(-96.8016128540039, 29.7633724212646, 0, -95.3631439208984, 32.782058715820, 0)</syntaxhighlight>
  
 
</div>
 
</div>
第1,437行: 第1,313行:
 
<div id="makeline" class="section">
 
<div id="makeline" class="section">
  
==== <code>MakeLine</code> ====
+
==== MakeLine ====
  
; ''class'' <code>MakeLine</code><span class="sig-paren">(</span>''<span class="n">geo_field</span>''<span class="sig-paren">)</span>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">MakeLine</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">geo_field</span></span>''<span class="sig-paren">)</span>
 
:  
 
:  
  
''Availability'': [https://postgis.net/docs/ST_MakeLine.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_MakeLine.html PostGIS],SpatiaLite
SpatiaLite
 
  
Returns a <code>LineString</code> constructed from the point field geometries in the
+
返回从 <code>QuerySet</code> 中的点场几何构造的 <code>LineString</code>。 目前,对查询集进行排序无效。
<code>QuerySet</code>. Currently, ordering the queryset has no effect.
 
  
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,454行: 第1,328行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&gt;&gt;&gt; qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(MakeLine('poly'))
+
<syntaxhighlight lang="python">>>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(MakeLine('poly'))
&gt;&gt;&gt; print(qs['poly__makeline'])
+
>>> print(qs['poly__makeline'])
LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018)</pre>
+
LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018)</syntaxhighlight>
  
 
</div>
 
</div>
第1,465行: 第1,339行:
 
<div id="union" class="section">
 
<div id="union" class="section">
  
==== <code>Union</code> ====
+
==== Union ====
  
; ''class'' <code>Union</code><span class="sig-paren">(</span>''<span class="n">geo_field</span>''<span class="sig-paren">)</span>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">Union</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">geo_field</span></span>''<span class="sig-paren">)</span>
 
:  
 
:  
  
''Availability'': [https://postgis.net/docs/ST_Union.html PostGIS],
+
''可用性''[https://postgis.net/docs/ST_Union.html PostGIS]、Oracle、SpatiaLite
Oracle, SpatiaLite
 
  
This method returns a [[../geos#django.contrib.gis.geos|<code>GEOSGeometry</code>]] object
+
此方法返回一个 [[../geos#django.contrib.gis.geos|GEOSGeometry]] 对象,该对象包含查询集中每个几何体的并集。 请注意,使用 <code>Union</code> 是处理器密集型的,并且可能会在大型查询集上花费大量时间。
comprising the union of every geometry in the queryset. Please note that use of
 
<code>Union</code> is processor intensive and may take a significant amount of time on
 
large querysets.
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
If the computation time for using this method is too expensive, consider
+
如果使用此方法的计算时间太昂贵,请考虑使用 [[#django.contrib.gis.db.models.Collect|Collect]] 代替。
using [[#django.contrib.gis.db.models.Collect|<code>Collect</code>]] instead.
 
  
  
 
</div>
 
</div>
举例:
+
例子:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第1,493行: 第1,362行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&gt;&gt;&gt; u = Zipcode.objects.aggregate(Union(poly))  # This may take a long time.
+
<syntaxhighlight lang="python">>>> u = Zipcode.objects.aggregate(Union(poly))  # This may take a long time.
&gt;&gt;&gt; u = Zipcode.objects.filter(poly__within=bbox).aggregate(Union(poly))  # A more sensible approach.</pre>
+
>>> u = Zipcode.objects.filter(poly__within=bbox).aggregate(Union(poly))  # A more sensible approach.</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
Footnotes
+
脚注
  
 
; <span class="brackets">[[#id4|1]]</span>
 
; <span class="brackets">[[#id4|1]]</span>
: ''See'' [http://www.opengis.org/docs/99-049.pdf OpenGIS Simple Feature Specification For SQL], at Ch. 2.1.13.2, p. 2-13 (The Dimensionally Extended Nine-Intersection Model).
+
: '''' [http://www.opengis.org/docs/99-049.pdf 用于 SQL 的 OpenGIS 简单特征规范], at Ch. 2.1.13.2, p. 2-13 (The Dimensionally Extended Nine-Intersection Model).
 
; <span class="brackets">[[#id5|2]]</span>
 
; <span class="brackets">[[#id5|2]]</span>
: ''See'' [https://docs.oracle.com/en/database/oracle/oracle-database/18/spatl/spatial-operators-reference.html#GUID-97C17C18-F05E-49B4-BE11-E89B972E2A02 SDO_RELATE documentation], from the Oracle Spatial and Graph Developer's Guide.
+
: '''' [https://docs.oracle.com/en/database/oracle/oracle-database/18/spatl/spatial-operators-reference.html#GUID-97C17C18-F05E-49B4-BE11-E89B972E2A02 SDO_RELATE 文档], from the Oracle Spatial and Graph Developer’s Guide.
 
; <span class="brackets">3</span><span class="fn-backref">([[#id2|1]],[[#id3|2]])</span>
 
; <span class="brackets">3</span><span class="fn-backref">([[#id2|1]],[[#id3|2]])</span>
: For an explanation of this routine, read [https://lin-ear-th-inking.blogspot.com/2007/06/subtleties-of-ogc-covers-spatial.html Quirks of the &quot;Contains&quot; Spatial Predicate] by Martin Davis (a PostGIS developer).
+
: 有关此例程的解释,请阅读 Martin Davis(PostGIS 开发人员)撰写的 [https://lin-ear-th-inking.blogspot.com/2007/06/subtleties-of-ogc-covers-spatial.html Quirks of the “Contains” Spatial Predicate]
  
  
第1,516行: 第1,385行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Django 2.2.x 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Django 2.2.x 文档]]

2021年10月31日 (日) 04:05的最新版本

GIS QuerySet API 参考

空间查找

本节中的空间查找可用于 GeometryFieldRasterField

有关介绍,请参阅 空间查找介绍 。 有关哪些查找与特定空间后端兼容的概述,请参阅 空间查找兼容性表

使用栅格查找

下面参考中的所有示例都是针对几何字段和输入给出的,但查找可以以相同的方式用于两侧的栅格。 每当查找不支持栅格输入时,输入会在必要时使用 ST_Polygon 函数自动转换为几何图形。 另请参阅 对栅格查找的介绍

查找使用的数据库运算符可以分为三类:

  • 原生栅格支持 N:运算符在查找的两侧原生接受栅格,并且栅格输入可以与几何输入混合。
  • 双边栅格支持 B:仅当查找的两侧都接收栅格输入时,运算符才支持栅格。 栅格数据会自动转换为几何图形以进行混合查找。
  • 几何转换支持 C。 查找没有原生栅格支持,所有栅格数据都会自动转换为几何图形。

下面的示例显示了在不同类型的栅格支持中查找的 SQL 等效项。 相同的模式适用于所有空间查找。

案件 查找 SQL 等价于:
N, B rast__contains=rst ST_Contains(rast, rst)
N, B rast__1__contains=(rst, 2) ST_Contains(rast, 1, rst, 2)
B, C rast__contains=geom ST_Contains(ST_Polygon(rast), geom)
B, C rast__1__contains=geom ST_Contains(ST_Polygon(rast, 1), geom)
B, C poly__contains=rst ST_Contains(poly, ST_Polygon(rst))
B, C poly__contains=(rst, 1) ST_Contains(poly, ST_Polygon(rst, 1))
C rast__crosses=rst ST_Crosses(ST_Polygon(rast), ST_Polygon(rst))
C rast__1__crosses=(rst, 2) ST_Crosses(ST_Polygon(rast, 1), ST_Polygon(rst, 2))
C rast__crosses=geom ST_Crosses(ST_Polygon(rast), geom)
C poly__crosses=rst ST_Crosses(poly, ST_Polygon(rst))

仅 PostGIS 后端(在本节中称为 PGRaster)支持使用栅格进行空间查找。


bbcontains

可用性PostGIS、MySQL、SpatiaLite、PGRaster(原生)

测试几何或栅格字段的边界框是否完全包含查找几何的边界框。

例子:

Zipcode.objects.filter(poly__bbcontains=geom)
后端 SQL 等价于:
PostGIS poly ~ geom
MySQL MBRContains(poly, geom)
SpatiaLite MbrContains(poly, geom)


bboverlaps

可用性PostGIS、MySQL、SpatiaLite、PGRaster(原生)

测试几何字段的边界框是否与查找几何的边界框重叠。

例子:

Zipcode.objects.filter(poly__bboverlaps=geom)
后端 SQL 等价于:
PostGIS poly && geom
MySQL MBROverlaps(poly, geom)
SpatiaLite MbrOverlaps(poly, geom)


contained

可用性PostGIS、MySQL、SpatiaLite、PGRaster(原生)

测试几何字段的边界框是否完全包含在查找几何的边界框内。

例子:

Zipcode.objects.filter(poly__contained=geom)
后端 SQL 等价于:
PostGIS poly @ geom
MySQL MBRWithin(poly, geom)
SpatiaLite MbrWithin(poly, geom)


contains

可用性PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(双边)

测试几何字段在空间上是否包含查找几何。

例子:

Zipcode.objects.filter(poly__contains=geom)
后端 SQL 等价于:
PostGIS ST_Contains(poly, geom)
Oracle SDO_CONTAINS(poly, geom)
MySQL MBRContains(poly, geom)
SpatiaLite Contains(poly, geom)


contains_properly

可用性PostGIS,PGRaster(双边)

如果查找几何与几何字段的内部相交,但不与边界(或外部)相交,则返回 true。

例子:

Zipcode.objects.filter(poly__contains_properly=geom)
后端 SQL 等价于:
PostGIS ST_ContainsProperly(poly, geom)


coveredby

可用性PostGIS、Oracle、PGRaster(双边)、SpatiaLite

测试几何字段中是否没有点位于查找几何之外。 3

例子:

Zipcode.objects.filter(poly__coveredby=geom)

2.2 版更改:添加了 SpatiaLite 支持。


后端 SQL 等价于:
PostGIS ST_CoveredBy(poly, geom)
Oracle SDO_COVEREDBY(poly, geom)
SpatiaLite CoveredBy(poly, geom)


covers

可用性PostGIS、Oracle、PGRaster(双边)、SpatiaLite

测试查找几何中是否没有点位于几何字段之外。 3

例子:

Zipcode.objects.filter(poly__covers=geom)

2.2 版更改:添加了 SpatiaLite 支持。


后端 SQL 等价于:
PostGIS ST_Covers(poly, geom)
Oracle SDO_COVERS(poly, geom)
SpatiaLite Covers(poly, geom)


crosses

可用性PostGIS、SpatiaLite、PGRaster(转换)

测试几何字段是否与查找几何在空间上交叉。

例子:

Zipcode.objects.filter(poly__crosses=geom)
后端 SQL 等价于:
PostGIS ST_Crosses(poly, geom)
SpatiaLite Crosses(poly, geom)


disjoint

可用性PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(双边)

测试几何字段是否与查找几何在空间上不相交。

例子:

Zipcode.objects.filter(poly__disjoint=geom)
后端 SQL 等价于:
PostGIS ST_Disjoint(poly, geom)
Oracle SDO_GEOM.RELATE(poly, 'DISJOINT', geom, 0.05)
MySQL MBRDisjoint(poly, geom)
SpatiaLite Disjoint(poly, geom)


equals

可用性PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(转换)

测试几何字段在空间上是否等于查找几何。

例子:

Zipcode.objects.filter(poly__equals=geom)
后端 SQL 等价于:
PostGIS ST_Equals(poly, geom)
Oracle SDO_EQUAL(poly, geom)
MySQL MBREquals(poly, geom)
SpatiaLite Equals(poly, geom)


exact、same_as

可用性PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(双边)

测试几何字段是否“等于”查找几何。 在 Oracle 和 SpatiaLite 上它测试空间相等性,而在 MySQL 和 PostGIS 上它测试边界框的相等性。

例子:

Zipcode.objects.filter(poly=geom)
后端 SQL 等价于:
PostGIS poly ~= geom
Oracle SDO_EQUAL(poly, geom)
MySQL MBREquals(poly, geom)
SpatiaLite Equals(poly, geom)


intersects

可用性PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(双边)

测试几何字段是否与查找几何在空间上相交。

例子:

Zipcode.objects.filter(poly__intersects=geom)
后端 SQL 等价于:
PostGIS ST_Intersects(poly, geom)
Oracle SDO_OVERLAPBDYINTERSECT(poly, geom)
MySQL MBRIntersects(poly, geom)
SpatiaLite Intersects(poly, geom)


isvalid

可用性:MySQL (≥ 5.7.5)、PostGIS、Oracle、SpatiaLite

测试几何图形是否有效。

例子:

Zipcode.objects.filter(poly__isvalid=True)
后端 SQL 等价于:
MySQL, PostGIS, SpatiaLite ST_IsValid(poly)
Oracle SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(poly, 0.05) = 'TRUE'


overlaps

可用性PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(双边)

测试几何字段是否与查找几何在空间上重叠。

后端 SQL 等价于:
PostGIS ST_Overlaps(poly, geom)
Oracle SDO_OVERLAPS(poly, geom)
MySQL MBROverlaps(poly, geom)
SpatiaLite Overlaps(poly, geom)


relate

可用性PostGIS、Oracle、SpatiaLite、PGRaster(转换)

通过给定模式中给定的值测试几何字段是否与查找几何在空间上相关。 这个查找需要一个元组参数,(geom, pattern)pattern 的形式将取决于空间后端:

PostGIS 和 SpatiaLite

在这些空间后端上,相交模式是一个由九个字符组成的字符串,用于定义几何字段与查找几何的内部、边界和外部之间的交集。 交集模式矩阵只能使用以下字符:12TF*。 这种查找类型允许用户“微调”与 DE-9IM 模型一致的特定几何关系。 1

几何示例:

# 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 等效项:

SELECT ... WHERE ST_Relate(poly, geom, 'T*T***FF*')

SpatiaLite SQL 等效项:

SELECT ... WHERE Relate(poly, geom, 'T*T***FF*')

光栅示例:

Zipcode.objects.filter(poly__relate=(rast, 1, 'T*T***FF*'))
Zipcode.objects.filter(rast__2__relate=(rast, 1, 'T*T***FF*'))

PostGIS SQL 等效项:

SELECT ... WHERE ST_Relate(poly, ST_Polygon(rast, 1), 'T*T***FF*')
SELECT ... WHERE ST_Relate(ST_Polygon(rast, 2), ST_Polygon(rast, 1), 'T*T***FF*')

Oracle

这里的关系模式由以下九个关系串中的至少一个组成:TOUCHOVERLAPBDYDISJOINTOVERLAPBDYINTERSECTEQUALINSIDECOVEREDBYCONTAINSCOVERSONANYINTERACT。 多个字符串可以用逻辑布尔运算符 OR 组合,例如,'inside+touch'2 关系字符串不区分大小写。

例子:

Zipcode.objects.filter(poly__relate=(geom, 'anyinteract'))

Oracle SQL 等效项:

SELECT ... WHERE SDO_RELATE(poly, geom, 'anyinteract')

touches

可用性PostGIS、Oracle、MySQL、SpatiaLite

测试几何字段是否在空间上接触查找几何。

例子:

Zipcode.objects.filter(poly__touches=geom)
后端 SQL 等价于:
PostGIS ST_Touches(poly, geom)
MySQL MBRTouches(poly, geom)
Oracle SDO_TOUCH(poly, geom)
SpatiaLite Touches(poly, geom)


within

可用性PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(双边)

测试几何字段是否在空间上查找几何。

例子:

Zipcode.objects.filter(poly__within=geom)
后端 SQL 等价于:
PostGIS ST_Within(poly, geom)
MySQL MBRWithin(poly, geom)
Oracle SDO_INSIDE(poly, geom)
SpatiaLite Within(poly, geom)


left

可用性PostGIS,PGRaster(转换)

测试几何字段的边界框是否严格位于查找几何的边界框的左侧。

例子:

Zipcode.objects.filter(poly__left=geom)

PostGIS 等效项:

SELECT ... WHERE poly << geom

overlaps_left

可用性PostGIS,PGRaster(双边)

测试几何字段的边界框是否与查找几何的边界框重叠或位于其左侧。

例子:

Zipcode.objects.filter(poly__overlaps_left=geom)

PostGIS 等效项:

SELECT ... WHERE poly &< geom

overlaps_right

可用性PostGIS,PGRaster(双边)

测试几何字段的边界框是否与查找几何的边界框重叠或位于其右侧。

例子:

Zipcode.objects.filter(poly__overlaps_right=geom)

PostGIS 等效项:

SELECT ... WHERE poly &> geom

overlaps_above

可用性PostGIS,PGRaster(转换)

测试几何字段的边界框是否与查找几何的边界框重叠或位于其上方。

例子:

Zipcode.objects.filter(poly__overlaps_above=geom)

PostGIS 等效项:

SELECT ... WHERE poly |&> geom

overlaps_below

可用性PostGIS,PGRaster(转换)

测试几何字段的边界框是否重叠或低于查找几何的边界框。

例子:

Zipcode.objects.filter(poly__overlaps_below=geom)

PostGIS 等效项:

SELECT ... WHERE poly &<| geom

strictly_above

可用性PostGIS,PGRaster(转换)

测试几何字段的边界框是否严格高于查找几何的边界框。

例子:

Zipcode.objects.filter(poly__strictly_above=geom)

PostGIS 等效项:

SELECT ... WHERE poly |>> geom

strictly_below

可用性PostGIS,PGRaster(转换)

测试几何字段的边界框是否严格低于查找几何的边界框。

例子:

Zipcode.objects.filter(poly__strictly_below=geom)

PostGIS 等效项:

SELECT ... WHERE poly <<| geom

距离查找

可用性:PostGIS、Oracle、MySQL、SpatiaLite、PGRaster(原生)

有关执行距离查询的概述,请参阅 距离查询介绍

距离查找采用以下形式:

<field>__<distance lookup>=(<geometry/raster>, <distance value>[, 'spheroid'])
<field>__<distance lookup>=(<raster>, <band_index>, <distance value>[, 'spheroid'])
<field>__<band_index>__<distance lookup>=(<raster>, <band_index>, <distance value>[, 'spheroid'])

传递给距离查找的值是一个元组; 前两个值是强制性的,是计算距离的几何图形和一个距离值(以字段为单位的数字,一个距离对象,或查询表达式 )。 要将波段索引传递给查找,请使用 3 元组,其中第二个条目是波段索引。

在除 :lookup:`dwithin` 之外的每个距离查找中,可以包含一个可选元素 'spheroid',以便在具有大地坐标系的字段上使用更准确的球体距离计算函数。

在 PostgreSQL 上,'spheroid' 选项使用 ST_DistanceSpheroid 而不是 ST_DistanceSphere。 更简单的 ST_Distance 函数用于投影坐标系。 栅格被转换为几何图形以进行基于球体的查找。

distance_gt

返回从查找几何到几何字段的距离大于给定距离值的模型。

例子:

Zipcode.objects.filter(poly__distance_gt=(geom, D(m=5)))
后端 SQL 等价于:
PostGIS ST_Distance/ST_Distance_Sphere(poly, geom) > 5
MySQL ST_Distance(poly, geom) > 5
Oracle SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) > 5
SpatiaLite Distance(poly, geom) > 5


distance_gte

返回从查找几何到几何字段的距离大于或等于给定距离值的模型。

例子:

Zipcode.objects.filter(poly__distance_gte=(geom, D(m=5)))
后端 SQL 等价于:
PostGIS ST_Distance/ST_Distance_Sphere(poly, geom) >= 5
MySQL ST_Distance(poly, geom) >= 5
Oracle SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) >= 5
SpatiaLite Distance(poly, geom) >= 5


distance_lt

返回从查找几何到几何字段的距离小于给定距离值的模型。

例子:

Zipcode.objects.filter(poly__distance_lt=(geom, D(m=5)))
后端 SQL 等价于:
PostGIS ST_Distance/ST_Distance_Sphere(poly, geom) < 5
MySQL ST_Distance(poly, geom) < 5
Oracle SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) < 5
SpatiaLite Distance(poly, geom) < 5


distance_lte

返回从查找几何到几何字段的距离小于或等于给定距离值的模型。

例子:

Zipcode.objects.filter(poly__distance_lte=(geom, D(m=5)))
后端 SQL 等价于:
PostGIS ST_Distance/ST_Distance_Sphere(poly, geom) <= 5
MySQL ST_Distance(poly, geom) <= 5
Oracle SDO_GEOM.SDO_DISTANCE(poly, geom, 0.05) <= 5
SpatiaLite Distance(poly, geom) <= 5


dwithin

返回从查找几何到几何字段的距离彼此在给定距离内的模型。 请注意,如果目标几何图形在投影系统中,您只能提供 Distance 对象。 对于地理几何,您应该使用几何字段的单位(例如 WGS84) 的度数。

例子:

Zipcode.objects.filter(poly__dwithin=(geom, D(m=5)))
后端 SQL 等价于:
PostGIS ST_DWithin(poly, geom, 5)
Oracle SDO_WITHIN_DISTANCE(poly, geom, 5)
SpatiaLite PtDistWithin(poly, geom, 5)


聚合函数

Django 提供了一些特定于 GIS 的聚合函数。 有关如何使用这些聚合函数的详细信息,请参阅 聚合主题指南

关键字参数 描述
tolerance 此关键字仅适用于 Oracle。 用于SDOAGGRTYPE程序使用的公差值; Oracle 文档 有更多细节。

例子:

>>> from django.contrib.gis.db.models import Extent, Union
>>> WorldBorder.objects.aggregate(Extent('mpoly'), Union('mpoly'))

Collect

class Collect(geo_field)

可用性PostGIS,SpatiaLite

从几何列返回 GEOMETRYCOLLECTIONMULTI 几何对象。 这类似于 Union 聚合的简化版本,但它可以比执行联合快几个数量级,因为它只是将几何图形汇总到一个集合或多对象中,而不关心分解边界。


Extent

class Extent(geo_field)

可用性PostGIS、Oracle、SpatiaLite

以四元组形式返回 QuerySet 中所有 geo_field 的范围,包括左下坐标和右上坐标。

例子:

>>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(Extent('poly'))
>>> print(qs['poly__extent'])
(-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820)

Extent3D

class Extent3D(geo_field)

可用性PostGIS

以六元组形式返回 QuerySet 中所有 geo_field 的 3D 范围,包括左下坐标和右上坐标(每个坐标都有 x、y 和 z 坐标)。

例子:

>>> 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

class MakeLine(geo_field)

可用性PostGIS,SpatiaLite

返回从 QuerySet 中的点场几何构造的 LineString。 目前,对查询集进行排序无效。

例子:

>>> qs = City.objects.filter(name__in=('Houston', 'Dallas')).aggregate(MakeLine('poly'))
>>> print(qs['poly__makeline'])
LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018)

Union

class Union(geo_field)

可用性PostGIS、Oracle、SpatiaLite

此方法返回一个 GEOSGeometry 对象,该对象包含查询集中每个几何体的并集。 请注意,使用 Union 是处理器密集型的,并且可能会在大型查询集上花费大量时间。

笔记

如果使用此方法的计算时间太昂贵,请考虑使用 Collect 代替。


例子:

>>> 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.

脚注

1
用于 SQL 的 OpenGIS 简单特征规范, at Ch. 2.1.13.2, p. 2-13 (The Dimensionally Extended Nine-Intersection Model).
2
SDO_RELATE 文档, from the Oracle Spatial and Graph Developer’s Guide.
3(1,2)
有关此例程的解释,请阅读 Martin Davis(PostGIS 开发人员)撰写的 Quirks of the “Contains” Spatial Predicate