---
title: "API Múnla GeodJango"
version: 6.0
locale: ga
source: https://docs.djangoproject.com/ga/6.0/ref/contrib/gis/model-api/
canonical: https://djangodocs.dev/ga/6.0/ref/contrib/gis/model-api/
---
# API Múnla GeodJango

This document explores the details of the GeoDjango Model API. Throughout this
section, we'll be using the following geographic model of a [ZIP code](https://en.wikipedia.org/wiki/ZIP_code) and
of a [Digital Elevation Model](https://en.wikipedia.org/wiki/Digital_elevation_model) as our examples:

```
from django.contrib.gis.db import models

class Zipcode(models.Model):
    code = models.CharField(max_length=5)
    poly = models.PolygonField()

class Elevation(models.Model):
    name = models.CharField(max_length=100)
    rast = models.RasterField()
```

## Cineálacha Réimse spású

Is éard atá i réimsí spásúla sraith cineálacha réimse geoiméadrachta agus cineál réimse raster amháin. Freagraíonn gach ceann de na cineálacha réimse geoiméadair do shonraíocht Gnéithe Simple OpenGIS \[#fnogc\] \_. Níl aon chaighdeán den sórt sin ann do shonraí raster.

### `Réimse Geoiméadraithe`

#### `class GeometryField`

An bunaicme do réimsí geoiméadrachta.

### `Pointfield`

#### `class PointField`

Stórais a: aicme: ~django.contrib.gis.geos.point.

### `Línestringfield`

#### `class LineStringField`

Stórais a: aicme: ~django.contrib.gis.geos.lineString.

### `Polygonfield`

#### `class PolygonField`

Stórais a: aicme: ~django.contrib.gis.geos.polygon.

### `Réimse Ilphoint`

#### `class MultiPointField`

Stórais a: aicme: ~django.contrib.gis.geos.multipoint.

### `Páirc Illíneach`

#### `class MultiLineStringField`

Stórais a: aicme: ~django.contrib.gis.geos.multilineString.

### `Multipolygonfield`

#### `class MultiPolygonField`

Stórais a: aicme: ~django.contrib.gis.geos.multipolygon.

### `Réimse Bailiúcháin Geoimetrach`

#### `class GeometryCollectionField`

Stórais a: aicme: ~django.contrib.gis.geos.geometryCollection.

### `Rasterfield`

#### `class RasterField`

Stórais a:aicme: ~django.contrib.gis.gdal.gdalraster.

Ní chuirtear Rasterfield i bhfeidhm faoi láthair ach amháin don chúltaca PostGIS.

## Roghanna Réimse spásúla

Chomh maith leis na rialt:ref: common-model-field-options atá ar fáil do réimsí samhail Django, tá na roghanna breise seo a leanas ag réimsí spásúla. Tá gach ceann roghnach.

### `Srid`

#### `BaseSpatialField.srid`

Socraíonn an SRID \[#fnogcsrid\] \_ (Aitheantas Córais Tagartha Spásúil) an réimse geoiméadrach don luach a thugtar. Réamhshocraithe go 4326 (ar a dtugtar [WGS84](https://en.wikipedia.org/wiki/WGS84) freisin, tá aonaid i gcéimeanna fadmhéad agus domhanleithead).

#### SRID a roghnú

Choosing an appropriate SRID for your model is an important decision that the
developer should consider carefully. The SRID is an integer specifier that
corresponds to the projection system that will be used to interpret the data in
the spatial database. [^3]  Projection systems give the context to the
coordinates that specify a location. Although the details of [geodesy](https://en.wikipedia.org/wiki/Geodesy) are
beyond the scope of this documentation, the general problem is that the earth
is spherical and representations of the earth (e.g., paper maps, web maps) are
not.

Most people are familiar with using latitude and longitude to reference a
location on the earth's surface. However, latitude and longitude are angles,
not distances. In other words, while the shortest path between two points on a
flat surface is a straight line, the shortest path between two points on a
curved surface (such as the earth) is an *arc* of a [great circle](https://en.wikipedia.org/wiki/Great_circle).
[^4]

Thus, additional computation is required to obtain distances in planar units
(e.g., kilometers and miles). Using a geographic coordinate system may
introduce complications for the developer later on. For example, SpatiaLite
does not have the capability to perform distance calculations between
geometries using geographic coordinate systems, e.g. constructing a query to
find all points within 5 miles of a county boundary stored as WGS84. [^5]

Portions of the earth's surface may projected onto a two-dimensional, or
Cartesian, plane. Projected coordinate systems are especially convenient for
region-specific applications, e.g., if you know that your database will only
cover geometries in [North Kansas](https://spatialreference.org/ref/epsg/2796/), then you may consider using projection
system specific to that region. Moreover, projected coordinate systems are
defined in Cartesian units (such as meters or feet), easing distance
calculations.

> **Note**
>
> \<geography-type\>Más mian leat ceisteanna achair treallacha a dhéanamh ag baint úsáide as geoiméadraí neamh-phointe i WGS84 i PostGIS agus ba mhaith leat feidhmíocht mhaith, cumasaigh an eochairfhocal: attr: Geometryfield.geography ionas go n-úsáidtear: ref: cineál bunachar sonraí tíreolaíochta ina ionad.

Acmhainní Breise:

- [spatialreference.org](https://spatialreference.org/): Bunachar sonraí faoi thiomáint Django de chórais tagartha spásúla.
- [The State Plane Coordinate System](https://web.archive.org/web/20080302095452/http://welcome.warnercnr.colostate.edu/class_info/nr502/lg3/datums_coordinates/spcs.html): A website covering the various
  projection systems used in the United States. Much of the U.S. spatial
  data encountered will be in one of these coordinate systems rather than
  in a geographic coordinate system such as WGS84.

### `Innéacsa_spáis`

#### `BaseSpatialField.spatial_index`

Defaults to `True`. Creates a spatial index for the given geometry
field.

> **Note**
>
> This is different from the `db_index` field option because spatial
> indexes are created in a different manner than regular database
> indexes. Specifically, spatial indexes are typically created using
> a variant of the R-Tree, while regular database indexes typically
> use B-Trees.

## Roghanna Réimse Céim

Tá roghanna breise ar fáil do réimsí Geoiméadra. Tá na roghanna seo a leanas go léir roghnach.

### `` `dim ``

#### `GeometryField.dim`

This option may be used for customizing the coordinate dimension of the
geometry field. By default, it is set to 2, for representing two-dimensional
geometries. For spatial backends that support it, it may be set to 3 for
three-dimensional support.

> **Note**
>
> Ag an am seo tá tacaíocht 3D teoranta do na cúltaca PostGIS agus Spatialite.

### `Geografa`

#### `GeometryField.geography`

If set to `True`, this option will create a database column of
type geography, rather than geometry. Please refer to the
[geography type](#geography-type) section below for more
details.

> **Note**
>
> Tá tacaíocht tíreolaíochta teoranta do PostGIS agus cuirfidh sé iallach ar an SRID a bheith 4326.

### `max_geom_collections`

#### `GeometryField.max_geom_collections`

> **New in Django 5.2.17**

This option is forwarded to the [`form field`](/ga/6.0/ref/contrib/gis/forms-api/#django.contrib.gis.forms.Field.max_geom_collections) generated for this model
field, bounding how many geometry collections may be contained in submitted
WKB/WKT inputs before raising [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError). Since spatial field
assignments are lazy, it is also checked when values are accessed, e.g. when
saving an instance, but not when read from a database. It defaults to `198`.

#### Cineál Tíreolaíochta

The geography type provides native support for spatial features represented
with geographic coordinates (e.g., WGS84 longitude/latitude). [^6]
Unlike the plane used by a geometry type, the geography type uses a spherical
representation of its data. Distance and measurement operations
performed on a geography column automatically employ great circle arc
calculations and return linear units. In other words, when `ST_Distance`
is called on two geographies, a value in meters is returned (as opposed
to degrees if called on a geometry column in WGS84).

Toisc go bhfuil níos mó matamaitice i gceist le ríomhanna tíreolaíochta, níl ach fo-thacar de na cuardaigh spásúla PostGIS ar fáil don chineál tíreolaíochta. \<spatial-lookups\>Go praiticiúil, \<distance-lookups\>ciallaíonn sé seo nach bhfuil ach na cuardach breise seo a leanas: ref: cuardaigh spásúla \`ar fáil do cholúin tíreolaíochta, i dteann:ref: \`cuardach achair:

- [`bboverlaps`](/ga/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-bboverlaps)
- [`coveredby`](/ga/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-coveredby)
- [`covers`](/ga/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-covers)
- [`intersects`](/ga/6.0/ref/contrib/gis/geoquerysets/#std-fieldlookup-intersects)

Más gá duit cuardach spásúil nó comhiomlán a úsáid nach dtacaíonn leis an gcineál tíreolaíochta mar ionchur, is féidir leat feidhm bhunachar sonraí: class: ~django.db.Models.functions.cast a úsáid chun an colún tíreolaíochta a thiontú go cineál geoiméadrach san fhiosrúchán:

```
from django.contrib.gis.db.models import PointField
from django.db.models.functions import Cast

Zipcode.objects.annotate(geom=Cast("geography_field", PointField())).filter(
    geom__within=poly
)
```

For more information, the PostGIS documentation contains a helpful section on
determining [when to use geography data type over geometry data type](https://postgis.net/docs/using_postgis_dbmanagement.html#PostGIS_GeographyVSGeometry).

**Fonótaí**

[^1]: OpenGIS Consortium, Inc., . \< <https://www.ogc.org/standard/sfs/>\>

[^2]: *Féach id.* ag Ch. 2.3.8, lch. 39 (Luachanna Coiméadrachta agus Córais Tagartha Spásúla).

[^3]: Typically, SRID integer corresponds to an EPSG ([European Petroleum Survey Group](https://epsg.org/)) identifier. However, it may also be associated with custom projections defined in spatial database's spatial reference systems table.

[^4]: Terry A. Slocum, Robert B. McMaster, Fritz C. Kessler, & Hugh H. Howard, *Cartografaíocht Téamach agus Amharc Geografach* (Halla Prentice, 2ú eagrán), ag Ch. 7.1.3.

[^5]: Ní bhaineann an teorannú seo le PostGIS.

[^6]: Féach do thoil do dhoiciméadú Cineál Tíreolaíochta PostGIS \_ le haghaidh tuilleadh son\< [https://postgis.net/docs/using\_postgis\_dbmanagement.html#PostGIS\_Geography](https://postgis.net/docs/using_postgis_dbmanagement.html#PostGIS_Geography)\> raí.
