{"title":"GeoDjango Database API","version":"6.0","locale":"en","docname":"ref/contrib/gis/db-api","url":"/en/6.0/ref/contrib/gis/db-api/","canonical":"https://djangodocs.dev/en/6.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\"><span class=\"pre\">django.contrib.gis.db.backends.postgis</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.gis.db.backends.mysql</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.gis.db.backends.oracle</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.gis.db.backends.spatialite</span></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>Django supports spatial functions operating on real geometries available in\nmodern MySQL versions. However, the spatial functions are not as rich as other\nbackends like PostGIS.</p>\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\"><span class=\"pre\">RasterField</span></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\"><span class=\"pre\">Zipcode</span></code>\nmodel):</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">zipcode.models</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">Zipcode</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">z</span> <span class=\"o\">=</span> <span class=\"n\">Zipcode</span><span class=\"p\">(</span><span class=\"n\">code</span><span class=\"o\">=</span><span class=\"mi\">77096</span><span class=\"p\">,</span> <span class=\"n\">poly</span><span class=\"o\">=</span><span class=\"s2\">&quot;POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">z</span><span class=\"o\">.</span><span class=\"n\">save</span><span class=\"p\">()</span>\n</code></pre></div>\n<p><a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GEOSGeometry</span></code></a> objects may also be used to save\ngeometric models:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.gis.geos</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">GEOSGeometry</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">poly</span> <span class=\"o\">=</span> <span class=\"n\">GEOSGeometry</span><span class=\"p\">(</span><span class=\"s2\">&quot;POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">z</span> <span class=\"o\">=</span> <span class=\"n\">Zipcode</span><span class=\"p\">(</span><span class=\"n\">code</span><span class=\"o\">=</span><span class=\"mi\">77096</span><span class=\"p\">,</span> <span class=\"n\">poly</span><span class=\"o\">=</span><span class=\"n\">poly</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">z</span><span class=\"o\">.</span><span class=\"n\">save</span><span class=\"p\">()</span>\n</code></pre></div>\n<p>Moreover, if the <code class=\"docutils literal notranslate\"><span class=\"pre\">GEOSGeometry</span></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=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">poly_3084</span> <span class=\"o\">=</span> <span class=\"n\">GEOSGeometry</span><span class=\"p\">(</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))&quot;</span><span class=\"p\">,</span> <span class=\"n\">srid</span><span class=\"o\">=</span><span class=\"mi\">3084</span>\n<span class=\"gp\">... </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><span class=\"n\">z</span> <span class=\"o\">=</span> <span class=\"n\">Zipcode</span><span class=\"p\">(</span><span class=\"n\">code</span><span class=\"o\">=</span><span class=\"mi\">78212</span><span class=\"p\">,</span> <span class=\"n\">poly</span><span class=\"o\">=</span><span class=\"n\">poly_3084</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">z</span><span class=\"o\">.</span><span class=\"n\">save</span><span class=\"p\">()</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.db</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">connection</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"nb\">print</span><span class=\"p\">(</span>\n<span class=\"gp\">... </span>    <span class=\"n\">connection</span><span class=\"o\">.</span><span class=\"n\">queries</span><span class=\"p\">[</span><span class=\"o\">-</span><span class=\"mi\">1</span><span class=\"p\">][</span><span class=\"s2\">&quot;sql&quot;</span><span class=\"p\">]</span>\n<span class=\"gp\">... </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\"><span class=\"pre\">GEOSGeometry</span></code> object,\nWKT (Well Known Text <a class=\"footnote-reference brackets\" href=\"#fnwkt\" id=\"id3\" 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=\"id4\" 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\"><span class=\"pre\">GEOSGeometry</span></code> object, the geometry field will attempt to\ncreate a <code class=\"docutils literal notranslate\"><span class=\"pre\">GEOSGeometry</span></code> instance from the input.</p>\n<p>For more information creating <a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GEOSGeometry</span></code></a>\nobjects, refer to the <a class=\"reference internal\" href=\"/en/6.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=\"/en/6.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\"><span class=\"pre\">GDALRaster</span></code></a> using lazy-evaluation.\nThe raster field will therefore accept any input that is accepted by the\n<a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GDALRaster</span></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\"><span class=\"pre\">volcano.tif</span></code> (assuming the <code class=\"docutils literal notranslate\"><span class=\"pre\">Elevation</span></code> model):</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">elevation.models</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">Elevation</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">dem</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"p\">(</span><span class=\"n\">name</span><span class=\"o\">=</span><span class=\"s2\">&quot;Volcano&quot;</span><span class=\"p\">,</span> <span class=\"n\">rast</span><span class=\"o\">=</span><span class=\"s2\">&quot;/path/to/raster/volcano.tif&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">dem</span><span class=\"o\">.</span><span class=\"n\">save</span><span class=\"p\">()</span>\n</code></pre></div>\n<p><a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GDALRaster</span></code></a> objects may also be used to save\nraster models:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.gis.gdal</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">GDALRaster</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">rast</span> <span class=\"o\">=</span> <span class=\"n\">GDALRaster</span><span class=\"p\">(</span>\n<span class=\"gp\">... </span>    <span class=\"p\">{</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;width&quot;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;height&quot;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;name&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Canyon&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;srid&quot;</span><span class=\"p\">:</span> <span class=\"mi\">4326</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;scale&quot;</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>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;bands&quot;</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<span class=\"gp\">... </span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">dem</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"p\">(</span><span class=\"n\">name</span><span class=\"o\">=</span><span class=\"s2\">&quot;Canyon&quot;</span><span class=\"p\">,</span> <span class=\"n\">rast</span><span class=\"o\">=</span><span class=\"n\">rast</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">dem</span><span class=\"o\">.</span><span class=\"n\">save</span><span class=\"p\">()</span>\n</code></pre></div>\n<p>Note that this is equivalent to:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">dem</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">create</span><span class=\"p\">(</span>\n<span class=\"gp\">... </span>    <span class=\"n\">name</span><span class=\"o\">=</span><span class=\"s2\">&quot;Canyon&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"n\">rast</span><span class=\"o\">=</span><span class=\"p\">{</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;width&quot;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;height&quot;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;name&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Canyon&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;srid&quot;</span><span class=\"p\">:</span> <span class=\"mi\">4326</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;scale&quot;</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>\n<span class=\"gp\">... </span>        <span class=\"s2\">&quot;bands&quot;</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<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\"><span class=\"pre\">filter()</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">exclude()</span></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=\"/en/6.0/ref/models/fields/#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CharField</span></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 in\nmost cases. However, unlike assignments to model fields, with lookups,\ntypes such as <code class=\"docutils literal notranslate\"><span class=\"pre\">str</span></code>, <a class=\"reference external\" href=\"https://docs.python.org/3/library/pathlib.html#pathlib.Path\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">pathlib.Path</span></code></a>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">dict</span></code> must be wrapped by\n<a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GDALRaster</span></code></a> to signify that the potential for\nfile writing or network fetching is acceptable. For the rationale, see\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/gdal/#raster-security\"><span class=\"std std-ref\">raster security considerations</span></a>.</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=\"/en/6.0/ref/contrib/gis/geoquerysets/#spatial-lookups\"><span class=\"std std-ref\">spatial lookup reference</span></a>.</p>\n<aside class=\"version-note version-changed\" data-version=\"5.2.17\">\n<p class=\"version-note-title\">Changed in Django 5.2.17</p><p>In earlier versions, spatial lookups accepted <code class=\"docutils literal notranslate\"><span class=\"pre\">str</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">dict</span></code> types\nfor new rasters, allowing file writes and network fetches.</p>\n</aside>\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\"><span class=\"pre\">Zipcode</span></code> model used in the <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/model-api/\"><span class=\"doc\">GeoDjango Model API</span></a>):</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</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=\"Text code\"><code>&gt;&gt;&gt; qs = Zipcode.objects.filter(&lt;field&gt;__&lt;lookup_type&gt;=&lt;parameter&gt;)\n&gt;&gt;&gt; qs = Zipcode.objects.exclude(...)\n</code></pre></div>\n<p>For example:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">Zipcode</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">poly__contains</span><span class=\"o\">=</span><span class=\"n\">pnt</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">poly__contains</span><span class=\"o\">=</span><span class=\"n\">rst</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>In this case, <code class=\"docutils literal notranslate\"><span class=\"pre\">poly</span></code> is the geographic field,\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-gis-contains\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">contains</span></code></a> is the spatial lookup type, <code class=\"docutils literal notranslate\"><span class=\"pre\">pnt</span></code> is the\nparameter (which may be a <a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GEOSGeometry</span></code></a> object\nor a string of GeoJSON , WKT, or HEXEWKB), and <code class=\"docutils literal notranslate\"><span class=\"pre\">rst</span></code> is a\n<a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GDALRaster</span></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\nband index is specified, the first band is used by default (index <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code>). In\nthat case 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\"><span class=\"pre\">Elevation</span></code> model used in the\n<a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/model-api/\"><span class=\"doc\">GeoDjango Model API</span></a>):</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</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=\"Text code\"><code>&gt;&gt;&gt; qs = Elevation.objects.filter(&lt;field&gt;__&lt;lookup_type&gt;=&lt;parameter&gt;)\n&gt;&gt;&gt; qs = Elevation.objects.filter(&lt;field&gt;__&lt;band_index&gt;__&lt;lookup_type&gt;=&lt;parameter&gt;)\n&gt;&gt;&gt; qs = Elevation.objects.filter(&lt;field&gt;__&lt;lookup_type&gt;=(&lt;raster_input, &lt;band_index&gt;)\n</code></pre></div>\n<p>For example:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">rast__contains</span><span class=\"o\">=</span><span class=\"n\">geom</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">rast__contains</span><span class=\"o\">=</span><span class=\"n\">rst</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">rast__1__contains</span><span class=\"o\">=</span><span class=\"n\">geom</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">rast__contains</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"n\">rst</span><span class=\"p\">,</span> <span class=\"mi\">1</span><span class=\"p\">))</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">Elevation</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">rast__1__contains</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"n\">rst</span><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\"><span class=\"pre\">rast</span></code> is the geographic raster field\nand <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-gis-contains\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">contains</span></code></a> is the spatial lookup type. On the right\nhand side, <code class=\"docutils literal notranslate\"><span class=\"pre\">geom</span></code> is a geometry input and <code class=\"docutils literal notranslate\"><span class=\"pre\">rst</span></code> is a\n<a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">GDALRaster</span></code></a> object. The band index defaults to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code> in the first two queries and is set to <code class=\"docutils literal notranslate\"><span class=\"pre\">1</span></code> on the others.</p>\n<p>While all spatial lookups can be used with raster objects on both sides, not\nall underlying operators natively accept raster input. For cases where the\noperator expects geometry input, the raster is automatically converted to a\ngeometry. It’s important to keep this in mind when interpreting the lookup\nresults.</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=\"id5\"></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>Introduction<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, the\nEarth is not flat. Some distance queries with fields in a geographic coordinate\nsystem may have to be expressed differently because of limitations in PostGIS.\nPlease see the <a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/model-api/#selecting-an-srid\"><span class=\"std std-ref\">Selecting an SRID</span></a> section 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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lt\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_lt</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lte\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_lte</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gt\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_gt</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gte\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_gte</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-dwithin\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">dwithin</span></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=\"/en/6.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\"><span class=\"pre\">Distance</span></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=\"/en/6.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\"><span class=\"pre\">Distance</span></code></a> object containing\nthe distance.</p></li>\n</ol>\n<p>If a <a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">Distance</span></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\"><span class=\"pre\">ST_Distance_Sphere</span></code> does <em>not</em> limit the geometry types\ngeographic distance queries are performed with. <a class=\"footnote-reference brackets\" href=\"#fndistsphere15\" id=\"id6\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>3<span class=\"fn-bracket\">]</span></a>\nHowever, these queries may take a long time, as great-circle distances must\nbe calculated 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=\"/en/6.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\n<code class=\"docutils literal notranslate\"><span class=\"pre\">geography=True</span></code> in your field definition.</p>\n</aside>\n<p>For example, let’s say we have a <code class=\"docutils literal notranslate\"><span class=\"pre\">SouthTexasCity</span></code> model (from the\n<a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/6.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=\"w\"> </span><span class=\"nn\">django.contrib.gis.db</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">models</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">SouthTexasCity</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">name</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">max_length</span><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    <span class=\"n\">point</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">PointField</span><span class=\"p\">(</span><span class=\"n\">srid</span><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=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.gis.geos</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">GEOSGeometry</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.gis.measure</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">D</span>  <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=\"w\"> </span><span class=\"nn\">geoapp.models</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">SouthTexasCity</span>\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><span class=\"n\">pnt</span> <span class=\"o\">=</span> <span class=\"n\">GEOSGeometry</span><span class=\"p\">(</span><span class=\"s2\">&quot;POINT(-96.876369 29.905320)&quot;</span><span class=\"p\">,</span> <span class=\"n\">srid</span><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><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">SouthTexasCity</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">point__distance_lte</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"n\">pnt</span><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><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">SouthTexasCity</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">point__distance_lte</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"n\">pnt</span><span class=\"p\">,</span> <span class=\"n\">D</span><span class=\"p\">(</span><span class=\"n\">km</span><span class=\"o\">=</span><span class=\"mi\">7</span><span class=\"p\">)))</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">SouthTexasCity</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">point__distance_gte</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"n\">pnt</span><span class=\"p\">,</span> <span class=\"n\">D</span><span class=\"p\">(</span><span class=\"n\">mi</span><span class=\"o\">=</span><span class=\"mi\">20</span><span class=\"p\">)))</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">SouthTexasCity</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">point__distance_gte</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"n\">pnt</span><span class=\"p\">,</span> <span class=\"n\">D</span><span class=\"p\">(</span><span class=\"n\">chain</span><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\"><span class=\"pre\">point</span></code> with\na raster field, or the <code class=\"docutils literal notranslate\"><span class=\"pre\">pnt</span></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=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">qs</span> <span class=\"o\">=</span> <span class=\"n\">SouthTexasCity</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">point__distance_gte</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"n\">rst</span><span class=\"p\">,</span> <span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"n\">D</span><span class=\"p\">(</span><span class=\"n\">km</span><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\"><span class=\"pre\">rst</span></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=\"id7\"></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\"><span class=\"pre\">N</span></code>, bilateral native support <code class=\"docutils literal notranslate\"><span class=\"pre\">B</span></code>,\nand geometry conversion support <code class=\"docutils literal notranslate\"><span class=\"pre\">C</span></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=\"#id9\" id=\"id8\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>4<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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-bbcontains\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">bbcontains</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-bboverlaps\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">bboverlaps</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-contained\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">contained</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-gis-contains\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">contains</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-contains_properly\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">contains_properly</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-coveredby\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">coveredby</span></code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X (≥ 12.0.1)</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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-covers\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">covers</span></code></a></p></td>\n<td><p>X</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>B</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-crosses\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">crosses</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-disjoint\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">disjoint</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gt\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_gt</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_gte\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_gte</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lt\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_lt</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-distance_lte\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">distance_lte</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-dwithin\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">dwithin</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-equals\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">equals</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-same_as\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">exact</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-geom_type\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">geom_type</span></code></a></p></td>\n<td><p>X</p></td>\n<td><p>X (≥ 23c)</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-intersects\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">intersects</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-isempty\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">isempty</span></code></a></p></td>\n<td><p>X</p></td>\n<td></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-isvalid\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">isvalid</span></code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X (≥ 12.0.1)</p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">overlaps</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-relate\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">relate</span></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<td><p>C</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-same_as\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">same_as</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-touches\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">touches</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-within\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">within</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-left\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">left</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-right\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">right</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_left\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">overlaps_left</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_right\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">overlaps_right</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_above\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">overlaps_above</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-overlaps_below\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">overlaps_below</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-strictly_above\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">strictly_above</span></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=\"/en/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-strictly_below\"><code class=\"xref std std-lookup docutils literal notranslate\"><span class=\"pre\">strictly_below</span></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=\"/en/6.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\"><span class=\"pre\">Area</span></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=\"/en/6.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\"><span class=\"pre\">AsGeoJSON</span></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=\"/en/6.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\"><span class=\"pre\">AsGML</span></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=\"/en/6.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\"><span class=\"pre\">AsKML</span></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=\"/en/6.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\"><span class=\"pre\">AsSVG</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.AsWKB\" title=\"django.contrib.gis.db.models.functions.AsWKB\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AsWKB</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.AsWKT\" title=\"django.contrib.gis.db.models.functions.AsWKT\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AsWKT</span></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=\"/en/6.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\"><span class=\"pre\">Azimuth</span></code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X (LWGEOM/RTTOPO)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">BoundingCircle</span></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 (≥ 5.1)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">Centroid</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.ClosestPoint\" title=\"django.contrib.gis.db.models.functions.ClosestPoint\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ClosestPoint</span></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=\"/en/6.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\"><span class=\"pre\">Difference</span></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=\"/en/6.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\"><span class=\"pre\">Distance</span></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=\"/en/6.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\"><span class=\"pre\">Envelope</span></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=\"/en/6.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\"><span class=\"pre\">ForcePolygonCW</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.FromWKB\" title=\"django.contrib.gis.db.models.functions.FromWKB\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FromWKB</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.FromWKT\" title=\"django.contrib.gis.db.models.functions.FromWKT\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FromWKT</span></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=\"/en/6.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\"><span class=\"pre\">GeoHash</span></code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X (≥ 12.0.1)</p></td>\n<td><p>X</p></td>\n<td><p>X (LWGEOM/RTTOPO)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.GeometryDistance\" title=\"django.contrib.gis.db.models.functions.GeometryDistance\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">GeometryDistance</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.GeometryType\" title=\"django.contrib.gis.db.models.functions.GeometryType\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">GeometryType</span></code></a></p></td>\n<td><p>X</p></td>\n<td><p>X (≥ 23c)</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=\"/en/6.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\"><span class=\"pre\">Intersection</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.IsEmpty\" title=\"django.contrib.gis.db.models.functions.IsEmpty\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">IsEmpty</span></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-even\"><td><p><a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">IsValid</span></code></a></p></td>\n<td><p>X</p></td>\n<td><p>X</p></td>\n<td><p>X (≥ 12.0.1)</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=\"/en/6.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\"><span class=\"pre\">Length</span></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=\"/en/6.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\"><span class=\"pre\">LineLocatePoint</span></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=\"/en/6.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\"><span class=\"pre\">MakeValid</span></code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td></td>\n<td></td>\n<td><p>X (LWGEOM/RTTOPO)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">MemSize</span></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=\"/en/6.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\"><span class=\"pre\">NumGeometries</span></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=\"/en/6.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\"><span class=\"pre\">NumPoints</span></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=\"/en/6.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\"><span class=\"pre\">Perimeter</span></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=\"/en/6.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\"><span class=\"pre\">PointOnSurface</span></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=\"/en/6.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\"><span class=\"pre\">Reverse</span></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=\"/en/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.Rotate\" title=\"django.contrib.gis.db.models.functions.Rotate\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Rotate</span></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=\"/en/6.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\"><span class=\"pre\">Scale</span></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=\"/en/6.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\"><span class=\"pre\">SnapToGrid</span></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=\"/en/6.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\"><span class=\"pre\">SymDifference</span></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=\"/en/6.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\"><span class=\"pre\">Transform</span></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=\"/en/6.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\"><span class=\"pre\">Translate</span></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=\"/en/6.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\"><span class=\"pre\">Union</span></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.</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>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=\"/en/6.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\"><span class=\"pre\">Collect</span></code></a></p></td>\n<td><p>X</p></td>\n<td></td>\n<td><p>X (≥ 12.0.1)</p></td>\n<td><p>X (≥ 8.0.24)</p></td>\n<td><p>X</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/en/6.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\"><span class=\"pre\">Extent</span></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=\"/en/6.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\"><span class=\"pre\">Extent3D</span></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=\"/en/6.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\"><span class=\"pre\">MakeLine</span></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=\"/en/6.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\"><span class=\"pre\">Union</span></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</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=\"#id3\">1</a><span class=\"fn-bracket\">]</span></span>\n<p><em>See</em> Open Geospatial Consortium, Inc., <a class=\"reference external\" href=\"https://portal.ogc.org/files/?artifact_id=829\">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=\"#id4\">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=\"#id6\">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\"><span class=\"pre\">ST_DistanceSphere</span></code>.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"id9\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id8\">4</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":"Introduction","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 Reference","url":"/en/6.0/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/en/6.0/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/en/6.0/ref/contrib/gis/"}],"prev":{"docname":"ref/contrib/gis/model-api","title":"GeoDjango Model API","url":"/en/6.0/ref/contrib/gis/model-api/"},"next":{"docname":"ref/contrib/gis/forms-api","title":"GeoDjango Forms API","url":"/en/6.0/ref/contrib/gis/forms-api/"},"formats":{"html":"/en/6.0/ref/contrib/gis/db-api/","markdown":"/en/6.0/ref/contrib/gis/db-api.md","json":"/en/6.0/ref/contrib/gis/db-api.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/ref/contrib/gis/db-api.txt","official":"https://docs.djangoproject.com/en/6.0/ref/contrib/gis/db-api/","inVersions":["dev","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","1.11","1.10","1.9","1.8"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}