{"title":"GeoDjango Model API","version":"1.8","locale":"en","docname":"ref/contrib/gis/model-api","url":"/en/1.8/ref/contrib/gis/model-api/","canonical":"https://djangodocs.dev/en/1.8/ref/contrib/gis/model-api/","summary":"This document explores the details of the GeoDjango Model API.","html":"<span id=\"geodjango-model-api\"></span><h1>GeoDjango Model API<a class=\"heading-anchor\" href=\"#module-django.contrib.gis.db.models\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This document explores the details of the GeoDjango Model API.  Throughout this\nsection, we’ll be using the following geographic model of a <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/ZIP_code\">ZIP code</a> as our\nexample:</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\">Zipcode</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    code <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">5</span><span class=\"p\">)</span>\n    poly <span class=\"o\">=</span> models<span class=\"o\">.</span>PolygonField<span class=\"p\">()</span>\n    objects <span class=\"o\">=</span> models<span class=\"o\">.</span>GeoManager<span class=\"p\">()</span>\n</code></pre></div>\n<section id=\"geometry-field-types\">\n<h2>Geometry Field Types<a class=\"heading-anchor\" href=\"#geometry-field-types\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Each of the following geometry field types correspond with the\nOpenGIS Simple Features specification <a class=\"footnote-reference brackets\" href=\"#fnogc\" id=\"id2\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>1<span class=\"fn-bracket\">]</span></a>.</p>\n<section id=\"geometryfield\">\n<h3><code class=\"docutils literal notranslate\">GeometryField</code><a class=\"heading-anchor\" href=\"#geometryfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.GeometryField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">GeometryField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.GeometryField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n<section id=\"pointfield\">\n<h3><code class=\"docutils literal notranslate\">PointField</code><a class=\"heading-anchor\" href=\"#pointfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.PointField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">PointField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.PointField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n<section id=\"linestringfield\">\n<h3><code class=\"docutils literal notranslate\">LineStringField</code><a class=\"heading-anchor\" href=\"#linestringfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.LineStringField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">LineStringField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.LineStringField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n<section id=\"polygonfield\">\n<h3><code class=\"docutils literal notranslate\">PolygonField</code><a class=\"heading-anchor\" href=\"#polygonfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.PolygonField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">PolygonField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.PolygonField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n<section id=\"multipointfield\">\n<h3><code class=\"docutils literal notranslate\">MultiPointField</code><a class=\"heading-anchor\" href=\"#multipointfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.MultiPointField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">MultiPointField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.MultiPointField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n<section id=\"multilinestringfield\">\n<h3><code class=\"docutils literal notranslate\">MultiLineStringField</code><a class=\"heading-anchor\" href=\"#multilinestringfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.MultiLineStringField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">MultiLineStringField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.MultiLineStringField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n<section id=\"multipolygonfield\">\n<h3><code class=\"docutils literal notranslate\">MultiPolygonField</code><a class=\"heading-anchor\" href=\"#multipolygonfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.MultiPolygonField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">MultiPolygonField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.MultiPolygonField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n<section id=\"geometrycollectionfield\">\n<h3><code class=\"docutils literal notranslate\">GeometryCollectionField</code><a class=\"heading-anchor\" href=\"#geometrycollectionfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.GeometryCollectionField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">GeometryCollectionField</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.GeometryCollectionField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n</section>\n</section>\n<section id=\"geometry-field-options\">\n<span id=\"id3\"></span><h2>Geometry Field Options<a class=\"heading-anchor\" href=\"#geometry-field-options\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In addition to the regular <a class=\"reference internal\" href=\"/en/1.8/ref/models/fields/#common-model-field-options\"><span class=\"std std-ref\">Field options</span></a> available for\nDjango model fields, geometry fields have the following additional options.\nAll are optional.</p>\n<section id=\"srid\">\n<h3><code class=\"docutils literal notranslate\">srid</code><a class=\"heading-anchor\" href=\"#srid\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.GeometryField.srid\">\n<span class=\"sig-prename descclassname\">GeometryField.</span><span class=\"sig-name descname\">srid</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.GeometryField.srid\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sets the SRID <a class=\"footnote-reference brackets\" href=\"#fnogcsrid\" id=\"id4\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>2<span class=\"fn-bracket\">]</span></a> (Spatial Reference System Identity) of the geometry field to\nthe given value. Defaults to 4326 (also known as <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/WGS84\">WGS84</a>, units are in degrees\nof longitude and latitude).</p>\n<section id=\"selecting-an-srid\">\n<span id=\"id6\"></span><h4>Selecting an SRID<a class=\"heading-anchor\" href=\"#selecting-an-srid\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Choosing an appropriate SRID for your model is an important decision that the\ndeveloper should consider carefully.  The SRID is an integer specifier that\ncorresponds to the projection system that will be used to interpret the data\nin the spatial database. <a class=\"footnote-reference brackets\" href=\"#fnsrid\" id=\"id7\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>3<span class=\"fn-bracket\">]</span></a>  Projection systems give the context to the\ncoordinates that specify a location.  Although the details of <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Geodesy\">geodesy</a> are\nbeyond the scope of this documentation, the general problem is that the earth\nis spherical and representations of the earth (e.g., paper maps, Web maps)\nare not.</p>\n<p>Most people are familiar with using latitude and longitude to reference a\nlocation on the earth’s surface.  However, latitude and longitude are angles,\nnot distances. <a class=\"footnote-reference brackets\" href=\"#fnharvard\" id=\"id8\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>4<span class=\"fn-bracket\">]</span></a>  In other words, while the shortest path between two points on\na flat surface is a straight line, the shortest path between two points on a curved\nsurface (such as the earth) is an <em>arc</em> of a <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Great_circle\">great circle</a>. <a class=\"footnote-reference brackets\" href=\"#fnthematic\" id=\"id9\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>5<span class=\"fn-bracket\">]</span></a>  Thus,\nadditional computation is required to obtain distances in planar units (e.g.,\nkilometers and miles).  Using a geographic coordinate system may introduce\ncomplications for the developer later on. For example, Spatialite does not have\nthe capability to perform distance calculations between geometries using\ngeographic coordinate systems, e.g. constructing a query to  find all points\nwithin 5 miles of a county boundary stored as WGS84.\n<a class=\"footnote-reference brackets\" href=\"#fndist\" id=\"id10\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>6<span class=\"fn-bracket\">]</span></a></p>\n<p>Portions of the earth’s surface may projected onto a two-dimensional, or\nCartesian, plane.  Projected coordinate systems are especially convenient\nfor region-specific applications, e.g., if you know that your database will\nonly cover geometries in <a class=\"reference external\" href=\"http://www.spatialreference.org/ref/epsg/2796/\">North Kansas</a>, then you may consider using projection\nsystem specific to that region.  Moreover, projected coordinate systems are\ndefined in Cartesian units (such as meters or feet), easing distance\ncalculations.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>If you wish to perform arbitrary distance queries using non-point\ngeometries in WGS84 in PostGIS and you want decent performance, enable the\n<a class=\"reference internal\" href=\"#django.contrib.gis.db.models.GeometryField.geography\" title=\"django.contrib.gis.db.models.GeometryField.geography\"><code class=\"xref py py-attr docutils literal notranslate\">GeometryField.geography</code></a> keyword so that <a class=\"reference internal\" href=\"#geography-type\"><span class=\"std std-ref\">geography database\ntype</span></a> is used instead.</p>\n</aside>\n<p>Additional Resources:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference external\" href=\"http://spatialreference.org/\">spatialreference.org</a>: A Django-powered database of spatial reference\nsystems.</p></li>\n<li><p><a class=\"reference external\" href=\"http://web.archive.org/web/20080302095452/http://welcome.warnercnr.colostate.edu/class_info/nr502/lg3/datums_coordinates/spcs.html\">The State Plane Coordinate System</a>: A Web site covering the various\nprojection systems used in the United States.  Much of the U.S. spatial\ndata encountered will be in one of these coordinate systems rather than\nin a geographic coordinate system such as WGS84.</p></li>\n</ul>\n</section>\n</section>\n<section id=\"spatial-index\">\n<h3><code class=\"docutils literal notranslate\">spatial_index</code><a class=\"heading-anchor\" href=\"#spatial-index\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.GeometryField.spatial_index\">\n<span class=\"sig-prename descclassname\">GeometryField.</span><span class=\"sig-name descname\">spatial_index</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.GeometryField.spatial_index\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Defaults to <code class=\"docutils literal notranslate\">True</code>.  Creates a spatial index for the given geometry\nfield.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>This is different from the <code class=\"docutils literal notranslate\">db_index</code> field option because spatial\nindexes are created in a different manner than regular database\nindexes.  Specifically, spatial indexes are typically created using\na variant of the R-Tree, while regular database indexes typically\nuse B-Trees.</p>\n</aside>\n</section>\n<section id=\"dim\">\n<h3><code class=\"docutils literal notranslate\">dim</code><a class=\"heading-anchor\" href=\"#dim\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.GeometryField.dim\">\n<span class=\"sig-prename descclassname\">GeometryField.</span><span class=\"sig-name descname\">dim</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.GeometryField.dim\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>This option may be used for customizing the coordinate dimension of the\ngeometry field.  By default, it is set to 2, for representing two-dimensional\ngeometries.  For spatial backends that support it, it may be set to 3 for\nthree-dimensional support.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>At this time 3D support is limited to the PostGIS spatial backend.</p>\n</aside>\n</section>\n<section id=\"geography\">\n<h3><code class=\"docutils literal notranslate\">geography</code><a class=\"heading-anchor\" href=\"#geography\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.GeometryField.geography\">\n<span class=\"sig-prename descclassname\">GeometryField.</span><span class=\"sig-name descname\">geography</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.GeometryField.geography\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>If set to <code class=\"docutils literal notranslate\">True</code>, this option will create a database column of\ntype geography, rather than geometry.  Please refer to the\n<a class=\"reference internal\" href=\"#geography-type\"><span class=\"std std-ref\">geography type</span></a> section below for more\ndetails.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Geography support is limited to PostGIS and will force the SRID to be 4326.</p>\n</aside>\n<section id=\"geography-type\">\n<span id=\"id16\"></span><h4>Geography Type<a class=\"heading-anchor\" href=\"#geography-type\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The geography type provides native support for spatial features represented\nwith geographic coordinates (e.g., WGS84 longitude/latitude). <a class=\"footnote-reference brackets\" href=\"#fngeography\" id=\"id17\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>7<span class=\"fn-bracket\">]</span></a>\nUnlike the plane used by a geometry type, the geography type uses a spherical\nrepresentation of its data.  Distance and measurement operations\nperformed on a geography column automatically employ great circle arc\ncalculations and return linear units.  In other words, when <code class=\"docutils literal notranslate\">ST_Distance</code>\nis called on two geographies, a value in meters is returned (as opposed\nto degrees if called on a geometry column in WGS84).</p>\n<p>Because geography calculations involve more mathematics, only a subset of the\nPostGIS spatial lookups are available for the geography type. Practically,\nthis means that in addition to the <a class=\"reference internal\" href=\"/en/1.8/ref/contrib/gis/geoquerysets/#distance-lookups\"><span class=\"std std-ref\">distance lookups</span></a>\nonly the following additional <a class=\"reference internal\" href=\"/en/1.8/ref/contrib/gis/geoquerysets/#spatial-lookups\"><span class=\"std std-ref\">spatial lookups</span></a> are\navailable for geography columns:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/en/1.8/ref/contrib/gis/geoquerysets/#std-fieldlookup-bboverlaps\"><code class=\"xref std std-lookup docutils literal notranslate\">bboverlaps</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/1.8/ref/contrib/gis/geoquerysets/#std-fieldlookup-coveredby\"><code class=\"xref std std-lookup docutils literal notranslate\">coveredby</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/1.8/ref/contrib/gis/geoquerysets/#std-fieldlookup-covers\"><code class=\"xref std std-lookup docutils literal notranslate\">covers</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/en/1.8/ref/contrib/gis/geoquerysets/#std-fieldlookup-intersects\"><code class=\"xref std std-lookup docutils literal notranslate\">intersects</code></a></p></li>\n</ul>\n<p>For more information, the PostGIS documentation contains a helpful section on\ndetermining <a class=\"reference external\" href=\"http://postgis.net/docs/manual-2.1/using_postgis_dbmanagement.html#PostGIS_GeographyVSGeometry\">when to use geography data type over geometry data type</a>.</p>\n</section>\n</section>\n</section>\n<section id=\"geomanager\">\n<h2><code class=\"docutils literal notranslate\">GeoManager</code><a class=\"heading-anchor\" href=\"#geomanager\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.gis.db.models.GeoManager\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">GeoManager</span><a class=\"heading-anchor\" href=\"#django.contrib.gis.db.models.GeoManager\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>In order to conduct geographic queries, each geographic model requires\na <code class=\"docutils literal notranslate\">GeoManager</code> model manager.  This manager allows for the proper SQL\nconstruction for geographic queries; thus, without it, all geographic filters\nwill fail.  It should also be noted that <code class=\"docutils literal notranslate\">GeoManager</code> is required even if the\nmodel does not have a geographic field itself, e.g., in the case of a\n<code class=\"docutils literal notranslate\">ForeignKey</code> relation to a model with a geographic field.  For example,\nif we had an <code class=\"docutils literal notranslate\">Address</code> model with a <code class=\"docutils literal notranslate\">ForeignKey</code> to our <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=\"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\">Address</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    num <span class=\"o\">=</span> models<span class=\"o\">.</span>IntegerField<span class=\"p\">()</span>\n    street <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">100</span><span class=\"p\">)</span>\n    city <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">100</span><span class=\"p\">)</span>\n    state <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">)</span>\n    zipcode <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>Zipcode<span class=\"p\">)</span>\n    objects <span class=\"o\">=</span> models<span class=\"o\">.</span>GeoManager<span class=\"p\">()</span>\n</code></pre></div>\n<p>The geographic manager is needed to do spatial queries on related <code class=\"docutils literal notranslate\">Zipcode</code> objects,\nfor example:</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>qs <span class=\"o\">=</span> Address<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>zipcode__poly__contains<span class=\"o\">=</span><span class=\"s1\">&#39;POINT(-104.590948 38.319914)&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p class=\"rubric\">Footnotes</p>\n<aside class=\"footnote-list brackets\">\n<aside class=\"footnote brackets\" id=\"fnogc\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id2\">1</a><span class=\"fn-bracket\">]</span></span>\n<p>OpenGIS Consortium, Inc., <a class=\"reference external\" href=\"http://www.opengeospatial.org/standards/sfs\">Simple Feature Specification For SQL</a>.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fnogcsrid\" 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 id.</em> at Ch. 2.3.8, p. 39 (Geometry Values and Spatial Reference Systems).</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fnsrid\" 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>Typically, SRID integer corresponds to an EPSG (<a class=\"reference external\" href=\"http://www.epsg.org\">European Petroleum Survey Group</a>) identifier.  However, it may also be associated with custom projections defined in spatial database’s spatial reference systems table.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fnharvard\" 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>Harvard Graduate School of Design, <a class=\"reference external\" href=\"http://www.gsd.harvard.edu/gis/manual/projections/fundamentals/\">An Overview of Geodesy and Geographic Referencing Systems</a>.  This is an excellent resource for an overview of principles relating to geographic and Cartesian coordinate systems.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fnthematic\" 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>Terry A. Slocum, Robert B. McMaster, Fritz C. Kessler, &amp; Hugh H. Howard, <em>Thematic Cartography and Geographic Visualization</em> (Prentice Hall, 2nd edition), at Ch. 7.1.3.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fndist\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id10\">6</a><span class=\"fn-bracket\">]</span></span>\n<p>This limitation does not apply to PostGIS.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"fngeography\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id17\">7</a><span class=\"fn-bracket\">]</span></span>\n<p>Please refer to the <a class=\"reference external\" href=\"http://postgis.net/docs/manual-2.1/using_postgis_dbmanagement.html#PostGIS_Geography\">PostGIS Geography Type</a> documentation for more details.</p>\n</aside>\n</aside>\n</section>","rootId":"module-django.contrib.gis.db.models","toc":[{"title":"Geometry Field Types","anchor":"geometry-field-types","children":[{"title":"GeometryField","anchor":"geometryfield","children":[]},{"title":"PointField","anchor":"pointfield","children":[]},{"title":"LineStringField","anchor":"linestringfield","children":[]},{"title":"PolygonField","anchor":"polygonfield","children":[]},{"title":"MultiPointField","anchor":"multipointfield","children":[]},{"title":"MultiLineStringField","anchor":"multilinestringfield","children":[]},{"title":"MultiPolygonField","anchor":"multipolygonfield","children":[]},{"title":"GeometryCollectionField","anchor":"geometrycollectionfield","children":[]}]},{"title":"Geometry Field Options","anchor":"geometry-field-options","children":[{"title":"srid","anchor":"srid","children":[{"title":"Selecting an SRID","anchor":"selecting-an-srid","children":[]}]},{"title":"spatial_index","anchor":"spatial-index","children":[]},{"title":"dim","anchor":"dim","children":[]},{"title":"geography","anchor":"geography","children":[{"title":"Geography Type","anchor":"geography-type","children":[]}]}]},{"title":"GeoManager","anchor":"geomanager","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/en/1.8/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/en/1.8/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/en/1.8/ref/contrib/gis/"}],"prev":{"docname":"ref/contrib/gis/install/spatialite","title":"Installing Spatialite","url":"/en/1.8/ref/contrib/gis/install/spatialite/"},"next":{"docname":"ref/contrib/gis/db-api","title":"GeoDjango Database API","url":"/en/1.8/ref/contrib/gis/db-api/"},"formats":{"html":"/en/1.8/ref/contrib/gis/model-api/","markdown":"/en/1.8/ref/contrib/gis/model-api.md","json":"/en/1.8/ref/contrib/gis/model-api.json"},"source":"https://github.com/django/django/blob/stable/1.8.x/docs/ref/contrib/gis/model-api.txt","official":"https://docs.djangoproject.com/en/1.8/ref/contrib/gis/model-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"]}