{"title":"GeoDjango Database API","version":"3.0","locale":"zh-hans","docname":"ref/contrib/gis/db-api","url":"/zh-hans/3.0/ref/contrib/gis/db-api/","canonical":"https://djangodocs.dev/zh-hans/3.0/ref/contrib/gis/db-api/","summary":"Spatial Backends Link to this heading # GeoDjango currently provides the following spatial database backends: django.contrib.gis.db.backends.postgis…","html":"<h1>GeoDjango Database API<a class=\"heading-anchor\" href=\"#geodjango-database-api\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"module-django.contrib.gis.db.backends\">\n<span id=\"id1\"></span><span id=\"spatial-backends\"></span><h2>Spatial Backends<a class=\"heading-anchor\" href=\"#module-django.contrib.gis.db.backends\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>GeoDjango currently provides the following spatial database backends:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">django.contrib.gis.db.backends.postgis</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">django.contrib.gis.db.backends.mysql</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">django.contrib.gis.db.backends.oracle</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">django.contrib.gis.db.backends.spatialite</code></p></li>\n</ul>\n<section id=\"mysql-spatial-limitations\">\n<span id=\"id2\"></span><h3>MySQL Spatial Limitations<a class=\"heading-anchor\" href=\"#mysql-spatial-limitations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Before MySQL 5.6.1, spatial extensions only support bounding box operations\n(what MySQL calls minimum bounding rectangles, or MBR). Specifically, MySQL did\nnot conform to the OGC standard. Django supports spatial functions operating on\nreal geometries available in modern MySQL versions. However, the spatial\nfunctions are not as rich as other backends like PostGIS.</p>\n<aside class=\"version-note version-changed\" data-version=\"3.0\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 3.0</p><p>Support for spatial functions operating on real geometries was added.</p>\n</aside>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>True spatial indexes (R-trees) are only supported with\nMyISAM tables on MySQL. <a class=\"footnote-reference brackets\" href=\"#fnmysqlidx\" id=\"id3\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>4<span class=\"fn-bracket\">]</span></a> In other words, when using\nMySQL spatial extensions you have to choose between fast spatial\nlookups and the integrity of your data -- MyISAM tables do\nnot support transactions or foreign key constraints.</p>\n</aside>\n</section>\n<section id=\"raster-support\">\n<h3>Raster Support<a class=\"heading-anchor\" href=\"#raster-support\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><code class=\"docutils literal notranslate\">RasterField</code> is currently only implemented for the PostGIS backend. Spatial\nlookups are available for raster fields, but spatial database functions and\naggregates aren't implemented for raster fields.</p>\n</section>\n</section>\n<section id=\"creating-and-saving-models-with-geometry-fields\">\n<h2>Creating and Saving Models with Geometry Fields<a class=\"heading-anchor\" href=\"#creating-and-saving-models-with-geometry-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Here is an example of how to create a geometry object (assuming the <code class=\"docutils literal notranslate\">Zipcode</code>\nmodel):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">zipcode.models</span> <span class=\"kn\">import</span> Zipcode\n<span class=\"gp\">&gt;&gt;&gt; </span>z <span class=\"o\">=</span> Zipcode<span class=\"p\">(</span>code<span class=\"o\">=</span><span class=\"mi\">77096</span><span class=\"p\">,</span> poly<span class=\"o\">=</span><span class=\"s1\">&#39;POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))&#39;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>z<span class=\"o\">.</span>save<span class=\"p\">()</span>\n</code></pre></div>\n<p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geos/#django.contrib.gis.geos.GEOSGeometry\" title=\"django.contrib.gis.geos.GEOSGeometry\"><code class=\"xref py py-class docutils literal notranslate\">GEOSGeometry</code></a> objects may also be used to save geometric models:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.contrib.gis.geos</span> <span class=\"kn\">import</span> GEOSGeometry\n<span class=\"gp\">&gt;&gt;&gt; </span>poly <span class=\"o\">=</span> GEOSGeometry<span class=\"p\">(</span><span class=\"s1\">&#39;POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))&#39;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>z <span class=\"o\">=</span> Zipcode<span class=\"p\">(</span>code<span class=\"o\">=</span><span class=\"mi\">77096</span><span class=\"p\">,</span> poly<span class=\"o\">=</span>poly<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>z<span class=\"o\">.</span>save<span class=\"p\">()</span>\n</code></pre></div>\n<p>Moreover, if the <code class=\"docutils literal notranslate\">GEOSGeometry</code> is in a different coordinate system (has a\ndifferent SRID value) than that of the field, then it will be implicitly\ntransformed into the SRID of the model's field, using the spatial database's\ntransform procedure:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>poly_3084 <span class=\"o\">=</span> GEOSGeometry<span class=\"p\">(</span><span class=\"s1\">&#39;POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))&#39;</span><span class=\"p\">,</span> srid<span class=\"o\">=</span><span class=\"mi\">3084</span><span class=\"p\">)</span>  <span class=\"c1\"># SRID 3084 is &#39;NAD83(HARN) / Texas Centric Lambert Conformal&#39;</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>z <span class=\"o\">=</span> Zipcode<span class=\"p\">(</span>code<span class=\"o\">=</span><span class=\"mi\">78212</span><span class=\"p\">,</span> poly<span class=\"o\">=</span>poly_3084<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>z<span class=\"o\">.</span>save<span class=\"p\">()</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> connection\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"nb\">print</span><span class=\"p\">(</span>connection<span class=\"o\">.</span>queries<span class=\"p\">[</span><span class=\"o\">-</span><span class=\"mi\">1</span><span class=\"p\">][</span><span class=\"s1\">&#39;sql&#39;</span><span class=\"p\">])</span> <span class=\"c1\"># printing the last SQL statement executed (requires DEBUG=True)</span>\n<span class=\"go\">INSERT INTO &quot;geoapp_zipcode&quot; (&quot;code&quot;, &quot;poly&quot;) VALUES (78212, ST_Transform(ST_GeomFromWKB(&#39;\\\\001 ... &#39;, 3084), 4326))</span>\n</code></pre></div>\n<p>Thus, geometry parameters may be passed in using the <code class=\"docutils literal notranslate\">GEOSGeometry</code> object, WKT\n(Well Known Text <a class=\"footnote-reference brackets\" href=\"#fnwkt\" id=\"id4\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>1<span class=\"fn-bracket\">]</span></a>), HEXEWKB (PostGIS specific -- a WKB geometry in\nhexadecimal <a class=\"footnote-reference brackets\" href=\"#fnewkb\" id=\"id5\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>2<span class=\"fn-bracket\">]</span></a>), and GeoJSON (see <span class=\"target\" id=\"index-0\"></span><a class=\"rfc reference external\" href=\"https://datatracker.ietf.org/doc/html/rfc7946.html\"><strong>RFC 7946</strong></a>). Essentially, if the\ninput is not a <code class=\"docutils literal notranslate\">GEOSGeometry</code> object, the geometry field will attempt to\ncreate a <code class=\"docutils literal notranslate\">GEOSGeometry</code> instance from the input.</p>\n<p>For more information creating <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geos/#django.contrib.gis.geos.GEOSGeometry\" title=\"django.contrib.gis.geos.GEOSGeometry\"><code class=\"xref py py-class docutils literal notranslate\">GEOSGeometry</code></a>\nobjects, refer to the <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geos/#geos-tutorial\"><span class=\"std std-ref\">GEOS tutorial</span></a>.</p>\n</section>\n<section id=\"creating-and-saving-models-with-raster-fields\">\n<span id=\"creating-and-saving-raster-models\"></span><h2>Creating and Saving Models with Raster Fields<a class=\"heading-anchor\" href=\"#creating-and-saving-models-with-raster-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When creating raster models, the raster field will implicitly convert the input\ninto a <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster\" title=\"django.contrib.gis.gdal.GDALRaster\"><code class=\"xref py py-class docutils literal notranslate\">GDALRaster</code></a> using lazy-evaluation.\nThe raster field will therefore accept any input that is accepted by the\n<a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster\" title=\"django.contrib.gis.gdal.GDALRaster\"><code class=\"xref py py-class docutils literal notranslate\">GDALRaster</code></a> constructor.</p>\n<p>Here is an example of how to create a raster object from a raster file\n<code class=\"docutils literal notranslate\">volcano.tif</code> (assuming the <code class=\"docutils literal notranslate\">Elevation</code> model):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">elevation.models</span> <span class=\"kn\">import</span> Elevation\n<span class=\"gp\">&gt;&gt;&gt; </span>dem <span class=\"o\">=</span> Elevation<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s1\">&#39;Volcano&#39;</span><span class=\"p\">,</span> rast<span class=\"o\">=</span><span class=\"s1\">&#39;/path/to/raster/volcano.tif&#39;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>dem<span class=\"o\">.</span>save<span class=\"p\">()</span>\n</code></pre></div>\n<p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster\" title=\"django.contrib.gis.gdal.GDALRaster\"><code class=\"xref py py-class docutils literal notranslate\">GDALRaster</code></a> objects may also be used to save\nraster models:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.contrib.gis.gdal</span> <span class=\"kn\">import</span> GDALRaster\n<span class=\"gp\">&gt;&gt;&gt; </span>rast <span class=\"o\">=</span> GDALRaster<span class=\"p\">({</span><span class=\"s1\">&#39;width&#39;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"s1\">&#39;height&#39;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"s1\">&#39;name&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;Canyon&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;srid&#39;</span><span class=\"p\">:</span> <span class=\"mi\">4326</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>                   <span class=\"s1\">&#39;scale&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"mf\">0.1</span><span class=\"p\">,</span> <span class=\"o\">-</span><span class=\"mf\">0.1</span><span class=\"p\">],</span> <span class=\"s1\">&#39;bands&#39;</span><span class=\"p\">:</span> <span class=\"p\">[{</span><span class=\"s2\">&quot;data&quot;</span><span class=\"p\">:</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"mi\">100</span><span class=\"p\">)}]})</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>dem <span class=\"o\">=</span> Elevation<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s1\">&#39;Canyon&#39;</span><span class=\"p\">,</span> rast<span class=\"o\">=</span>rast<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>dem<span class=\"o\">.</span>save<span class=\"p\">()</span>\n</code></pre></div>\n<p>Note that this equivalent to:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>dem <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    name<span class=\"o\">=</span><span class=\"s1\">&#39;Canyon&#39;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    rast<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s1\">&#39;width&#39;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"s1\">&#39;height&#39;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"s1\">&#39;name&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;Canyon&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;srid&#39;</span><span class=\"p\">:</span> <span class=\"mi\">4326</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>          <span class=\"s1\">&#39;scale&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"mf\">0.1</span><span class=\"p\">,</span> <span class=\"o\">-</span><span class=\"mf\">0.1</span><span class=\"p\">],</span> <span class=\"s1\">&#39;bands&#39;</span><span class=\"p\">:</span> <span class=\"p\">[{</span><span class=\"s2\">&quot;data&quot;</span><span class=\"p\">:</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"mi\">100</span><span class=\"p\">)}]},</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"spatial-lookups\">\n<span id=\"spatial-lookups-intro\"></span><h2>Spatial Lookups<a class=\"heading-anchor\" href=\"#spatial-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>GeoDjango's lookup types may be used with any manager method like\n<code class=\"docutils literal notranslate\">filter()</code>, <code class=\"docutils literal notranslate\">exclude()</code>, etc.  However, the lookup types unique to\nGeoDjango are only available on spatial fields.</p>\n<p>Filters on 'normal' fields (e.g. <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/models/fields/#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a>)\nmay be chained with those on geographic fields. Geographic lookups accept\ngeometry and raster input on both sides and input types can be mixed freely.</p>\n<p>The general structure of geographic lookups is described below. A complete\nreference can be found in the <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#spatial-lookups\"><span class=\"std std-ref\">spatial lookup reference</span></a>.</p>\n<section id=\"geometry-lookups\">\n<h3>Geometry Lookups<a class=\"heading-anchor\" href=\"#geometry-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Geographic queries with geometries take the following general form (assuming\nthe <code class=\"docutils literal notranslate\">Zipcode</code> model used in the <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/model-api/\"><span class=\"doc\">GeoDjango Model API</span></a>):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Zipcode<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span><span class=\"o\">&lt;</span>field<span class=\"o\">&gt;</span>__<span class=\"o\">&lt;</span>lookup_type<span class=\"o\">&gt;=&lt;</span>parameter<span class=\"o\">&gt;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Zipcode<span class=\"o\">.</span>objects<span class=\"o\">.</span>exclude<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>例子:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Zipcode<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>poly__contains<span class=\"o\">=</span>pnt<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>poly__contains<span class=\"o\">=</span>rst<span class=\"p\">)</span>\n</code></pre></div>\n<p>In this case, <code class=\"docutils literal notranslate\">poly</code> is the geographic field, <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-gis-contains\"><code class=\"xref std std-lookup docutils literal notranslate\">contains</code></a>\nis the spatial lookup type, <code class=\"docutils literal notranslate\">pnt</code> is the parameter (which may be a\n<a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geos/#django.contrib.gis.geos.GEOSGeometry\" title=\"django.contrib.gis.geos.GEOSGeometry\"><code class=\"xref py py-class docutils literal notranslate\">GEOSGeometry</code></a> object or a string of\nGeoJSON , WKT, or HEXEWKB), and <code class=\"docutils literal notranslate\">rst</code> is a\n<a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster\" title=\"django.contrib.gis.gdal.GDALRaster\"><code class=\"xref py py-class docutils literal notranslate\">GDALRaster</code></a> object.</p>\n</section>\n<section id=\"raster-lookups\">\n<span id=\"spatial-lookup-raster\"></span><h3>Raster Lookups<a class=\"heading-anchor\" href=\"#raster-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The raster lookup syntax is similar to the syntax for geometries. The only\ndifference is that a band index can be specified as additional input. If no band\nindex is specified, the first band is used by default (index <code class=\"docutils literal notranslate\">0</code>). In that\ncase the syntax is identical to the syntax for geometry lookups.</p>\n<p>To specify the band index, an additional parameter can be specified on both\nsides of the lookup. On the left hand side, the double underscore syntax is\nused to pass a band index. On the right hand side, a tuple of the raster and\nband index can be specified.</p>\n<p>This results in the following general form for lookups involving rasters\n(assuming the <code class=\"docutils literal notranslate\">Elevation</code> model used in the <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/model-api/\"><span class=\"doc\">GeoDjango Model API</span></a>):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span><span class=\"o\">&lt;</span>field<span class=\"o\">&gt;</span>__<span class=\"o\">&lt;</span>lookup_type<span class=\"o\">&gt;=&lt;</span>parameter<span class=\"o\">&gt;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span><span class=\"o\">&lt;</span>field<span class=\"o\">&gt;</span>__<span class=\"o\">&lt;</span>band_index<span class=\"o\">&gt;</span>__<span class=\"o\">&lt;</span>lookup_type<span class=\"o\">&gt;=&lt;</span>parameter<span class=\"o\">&gt;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span><span class=\"o\">&lt;</span>field<span class=\"o\">&gt;</span>__<span class=\"o\">&lt;</span>lookup_type<span class=\"o\">&gt;=</span><span class=\"p\">(</span><span class=\"o\">&lt;</span>raster_input<span class=\"p\">,</span> <span class=\"o\">&lt;</span>band_index<span class=\"o\">&gt;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>例子:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>rast__contains<span class=\"o\">=</span>geom<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>rast__contains<span class=\"o\">=</span>rst<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>rast__1__contains<span class=\"o\">=</span>geom<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>rast__contains<span class=\"o\">=</span><span class=\"p\">(</span>rst<span class=\"p\">,</span> <span class=\"mi\">1</span><span class=\"p\">))</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> Elevation<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>rast__1__contains<span class=\"o\">=</span><span class=\"p\">(</span>rst<span class=\"p\">,</span> <span class=\"mi\">1</span><span class=\"p\">))</span>\n</code></pre></div>\n<p>On the left hand side of the example, <code class=\"docutils literal notranslate\">rast</code> is the geographic raster field\nand <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-gis-contains\"><code class=\"xref std std-lookup docutils literal notranslate\">contains</code></a> is the spatial lookup type. On the right\nhand side, <code class=\"docutils literal notranslate\">geom</code> is a geometry input and <code class=\"docutils literal notranslate\">rst</code> is a\n<a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.GDALRaster\" title=\"django.contrib.gis.gdal.GDALRaster\"><code class=\"xref py py-class docutils literal notranslate\">GDALRaster</code></a> object. The band index defaults to\n<code class=\"docutils literal notranslate\">0</code> in the first two queries and is set to <code class=\"docutils literal notranslate\">1</code> on the others.</p>\n<p>While all spatial lookups can be used with raster objects on both sides, not all\nunderlying operators natively accept raster input. For cases where the operator\nexpects geometry input, the raster is automatically converted to a geometry.\nIt's important to keep this in mind when interpreting the lookup results.</p>\n<p>The type of raster support is listed for all lookups in the <a class=\"reference internal\" href=\"#spatial-lookup-compatibility\"><span class=\"std std-ref\">compatibility\ntable</span></a>. Lookups involving rasters are currently\nonly available for the PostGIS backend.</p>\n</section>\n</section>\n<section id=\"distance-queries\">\n<span id=\"id6\"></span><h2>Distance Queries<a class=\"heading-anchor\" href=\"#distance-queries\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"introduction\">\n<h3>介绍<a class=\"heading-anchor\" href=\"#introduction\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Distance calculations with spatial data is tricky because, unfortunately,\nthe Earth is not flat.  Some distance queries with fields in a geographic\ncoordinate system may have to be expressed differently because of\nlimitations in PostGIS.  Please see the <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/model-api/#selecting-an-srid\"><span class=\"std std-ref\">Selecting an SRID</span></a> section\nin the <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/model-api/\"><span class=\"doc\">GeoDjango Model API</span></a> documentation for more details.</p>\n</section>\n<section id=\"distance-lookups\">\n<span id=\"distance-lookups-intro\"></span><h3>Distance Lookups<a class=\"heading-anchor\" href=\"#distance-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><em>Availability</em>: PostGIS, MariaDB, MySQL, Oracle, SpatiaLite, PGRaster (Native)</p>\n<p>The following distance lookups are available:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lt\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_lt</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lte\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_lte</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gt\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_gt</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gte\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_gte</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-dwithin\"><code class=\"xref std std-lookup docutils literal notranslate\">dwithin</code></a> (except MariaDB and MySQL)</p></li>\n</ul>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>For <em>measuring</em>, rather than querying on distances, use the\n<a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Distance\" title=\"django.contrib.gis.db.models.functions.Distance\"><code class=\"xref py py-class docutils literal notranslate\">Distance</code></a> function.</p>\n</aside>\n<p>Distance lookups take a tuple parameter comprising:</p>\n<ol class=\"arabic simple\">\n<li><p>A geometry or raster to base calculations from; and</p></li>\n<li><p>A number or <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/measure/#django.contrib.gis.measure.Distance\" title=\"django.contrib.gis.measure.Distance\"><code class=\"xref py py-class docutils literal notranslate\">Distance</code></a> object containing the distance.</p></li>\n</ol>\n<p>If a <a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/measure/#django.contrib.gis.measure.Distance\" title=\"django.contrib.gis.measure.Distance\"><code class=\"xref py py-class docutils literal notranslate\">Distance</code></a> object is used,\nit may be expressed in any units (the SQL generated will use units\nconverted to those of the field); otherwise, numeric parameters are assumed\nto be in the units of the field.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>In PostGIS, <code class=\"docutils literal notranslate\">ST_Distance_Sphere</code> does <em>not</em> limit the geometry types\ngeographic distance queries are performed with. <a class=\"footnote-reference brackets\" href=\"#fndistsphere15\" id=\"id7\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>3<span class=\"fn-bracket\">]</span></a>  However,\nthese queries may take a long time, as great-circle distances must be\ncalculated on the fly for <em>every</em> row in the query.  This is because the\nspatial index on traditional geometry fields cannot be used.</p>\n<p>For much better performance on WGS84 distance queries, consider using\n<a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/model-api/#geography-type\"><span class=\"std std-ref\">geography columns</span></a> in your database instead because\nthey are able to use their spatial index in distance queries.\nYou can tell GeoDjango to use a geography column by setting <code class=\"docutils literal notranslate\">geography=True</code>\nin your field definition.</p>\n</aside>\n<p>For example, let's say we have a <code class=\"docutils literal notranslate\">SouthTexasCity</code> model (from the\n<a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/3.0.x/tests/gis_tests/distapp/models.py\">GeoDjango distance tests</a> ) on a\n<em>projected</em> coordinate system valid for cities in southern Texas:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib.gis.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">SouthTexasCity</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">30</span><span class=\"p\">)</span>\n    <span class=\"c1\"># A projected coordinate system (only valid for South Texas!)</span>\n    <span class=\"c1\"># is used, units are in meters.</span>\n    point <span class=\"o\">=</span> models<span class=\"o\">.</span>PointField<span class=\"p\">(</span>srid<span class=\"o\">=</span><span class=\"mi\">32140</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Then distance queries may be performed as follows:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.contrib.gis.geos</span> <span class=\"kn\">import</span> GEOSGeometry\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.contrib.gis.measure</span> <span class=\"kn\">import</span> D <span class=\"c1\"># ``D`` is a shortcut for ``Distance``</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">geoapp.models</span> <span class=\"kn\">import</span> SouthTexasCity\n<span class=\"go\"># Distances will be calculated from this point, which does not have to be projected.</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>pnt <span class=\"o\">=</span> GEOSGeometry<span class=\"p\">(</span><span class=\"s1\">&#39;POINT(-96.876369 29.905320)&#39;</span><span class=\"p\">,</span> srid<span class=\"o\">=</span><span class=\"mi\">4326</span><span class=\"p\">)</span>\n<span class=\"go\"># If numeric parameter, units of field (meters in this case) are assumed.</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> SouthTexasCity<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>point__distance_lte<span class=\"o\">=</span><span class=\"p\">(</span>pnt<span class=\"p\">,</span> <span class=\"mi\">7000</span><span class=\"p\">))</span>\n<span class=\"go\"># Find all Cities within 7 km, &gt; 20 miles away, and &gt; 100 chains away (an obscure unit)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> SouthTexasCity<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>point__distance_lte<span class=\"o\">=</span><span class=\"p\">(</span>pnt<span class=\"p\">,</span> D<span class=\"p\">(</span>km<span class=\"o\">=</span><span class=\"mi\">7</span><span class=\"p\">)))</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> SouthTexasCity<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>point__distance_gte<span class=\"o\">=</span><span class=\"p\">(</span>pnt<span class=\"p\">,</span> D<span class=\"p\">(</span>mi<span class=\"o\">=</span><span class=\"mi\">20</span><span class=\"p\">)))</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> SouthTexasCity<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>point__distance_gte<span class=\"o\">=</span><span class=\"p\">(</span>pnt<span class=\"p\">,</span> D<span class=\"p\">(</span>chain<span class=\"o\">=</span><span class=\"mi\">100</span><span class=\"p\">)))</span>\n</code></pre></div>\n<p>Raster queries work the same way by replacing the geometry field <code class=\"docutils literal notranslate\">point</code> with\na raster field, or the <code class=\"docutils literal notranslate\">pnt</code> object with a raster object, or both. To specify\nthe band index of a raster input on the right hand side, a 3-tuple can be\npassed to the lookup as follows:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>qs <span class=\"o\">=</span> SouthTexasCity<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>point__distance_gte<span class=\"o\">=</span><span class=\"p\">(</span>rst<span class=\"p\">,</span> <span class=\"mi\">2</span><span class=\"p\">,</span> D<span class=\"p\">(</span>km<span class=\"o\">=</span><span class=\"mi\">7</span><span class=\"p\">)))</span>\n</code></pre></div>\n<p>Where the band with index 2 (the third band) of the raster <code class=\"docutils literal notranslate\">rst</code> would be\nused for the lookup.</p>\n</section>\n</section>\n<section id=\"compatibility-tables\">\n<span id=\"compatibility-table\"></span><h2>Compatibility Tables<a class=\"heading-anchor\" href=\"#compatibility-tables\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"spatial-lookup-compatibility\">\n<span id=\"id8\"></span><h3>Spatial Lookups<a class=\"heading-anchor\" href=\"#spatial-lookup-compatibility\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The following table provides a summary of what spatial lookups are available\nfor each spatial database backend. The PostGIS Raster (PGRaster) lookups are\ndivided into the three categories described in the <a class=\"reference internal\" href=\"#spatial-lookup-raster\"><span class=\"std std-ref\">raster lookup details</span></a>: native support <code class=\"docutils literal notranslate\">N</code>, bilateral native support <code class=\"docutils literal notranslate\">B</code>,\nand geometry conversion support <code class=\"docutils literal notranslate\">C</code>.</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Lookup Type</p></th>\n<th class=\"head\"><p>PostGIS</p></th>\n<th class=\"head\"><p>Oracle</p></th>\n<th class=\"head\"><p>MariaDB</p></th>\n<th class=\"head\"><p>MySQL <a class=\"footnote-reference brackets\" href=\"#id10\" id=\"id9\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>5<span class=\"fn-bracket\">]</span></a></p></th>\n<th class=\"head\"><p>SpatiaLite</p></th>\n<th class=\"head\"><p>PGRaster</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-bbcontains\"><code class=\"xref std std-lookup docutils literal notranslate\">bbcontains</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>N</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-bboverlaps\"><code class=\"xref std std-lookup docutils literal notranslate\">bboverlaps</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>N</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-contained\"><code class=\"xref std std-lookup docutils literal notranslate\">contained</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>N</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-gis-contains\"><code class=\"xref std std-lookup docutils literal notranslate\">contains</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-contains_properly\"><code class=\"xref std std-lookup docutils literal notranslate\">contains_properly</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-coveredby\"><code class=\"xref std std-lookup docutils literal notranslate\">coveredby</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-covers\"><code class=\"xref std std-lookup docutils literal notranslate\">covers</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-crosses\"><code class=\"xref std std-lookup docutils literal notranslate\">crosses</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-disjoint\"><code class=\"xref std std-lookup docutils literal notranslate\">disjoint</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gt\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_gt</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>N</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gte\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_gte</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>N</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lt\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_lt</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>N</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lte\"><code class=\"xref std std-lookup docutils literal notranslate\">distance_lte</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>N</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-dwithin\"><code class=\"xref std std-lookup docutils literal notranslate\">dwithin</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-equals\"><code class=\"xref std std-lookup docutils literal notranslate\">equals</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-same_as\"><code class=\"xref std std-lookup docutils literal notranslate\">exact</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-intersects\"><code class=\"xref std std-lookup docutils literal notranslate\">intersects</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-isvalid\"><code class=\"xref std std-lookup docutils literal notranslate\">isvalid</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X (≥ 5.7.5)</p></td>\n<td><p>X (LWGEOM)</p></td>\n<td></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps\"><code class=\"xref std std-lookup docutils literal notranslate\">overlaps</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-relate\"><code class=\"xref std std-lookup docutils literal notranslate\">relate</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-same_as\"><code class=\"xref std std-lookup docutils literal notranslate\">same_as</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-touches\"><code class=\"xref std std-lookup docutils literal notranslate\">touches</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-within\"><code class=\"xref std std-lookup docutils literal notranslate\">within</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-left\"><code class=\"xref std std-lookup docutils literal notranslate\">left</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-right\"><code class=\"xref std std-lookup docutils literal notranslate\">right</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_left\"><code class=\"xref std std-lookup docutils literal notranslate\">overlaps_left</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_right\"><code class=\"xref std std-lookup docutils literal notranslate\">overlaps_right</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_above\"><code class=\"xref std std-lookup docutils literal notranslate\">overlaps_above</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_below\"><code class=\"xref std std-lookup docutils literal notranslate\">overlaps_below</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-strictly_above\"><code class=\"xref std std-lookup docutils literal notranslate\">strictly_above</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>C</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-strictly_below\"><code class=\"xref std std-lookup docutils literal notranslate\">strictly_below</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>C</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n<section id=\"database-functions\">\n<span id=\"database-functions-compatibility\"></span><h3>Database functions<a class=\"heading-anchor\" href=\"#database-functions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The following table provides a summary of what geography-specific database\nfunctions are available on each spatial backend.</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Function</p></th>\n<th class=\"head\"><p>PostGIS</p></th>\n<th class=\"head\"><p>Oracle</p></th>\n<th class=\"head\"><p>MariaDB</p></th>\n<th class=\"head\"><p>MySQL</p></th>\n<th class=\"head\"><p>SpatiaLite</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Area\" title=\"django.contrib.gis.db.models.functions.Area\"><code class=\"xref py py-class docutils literal notranslate\">Area</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.AsGeoJSON\" title=\"django.contrib.gis.db.models.functions.AsGeoJSON\"><code class=\"xref py py-class docutils literal notranslate\">AsGeoJSON</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X (≥ 10.2.4)</p></td>\n<td><p>X (≥ 5.7.5)</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.AsGML\" title=\"django.contrib.gis.db.models.functions.AsGML\"><code class=\"xref py py-class docutils literal notranslate\">AsGML</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.AsKML\" title=\"django.contrib.gis.db.models.functions.AsKML\"><code class=\"xref py py-class docutils literal notranslate\">AsKML</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.AsSVG\" title=\"django.contrib.gis.db.models.functions.AsSVG\"><code class=\"xref py py-class docutils literal notranslate\">AsSVG</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Azimuth\" title=\"django.contrib.gis.db.models.functions.Azimuth\"><code class=\"xref py py-class docutils literal notranslate\">Azimuth</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X (LWGEOM)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.BoundingCircle\" title=\"django.contrib.gis.db.models.functions.BoundingCircle\"><code class=\"xref py py-class docutils literal notranslate\">BoundingCircle</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Centroid\" title=\"django.contrib.gis.db.models.functions.Centroid\"><code class=\"xref py py-class docutils literal notranslate\">Centroid</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Difference\" title=\"django.contrib.gis.db.models.functions.Difference\"><code class=\"xref py py-class docutils literal notranslate\">Difference</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Distance\" title=\"django.contrib.gis.db.models.functions.Distance\"><code class=\"xref py py-class docutils literal notranslate\">Distance</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Envelope\" title=\"django.contrib.gis.db.models.functions.Envelope\"><code class=\"xref py py-class docutils literal notranslate\">Envelope</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.ForcePolygonCW\" title=\"django.contrib.gis.db.models.functions.ForcePolygonCW\"><code class=\"xref py py-class docutils literal notranslate\">ForcePolygonCW</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.GeoHash\" title=\"django.contrib.gis.db.models.functions.GeoHash\"><code class=\"xref py py-class docutils literal notranslate\">GeoHash</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X (≥ 5.7.5)</p></td>\n<td><p>X (LWGEOM)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Intersection\" title=\"django.contrib.gis.db.models.functions.Intersection\"><code class=\"xref py py-class docutils literal notranslate\">Intersection</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.IsValid\" title=\"django.contrib.gis.db.models.functions.IsValid\"><code class=\"xref py py-class docutils literal notranslate\">IsValid</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X (≥ 5.7.5)</p></td>\n<td><p>X (LWGEOM)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Length\" title=\"django.contrib.gis.db.models.functions.Length\"><code class=\"xref py py-class docutils literal notranslate\">Length</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.LineLocatePoint\" title=\"django.contrib.gis.db.models.functions.LineLocatePoint\"><code class=\"xref py py-class docutils literal notranslate\">LineLocatePoint</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.MakeValid\" title=\"django.contrib.gis.db.models.functions.MakeValid\"><code class=\"xref py py-class docutils literal notranslate\">MakeValid</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X (LWGEOM)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.MemSize\" title=\"django.contrib.gis.db.models.functions.MemSize\"><code class=\"xref py py-class docutils literal notranslate\">MemSize</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.NumGeometries\" title=\"django.contrib.gis.db.models.functions.NumGeometries\"><code class=\"xref py py-class docutils literal notranslate\">NumGeometries</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.NumPoints\" title=\"django.contrib.gis.db.models.functions.NumPoints\"><code class=\"xref py py-class docutils literal notranslate\">NumPoints</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Perimeter\" title=\"django.contrib.gis.db.models.functions.Perimeter\"><code class=\"xref py py-class docutils literal notranslate\">Perimeter</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.PointOnSurface\" title=\"django.contrib.gis.db.models.functions.PointOnSurface\"><code class=\"xref py py-class docutils literal notranslate\">PointOnSurface</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Reverse\" title=\"django.contrib.gis.db.models.functions.Reverse\"><code class=\"xref py py-class docutils literal notranslate\">Reverse</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Scale\" title=\"django.contrib.gis.db.models.functions.Scale\"><code class=\"xref py py-class docutils literal notranslate\">Scale</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.SnapToGrid\" title=\"django.contrib.gis.db.models.functions.SnapToGrid\"><code class=\"xref py py-class docutils literal notranslate\">SnapToGrid</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.SymDifference\" title=\"django.contrib.gis.db.models.functions.SymDifference\"><code class=\"xref py py-class docutils literal notranslate\">SymDifference</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Transform\" title=\"django.contrib.gis.db.models.functions.Transform\"><code class=\"xref py py-class docutils literal notranslate\">Transform</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Translate\" title=\"django.contrib.gis.db.models.functions.Translate\"><code class=\"xref py py-class docutils literal notranslate\">Translate</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Union\" title=\"django.contrib.gis.db.models.functions.Union\"><code class=\"xref py py-class docutils literal notranslate\">Union</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n<section id=\"aggregate-functions\">\n<h3>Aggregate Functions<a class=\"heading-anchor\" href=\"#aggregate-functions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The following table provides a summary of what GIS-specific aggregate functions\nare available on each spatial backend. Please note that MySQL does not\nsupport any of these aggregates, and is thus excluded from the table.</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Aggregate</p></th>\n<th class=\"head\"><p>PostGIS</p></th>\n<th class=\"head\"><p>Oracle</p></th>\n<th class=\"head\"><p>SpatiaLite</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.Collect\" title=\"django.contrib.gis.db.models.Collect\"><code class=\"xref py py-class docutils literal notranslate\">Collect</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.Extent\" title=\"django.contrib.gis.db.models.Extent\"><code class=\"xref py py-class docutils literal notranslate\">Extent</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.Extent3D\" title=\"django.contrib.gis.db.models.Extent3D\"><code class=\"xref py py-class docutils literal notranslate\">Extent3D</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.MakeLine\" title=\"django.contrib.gis.db.models.MakeLine\"><code class=\"xref py py-class docutils literal notranslate\">MakeLine</code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/zh-hans/3.0/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.Union\" title=\"django.contrib.gis.db.models.Union\"><code class=\"xref py py-class docutils literal notranslate\">Union</code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n<p class=\"rubric\">Footnotes</p>\n<aside class=\"footnote-list brackets\">\n<aside class=\"footnote brackets\" id=\"fnwkt\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id4\">1</a><span class=\"fn-bracket\">]</span></span>\n<p><em>See</em> Open Geospatial Consortium, Inc., <a class=\"reference external\" href=\"http://www.opengis.org/docs/99-049.pdf\">OpenGIS Simple Feature Specification For SQL</a>, Document 99-049 (May 5, 1999), at  Ch. 3.2.5, p. 3-11 (SQL Textual Representation of Geometry).</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fnewkb\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id5\">2</a><span class=\"fn-bracket\">]</span></span>\n<p><em>See</em> <a class=\"reference external\" href=\"https://postgis.net/docs/using_postgis_dbmanagement.html#EWKB_EWKT\">PostGIS EWKB, EWKT and Canonical Forms</a>, PostGIS documentation at Ch. 4.1.2.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fndistsphere15\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id7\">3</a><span class=\"fn-bracket\">]</span></span>\n<p><em>See</em> <a class=\"reference external\" href=\"https://postgis.net/docs/ST_DistanceSphere.html\">PostGIS documentation</a> on <code class=\"docutils literal notranslate\">ST_DistanceSphere</code>.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fnmysqlidx\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id3\">4</a><span class=\"fn-bracket\">]</span></span>\n<p><em>See</em> <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/creating-spatial-indexes.html\">Creating Spatial Indexes</a>\nin the MySQL Reference Manual:</p>\n<blockquote>\n<div><p>For MyISAM tables, <code class=\"docutils literal notranslate\">SPATIAL INDEX</code> creates an R-tree index. For storage\nengines that support nonspatial indexing of spatial columns, the engine\ncreates a B-tree index. A B-tree index on spatial values will be useful\nfor exact-value lookups, but not for range scans.</p>\n</div></blockquote>\n</aside>\n<aside class=\"footnote brackets\" id=\"id10\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id9\">5</a><span class=\"fn-bracket\">]</span></span>\n<p>Refer <a class=\"reference internal\" href=\"#mysql-spatial-limitations\"><span class=\"std std-ref\">MySQL Spatial Limitations</span></a> section for more details.</p>\n</aside>\n</aside>\n</section>\n</section>","rootId":"geodjango-database-api","toc":[{"title":"Spatial Backends","anchor":"module-django.contrib.gis.db.backends","children":[{"title":"MySQL Spatial Limitations","anchor":"mysql-spatial-limitations","children":[]},{"title":"Raster Support","anchor":"raster-support","children":[]}]},{"title":"Creating and Saving Models with Geometry Fields","anchor":"creating-and-saving-models-with-geometry-fields","children":[]},{"title":"Creating and Saving Models with Raster Fields","anchor":"creating-and-saving-models-with-raster-fields","children":[]},{"title":"Spatial Lookups","anchor":"spatial-lookups","children":[{"title":"Geometry Lookups","anchor":"geometry-lookups","children":[]},{"title":"Raster Lookups","anchor":"raster-lookups","children":[]}]},{"title":"Distance Queries","anchor":"distance-queries","children":[{"title":"介绍","anchor":"introduction","children":[]},{"title":"Distance Lookups","anchor":"distance-lookups","children":[]}]},{"title":"Compatibility Tables","anchor":"compatibility-tables","children":[{"title":"Spatial Lookups","anchor":"spatial-lookup-compatibility","children":[]},{"title":"Database functions","anchor":"database-functions","children":[]},{"title":"Aggregate Functions","anchor":"aggregate-functions","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API参考","url":"/zh-hans/3.0/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/zh-hans/3.0/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/zh-hans/3.0/ref/contrib/gis/"}],"prev":{"docname":"ref/contrib/gis/model-api","title":"GeoDjango Model API","url":"/zh-hans/3.0/ref/contrib/gis/model-api/"},"next":{"docname":"ref/contrib/gis/forms-api","title":"GeoDjango Forms API","url":"/zh-hans/3.0/ref/contrib/gis/forms-api/"},"formats":{"html":"/zh-hans/3.0/ref/contrib/gis/db-api/","markdown":"/zh-hans/3.0/ref/contrib/gis/db-api.md","json":"/zh-hans/3.0/ref/contrib/gis/db-api.json"},"source":"https://github.com/django/django/blob/stable/3.0.x/docs/ref/contrib/gis/db-api.txt","official":"https://docs.djangoproject.com/zh-hans/3.0/ref/contrib/gis/db-api/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}