---
title: "API GEOS"
version: 6.0
locale: id
source: https://docs.djangoproject.com/id/6.0/ref/contrib/gis/geos/
canonical: https://djangodocs.dev/id/6.0/ref/contrib/gis/geos/
---
# API GEOS

## Latar belakang

### Apa itu GEOS?

[GEOS](https://libgeos.org/) stands for **Geometry Engine - Open Source**,
and is a C++ library, ported from the  [Java Topology Suite](https://sourceforge.net/projects/jts-topo-suite/). GEOS
implements the OpenGIS [Simple Features for SQL](https://www.ogc.org/standard/sfs/) spatial predicate functions
and spatial operators. GEOS, now an OSGeo project, was initially developed and
maintained by [Refractions Research](http://www.refractions.net/) of Victoria, Canada.

### Fitur

GeoDjango menerapkan pembungkus Python tingkat-tinggi untuk pustaka GEOS, fitur-fiturnya termasuk:

- Sebuah antarmuka berlisensi-BSD pada rutin geometri GEOS, diterapkan sepenuhnya dalam Python menggunakan `ctypes`.
- Loosely-coupled to GeoDjango. For example, [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) objects
  may be used outside of a Django project/application. In other words,
  no need to have [`DJANGO_SETTINGS_MODULE`](/id/6.0/topics/settings/#envvar-DJANGO_SETTINGS_MODULE) set or use a database, etc.
- Berubah-ubah: obyek [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) mungkin dirubah.
- Cross-platform tested.

## Pengajaran tambahan

Bagian ini mengandung perkenalan singkat dan pengajaran tambahan menggunakan obyek [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry).

### Membuat Geometri

[`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) objects may be created in a few ways. The first is
to simply instantiate the object on some spatial input -- the following
are examples of creating the same geometry from WKT, HEX, WKB, and GeoJSON:

```pycon
>>> from django.contrib.gis.geos import GEOSGeometry
>>> pnt = GEOSGeometry("POINT(5 23)")  # WKT
>>> pnt = GEOSGeometry("010100000000000000000014400000000000003740")  # HEX
>>> pnt = GEOSGeometry(
...     memoryview(
...         b"\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x007@"
...     )
... )  # WKB
>>> pnt = GEOSGeometry(
...     '{ "type": "Point", "coordinates": [ 5.000000, 23.000000 ] }'
... )  # GeoJSON
```

Another option is to use the constructor for the specific geometry type
that you wish to create. For example, a [`Point`](#django.contrib.gis.geos.Point) object may be
created by passing in the X and Y coordinates into its constructor:

```pycon
>>> from django.contrib.gis.geos import Point
>>> pnt = Point(5, 23)
```

All these constructors take the keyword argument `srid`. For example:

```pycon
>>> from django.contrib.gis.geos import GEOSGeometry, LineString, Point
>>> print(GEOSGeometry("POINT (0 0)", srid=4326))
SRID=4326;POINT (0 0)
>>> print(LineString((0, 0), (1, 1), srid=4326))
SRID=4326;LINESTRING (0 0, 1 1)
>>> print(Point(0, 0, srid=32140))
SRID=32140;POINT (0 0)
```

Finally, there is the [`fromfile()`](#django.contrib.gis.geos.fromfile) factory method which returns a
[`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) object from a file:

```pycon
>>> from django.contrib.gis.geos import fromfile
>>> pnt = fromfile("/path/to/pnt.wkt")
>>> pnt = fromfile(open("/path/to/pnt.wkt"))
```

> **Catatan-catatan saya dipenuhi dengan kesalahan berhubungan-GEOS**
>
> You find many `TypeError` or `AttributeError` exceptions filling your
> web server's log files. This generally means that you are creating GEOS
> objects at the top level of some of your Python modules. Then, due to a
> race condition in the garbage collector, your module is garbage collected
> before the GEOS object. To prevent this, create [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry)
> objects inside the local scope of your functions/methods.

### Geometri adalah Pythonic

[`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) objects are 'Pythonic', in other words components may
be accessed, modified, and iterated over using standard Python conventions.
For example, you can iterate over the coordinates in a [`Point`](#django.contrib.gis.geos.Point):

```pycon
>>> pnt = Point(5, 23)
>>> [coord for coord in pnt]
[5.0, 23.0]
```

With any geometry object, the [`GEOSGeometry.coords`](#django.contrib.gis.geos.GEOSGeometry.coords) property
may be used to get the geometry coordinates as a Python tuple:

```pycon
>>> pnt.coords
(5.0, 23.0)
```

You can get/set geometry components using standard Python indexing
techniques. However, what is returned depends on the geometry type
of the object. For example, indexing on a [`LineString`](#django.contrib.gis.geos.LineString)
returns a coordinate tuple:

```pycon
>>> from django.contrib.gis.geos import LineString
>>> line = LineString((0, 0), (0, 50), (50, 50), (50, 0), (0, 0))
>>> line[0]
(0.0, 0.0)
>>> line[-2]
(50.0, 0.0)
```

Whereas indexing on a [`Polygon`](#django.contrib.gis.geos.Polygon) will return the ring
(a [`LinearRing`](#django.contrib.gis.geos.LinearRing) object) corresponding to the index:

```pycon
>>> from django.contrib.gis.geos import Polygon
>>> poly = Polygon(((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0)))
>>> poly[0]
<LinearRing object at 0x1044395b0>
>>> poly[0][-2]  # second-to-last coordinate of external ring
(50.0, 0.0)
```

In addition, coordinates/components of the geometry may added or modified,
just like a Python list:

```pycon
>>> line[0] = (1.0, 1.0)
>>> line.pop()
(0.0, 0.0)
>>> line.append((1.0, 1.0))
>>> line.coords
((1.0, 1.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (1.0, 1.0))
```

Geometries support set-like operators:

```pycon
>>> from django.contrib.gis.geos import LineString
>>> ls1 = LineString((0, 0), (2, 2))
>>> ls2 = LineString((1, 1), (3, 3))
>>> print(ls1 | ls2)  # equivalent to `ls1.union(ls2)`
MULTILINESTRING ((0 0, 1 1), (1 1, 2 2), (2 2, 3 3))
>>> print(ls1 & ls2)  # equivalent to `ls1.intersection(ls2)`
LINESTRING (1 1, 2 2)
>>> print(ls1 - ls2)  # equivalent to `ls1.difference(ls2)`
LINESTRING(0 0, 1 1)
>>> print(ls1 ^ ls2)  # equivalent to `ls1.sym_difference(ls2)`
MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))
```

> **Kesetaraan penghubung tidak memeriksa kesetaraam spasial**
>
> The [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) equality operator uses
> [`equals_exact()`](#django.contrib.gis.geos.GEOSGeometry.equals_exact), not [`equals()`](#django.contrib.gis.geos.GEOSGeometry.equals), i.e.
> it requires the compared geometries to have the same coordinates in the
> same positions with the same SRIDs:
>
> ```pycon
> >>> from django.contrib.gis.geos import LineString
> >>> ls1 = LineString((0, 0), (1, 1))
> >>> ls2 = LineString((1, 1), (0, 0))
> >>> ls3 = LineString((1, 1), (0, 0), srid=4326)
> >>> ls1.equals(ls2)
> True
> >>> ls1 == ls2
> False
> >>> ls3 == ls2  # different SRIDs
> False
> ```

## Obyek Geometri

### `GEOSGeometry`

#### `class GEOSGeometry(geo_input, srid=None, * (Keyword-only parameters separator (PEP 3102)), max_geom_collections=198)`

**Parameter:** - `geo_input` -- Geometry input value (string or [`memoryview`](https://docs.python.org/3/library/stdtypes.html#memoryview))
- `srid` ([`int`](https://docs.python.org/3/library/functions.html#int)) -- penciri acuan spasial
- `max_geom_collections` -- maximum number of nested (WKT) or total (WKB)
  geometry collections accepted before parsing is refused

This is the base class for all GEOS geometry objects. It initializes on the
given `geo_input` argument, and then assumes the proper geometry subclass
(e.g., `GEOSGeometry('POINT(1 1)')` will create a [`Point`](#django.contrib.gis.geos.Point) object).

The `srid` parameter, if given, is set as the SRID of the created geometry if
`geo_input` doesn't have an SRID. If different SRIDs are provided through the
`geo_input` and `srid` parameters, `ValueError` is raised:

```pycon
>>> from django.contrib.gis.geos import GEOSGeometry
>>> GEOSGeometry("POINT EMPTY", srid=4326).ewkt
'SRID=4326;POINT EMPTY'
>>> GEOSGeometry("SRID=4326;POINT EMPTY", srid=4326).ewkt
'SRID=4326;POINT EMPTY'
>>> GEOSGeometry("SRID=1;POINT EMPTY", srid=4326)
Traceback (most recent call last):
...
ValueError: Input geometry already has SRID: 1.
```

Bentuk-bentuk masukan berikut, bersama dengan jenis-jenis Python yang sesuai, adalah diterima:

| Bentuk | Jenis Masukan |
| --- | --- |
| WKT / EWKT | `str` |
| HEX / HEXEWKB | `str` |
| WKB / EWKB | `memoryview` |
| [**GeoJSON**](https://datatracker.ietf.org/doc/html/rfc7946.html) | `str` |

Untuk bentuk GeoJSON, SRID disetel berdasarkan pada anggota `crs`. jika `crs` tidak disediakan, SRID awalan pada 4326.

> **Changed in Django 5.2.17**
>
> The `max_geom_collections` parameter was added.

#### `classmethod GEOSGeometry.from_gml(gml_string)`

Membangun sebuah [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) dari string GML yang diberikan.

#### Sifat-sifat

#### `GEOSGeometry.coords`

Mengembalikan kordinat dari geometri sebagai tuple.

#### `GEOSGeometry.dims`

Mengembalikan dimensi dari geometri:

- `0` untuk [`Point`](#django.contrib.gis.geos.Point) dan [`MultiPoint`](#django.contrib.gis.geos.MultiPoint)
- `1` untuk [`LineString`](#django.contrib.gis.geos.LineString) dan [`MultiLineString`](#django.contrib.gis.geos.MultiLineString)
- `2` untuk [`Polygon`](#django.contrib.gis.geos.Polygon) dan [`MultiPolygon`](#django.contrib.gis.geos.MultiPolygon)
- `-1` untuk [`GeometryCollection`](#django.contrib.gis.geos.GeometryCollection) kosong
- dimensi maksimal dari unsur-unsurnya untuk [`GeometryCollection`](#django.contrib.gis.geos.GeometryCollection) bukan-kosong.

#### `GEOSGeometry.empty`

Mengembalikan apakah atau tidak disetel dari titik-titik dalam geometri adalah kosong.

#### `GEOSGeometry.geom_type`

Returns a string corresponding to the type of geometry. For example:

```pycon
>>> pnt = GEOSGeometry("POINT(5 23)")
>>> pnt.geom_type
'Point'
```

#### `GEOSGeometry.geom_typeid`

Returns the GEOS geometry type identification number. The following table
shows the value for each geometry type:

| Geometri | ID |
| --- | --- |
| [`Point`](#django.contrib.gis.geos.Point) | 0 |
| [`LineString`](#django.contrib.gis.geos.LineString) | 1 |
| [`LinearRing`](#django.contrib.gis.geos.LinearRing) | 2 |
| [`Polygon`](#django.contrib.gis.geos.Polygon) | 3 |
| [`MultiPoint`](#django.contrib.gis.geos.MultiPoint) | 4 |
| [`MultiLineString`](#django.contrib.gis.geos.MultiLineString) | 5 |
| [`MultiPolygon`](#django.contrib.gis.geos.MultiPolygon) | 6 |
| [`GeometryCollection`](#django.contrib.gis.geos.GeometryCollection) | 7 |

#### `GEOSGeometry.num_coords`

Mengembalikan angka dari kordinat di geometri.

#### `GEOSGeometry.num_geom`

Returns the number of geometries in this geometry. In other words, will
return 1 on anything but geometry collections.

#### `GEOSGeometry.hasz`

Returns a boolean indicating whether the geometry has the Z dimension.

#### `GEOSGeometry.hasm`

> **New in Django 6.0**

Returns a boolean indicating whether the geometry has the M dimension.
Requires GEOS 3.12.

#### `GEOSGeometry.ring`

Mengembalikan sebuah boolean menunjukkan apakah geometri adalah `LinearRing`.

#### `GEOSGeometry.simple`

Returns a boolean indicating whether the geometry is 'simple'. A geometry
is simple if and only if it does not intersect itself (except at boundary
points). For example, a [`LineString`](#django.contrib.gis.geos.LineString) object is not simple if it
intersects itself. Thus, [`LinearRing`](#django.contrib.gis.geos.LinearRing) and [`Polygon`](#django.contrib.gis.geos.Polygon) objects
are always simple because they cannot intersect themselves, by definition.

#### `GEOSGeometry.valid`

Mengembalikan sebuah boolean menunjukkan apakah geometri adalah sah.

#### `GEOSGeometry.valid_reason`

Mengembalikan deretan kalimat menggambarkan alasan mengapa geometri sah.

#### `GEOSGeometry.srid`

Property that may be used to retrieve or set the SRID associated with the
geometry. For example:

```pycon
>>> pnt = Point(5, 23)
>>> print(pnt.srid)
None
>>> pnt.srid = 4326
>>> pnt.srid
4326
```

#### Sifat-sifat Keluaran

The properties in this section export the [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) object into
a different. This output may be in the form of a string, buffer, or even
another object.

#### `GEOSGeometry.ewkt`

Returns the "extended" Well-Known Text of the geometry. This representation
is specific to PostGIS and is a superset of the OGC WKT standard. [^1]
Essentially the SRID is prepended to the WKT representation, for example
`SRID=4326;POINT(5 23)`.

> **Note**
>
> Keluaran dari sifat ini tidak menyertakan informasi 3dm, 3dz, dan 4d yang PostGIS dukung dalam perwakilan EWKT nya.

#### `GEOSGeometry.hex`

Returns the WKB of this Geometry in hexadecimal form. Please note
that the SRID value is not included in this representation
because it is not a part of the OGC specification (use the
[`GEOSGeometry.hexewkb`](#django.contrib.gis.geos.GEOSGeometry.hexewkb) property instead).

#### `GEOSGeometry.hexewkb`

Returns the EWKB of this Geometry in hexadecimal form. This is an
extension of the WKB specification that includes the SRID value
that are a part of this geometry.

#### `GEOSGeometry.json`

Mengembalikan perwakilan GeoJSON dari geometri. Catat bahwa ahsiladalah bukan struktur GeoJSON lengkap tetapi hanya isi kunci `geometry` dari struktur GeoJSON. Lihat juga [Penserial GeoJSON](/id/6.0/ref/contrib/gis/serializers/).

#### `GEOSGeometry.geojson`

Nama lain dari [`GEOSGeometry.json`](#django.contrib.gis.geos.GEOSGeometry.json).

#### `GEOSGeometry.kml`

Returns a [KML](https://developers.google.com/kml/documentation/) (Keyhole Markup Language) representation of the
geometry. This should only be used for geometries with an SRID of
4326 (WGS84), but this restriction is not enforced.

#### `GEOSGeometry.ogr`

Mengembalikan obyek [`OGRGeometry`](/id/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.OGRGeometry) terkait pada permintaan pada geometri GEOS.

#### `GEOSGeometry.wkb`

Returns the WKB (Well-Known Binary) representation of this Geometry
as a Python buffer. SRID value is not included, use the
[`GEOSGeometry.ewkb`](#django.contrib.gis.geos.GEOSGeometry.ewkb) property instead.

#### `GEOSGeometry.ewkb`

Mengembalikan perwakilan EWKB dari Geometry sebagai sebuah penyangga Python. Ini adalah sebuah tambahan dari spesifikasi WKB yang menyertakan nilai SRID apapun yang bagian dari geometri ini.

#### `GEOSGeometry.wkt`

Mengembalikan Well-Known Text dari geometri (sebuah standar OGC).

#### Metode Predikat Spasial

Semua dari metode-metode predikat spasial berikut mengambil contoh [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) lain (`other`) sebagai sebuah parameter, dan mengembalikan boolean.

#### `GEOSGeometry.contains(other)`

Mengembalikan `True` jika [`other.within(this)`](#django.contrib.gis.geos.GEOSGeometry.within) mengembalikan `True`.

#### `GEOSGeometry.covers(other)`

Mengembalikan `True` jika geometri mencangkup geometri tertentu.

Sebutan `covers` mempunyai pengertian kesetaraan berikut:

- Setiap titik dari geometri lain adalah sebuah titik dari geometri ini.
- The [DE-9IM](https://en.wikipedia.org/wiki/DE-9IM) Intersection Matrix for the two geometries is
  `T*****FF*`, `*T****FF*`, `***T**FF*`, or `****T*FF*`.

Jika salah satu geometri adalah kosong, kembalikan `False`.

Prediakt ini mirip pada [`GEOSGeometry.contains()`](#django.contrib.gis.geos.GEOSGeometry.contains), tetapi lebih termasuk (yaitu mengembalikan `True` untuk kasus-kasus lebih). Khususnya, tidak seperti [`contains()`](#django.contrib.gis.geos.GEOSGeometry.contains) itu tidak membedakan diantara titik-titik dalam batasan dan dalam interior dari geometri. Untuk kebanyakan situasi, `covers()` harus dipilih pada [`contains()`](#django.contrib.gis.geos.GEOSGeometry.contains). Sebagai sebuah keuntungan tambahan, `covers()` lebih menerima untuk optimalisasi dan karena itu harus mengungguli [`contains()`](#django.contrib.gis.geos.GEOSGeometry.contains).

#### `GEOSGeometry.crosses(other)`

Mengembalikan `True` jika matriks persimpangan DE-9IM untuk dua geometri adalah `T*T******` (untuk titik dan kurva, titik dan kawasan atau baris dan kawasan) `0********` (untuk dua kurva).

#### `GEOSGeometry.disjoint(other)`

Mengembalikan `True` jika matriks persimpangan DE-9IM untuk dua geometri adalah `FF*FF****`.

#### `GEOSGeometry.equals(other)`

Mengembalikan `True` jika matriks persimpangan DE-9IM untuk dua geometri adalah `T*F**FFF*`.

#### `GEOSGeometry.equals_exact(other, tolerance=0)`

Returns true if the two geometries are exactly equal, up to a
specified tolerance. The `tolerance` value should be a floating
point number representing the error tolerance in the comparison, e.g.,
`poly1.equals_exact(poly2, 0.001)` will compare equality to within
one thousandth of a unit.

#### `GEOSGeometry.equals_identical(other)`

Returns `True` if the two geometries are point-wise equivalent by
checking that the structure, ordering, and values of all vertices are
identical in all dimensions. `NaN` values are considered to be equal to
other `NaN` values. Requires GEOS 3.12.

#### `GEOSGeometry.intersects(other)`

Mengembalikan `True` jika [`GEOSGeometry.disjoint()`](#django.contrib.gis.geos.GEOSGeometry.disjoint) adalah `False`.

#### `GEOSGeometry.overlaps(other)`

Mengembalikan `True` jika matriks persimpangan DE-9IM untuk dua geometri adalah `T*T***T**` (untuk titik dan kurva, titik dan kawasan atau baris dan kawasan) `1*T***T**` (untuk dua kurva).

#### `GEOSGeometry.relate_pattern(other, pattern)`

Mengembalikan `True` jika matriks persimpangan DE-9IM untuk geometri ini dah lainnya cocok pada `pattern` yang diberikan -- string dari sembilan karakter dari alfabet: {`T`, `F`, `*`, `0`}.

#### `GEOSGeometry.touches(other)`

Mengembalikan `True` jika matriks persimpangan DE-9IM untuk dua geometri adalah  `FT*******`, `F**T*****` or `F***T****`.

#### `GEOSGeometry.within(other)`

Mengembalikan `True` jika matriks persimpangan DE-9IM untuk dua geometri adalah `T*F**F***`.

#### Metode-metode Topologi

#### `GEOSGeometry.buffer(width, quadsegs=8)`

Mengembalikan sebuah [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) yang mewakili semua titik-titik yang jaraknya dari geometri ini kurang dari atau setara pada `width` yang diberikan. Kata kunci `quadsegs` pilihan mensetel angka dari bagian-bagian digunakan untuk memperkirakan seperempat lingkaran (awalan adalah 8).

#### `GEOSGeometry.buffer_with_style(width, quadsegs=8, end_cap_style=1, join_style=1, mitre_limit=5.0)`

Sama seperti [`buffer()`](#django.contrib.gis.geos.GEOSGeometry.buffer), tetapi mengizinkan gaya dari penyangga.

- `end_cap_style` dapat berupa round (`1`), flat (`2`), atau square (`3`).
- `join_style` dapat berupa round (`1`), mitre (`2`), atau bevel (`3`).
- Batas rasio siku (`mitre_limit`) hanya mempengaruhi gaya gabungan sudut.

#### `GEOSGeometry.difference(other)`

Mengembalikan [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) mewakili titik-titik membuat geometri ini yang tidak membuat lain.

#### `GEOSGeometry.interpolate(distance)`

#### `GEOSGeometry.interpolate_normalized(distance)`

Diberikan sebuah jarak (float), mengembalikan titik (atau titik terdekat) dalam geometri ([`LineString`](#django.contrib.gis.geos.LineString) atau [`MultiLineString`](#django.contrib.gis.geos.MultiLineString)) pada jarak itu. Versi biasa mengambil jarak sebagai sebuah float diantara 0 (asli) dan 1 (titik akhir).

Membalikkan dari [`GEOSGeometry.project()`](#django.contrib.gis.geos.GEOSGeometry.project).

#### `GEOSGeometry.intersection(other)`

Mengembalikan [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) mewakili titik-titik dibgi oleh geometri ini dan lainnya.

#### `GEOSGeometry.project(point)`

#### `GEOSGeometry.project_normalized(point)`

Mengembalikan jarak (float) dari asli geometri ([`LineString`](#django.contrib.gis.geos.LineString) atau [`MultiLineString`](#django.contrib.gis.geos.MultiLineString)) ke titik diproyeksikan pada geometri (yaitu pada titik dari baris terdekat pada titik yang diberikan). Versi biasa mengembalikan jarak sebagai sebuah float diantara 0 (asli) dan 1 (titik akhir).

Membalikkan dari [`GEOSGeometry.interpolate()`](#django.contrib.gis.geos.GEOSGeometry.interpolate).

#### `GEOSGeometry.relate(other)`

Mengembalikan matriks (string) persimpangan DE-9IM mewakili hubungan topologi diantara geometri ini dan lainnya.

#### `GEOSGeometry.simplify(tolerance=0.0, preserve_topology=False)`

Mengembalikan sebuah [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) baru, disederhanakan pada toleransi yang ditentukan menggunakan algoritma Douglas-Peucker. Nilai toleransi lebih tinggi mengartikan sedikit titik dalam keluaran. Jika toleransi tidak disediakan, awalan itu pada 0.

Secara awalan, fungsi ini tidak mempertahankan topologi. Sebagai contoh, obyek-obyek [`Polygon`](#django.contrib.gis.geos.Polygon) dapat dipisah, dirobohkan menjadi baris-baris, atau hilang. Lubang-lubang [`Polygon`](#django.contrib.gis.geos.Polygon) dapat dibuat atau hilang, dan baris-baris mungkin bersilangan. Dengan menentukan `preserve_topology=True`, hasil akan mempunyai dimensi sama dan jumlah komponen sebagai masukan; ini secara signifikan lebih lama, bagaimanapun.

#### `GEOSGeometry.sym_difference(other)`

Mengembalikan [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) menggabungkan titik-titik dalam geometri ini bukan yang lain, dan titik-titik di lainnya bukan dalam geometri ini.

#### `GEOSGeometry.union(other)`

Mengembalikan [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) mewakili semua titik dalam geometri ini dan lainnya.

#### Sifat-sifat Topologi

#### `GEOSGeometry.boundary`

Mengembalikan batasan sebagai sebuah obyek Geometri baru dialokasikan.

#### `GEOSGeometry.centroid`

Returns a [`Point`](#django.contrib.gis.geos.Point) object representing the geometric center of
the geometry. The point is not guaranteed to be on the interior
of the geometry.

#### `GEOSGeometry.convex_hull`

Mengembalikan [`Polygon`](#django.contrib.gis.geos.Polygon) terkecil yang mengandung semua titik dalam geometri.

#### `GEOSGeometry.envelope`

Mengembalikan sebuah [`Polygon`](#django.contrib.gis.geos.Polygon) yang meakili batasan bungkus dari geometri. Catat bahwa itu dapat juga mengembalikan sebuah [`Point`](#django.contrib.gis.geos.Point) jika masukan geometri adalah sebuah titik.

#### `GEOSGeometry.point_on_surface`

Menghitung dan mengembalikan jaminan [`Point`](#django.contrib.gis.geos.Point) untuk berada dalam interior dari geometri ini.

#### `GEOSGeometry.unary_union`

Menghitung gabungan dari semua unsur dari geometri ini.

Hasil mematuhi kontrak berikut:

- Unioning a set of [`LineString`](#django.contrib.gis.geos.LineString)s has the effect of fully noding
  and dissolving the linework.
- Menyatukan kumpulan dari [`Polygon`](#django.contrib.gis.geos.Polygon) akan selalu mengembalikan geometri [`Polygon`](#django.contrib.gis.geos.Polygon) atau [`MultiPolygon`](#django.contrib.gis.geos.MultiPolygon) (tidak seperti [`GEOSGeometry.union()`](#django.contrib.gis.geos.GEOSGeometry.union), yang mungkin mengembalikan geometri dari dimensi terendah jika topologi runtuh timbul).

#### Sifat dan Metode lain

#### `GEOSGeometry.area`

Sifat ini mengembalikan kawasan dari Geometri.

#### `GEOSGeometry.extent`

Sifat ini mengembalikan jangkauan dari geometri ini sebagai 4-tuple, terdiri dari `(xmin, ymin, xmax, ymax)`.

#### `GEOSGeometry.clone()`

Metode ini mengembalikan [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) yaitu sebuah kloningan dari asli.

#### `GEOSGeometry.distance(geom)`

Mengembalikan jarak diantara titik-titik terdekat pada geometri ini dan `geom` yang diberikan (obyek [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) lain).

> **Note**
>
> Perhitungan jarak GEOS adalah segaris -- dengan kata lain, GEOS tidak melakukan perhitungan bola bahkan jika SRID menentukan sistem kordinat geografis.

#### `GEOSGeometry.length`

Mengembalikan panjang dari geometri (misalnya, 0 untuk sebuah [`Point`](#django.contrib.gis.geos.Point), panjang dari sebuah [`LineString`](#django.contrib.gis.geos.LineString), atau lingkaran dari sebuah [`Polygon`](#django.contrib.gis.geos.Polygon)).

#### `GEOSGeometry.prepared`

Mengembalikan `PreparedGeometry` GEOS untuk isi dari geometri ini. Obyek-obyek  `PreparedGeometry` dioptimalkan untuk mengandung, bersimpangan, menutupi, bersilangan, menguraikan, tumpang tindih, menyentuh dan dalam tindakan-tindakan. Mengacu pada dokumentasi [Prepared Geometry](#prepared-geometries) untuk informasi lebih.

#### `GEOSGeometry.srs`

Mengembalikan obyek [`SpatialReference`](/id/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.SpatialReference) yang sesuai pada SRID dari geometri atau `None`.

#### `GEOSGeometry.transform(ct, clone=False)`

Transforms the geometry according to the given coordinate transformation
parameter (`ct`), which may be an integer SRID, spatial reference WKT
string, a PROJ string, a [`SpatialReference`](/id/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.SpatialReference)
object, or a [`CoordTransform`](/id/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.CoordTransform) object. By
default, the geometry is transformed in-place and nothing is returned.
However if the `clone` keyword is set, then the geometry is not modified
and a transformed clone of the geometry is returned instead.

> **Note**
>
> Memunculkan [`GEOSException`](#django.contrib.gis.geos.GEOSException) jika GDAL tidak tersedia atau jika SRID geometri adalah `None` atau kurang dari 0. Itu tidak mengenakan batasan apapun pada SRID geometri jika dipanggil dengan obyek [`CoordTransform`](/id/6.0/ref/contrib/gis/gdal/#django.contrib.gis.gdal.CoordTransform).

#### `GEOSGeometry.make_valid()`

Returns a valid [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) equivalent, trying not to lose any of
the input vertices. If the geometry is already valid, it is returned
untouched. This is similar to the
[`MakeValid`](/id/6.0/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.MakeValid) database
function. Requires GEOS 3.8.

#### `GEOSGeometry.normalize(clone=False)`

Converts this geometry to canonical form. If the `clone` keyword is set,
then the geometry is not modified and a normalized clone of the geometry is
returned instead:

```pycon
>>> g = MultiPoint(Point(0, 0), Point(2, 2), Point(1, 1))
>>> print(g)
MULTIPOINT (0 0, 2 2, 1 1)
>>> g.normalize()
>>> print(g)
MULTIPOINT (2 2, 1 1, 0 0)
```

### `Point`

#### `class Point(x=None, y=None, z=None, srid=None)`

`Point` objects are instantiated using arguments that represent the
component coordinates of the point or with a single sequence coordinates.
For example, the following are equivalent:

```pycon
>>> pnt = Point(5, 23)
>>> pnt = Point([5, 23])
```

Empty `Point` objects may be instantiated by passing no arguments or an
empty sequence. The following are equivalent:

```pycon
>>> pnt = Point()
>>> pnt = Point([])
```

### `LineString`

#### `class LineString(*args, **kwargs)`

`LineString` objects are instantiated using arguments that are either a
sequence of coordinates or [`Point`](#django.contrib.gis.geos.Point) objects. For example, the
following are equivalent:

```pycon
>>> ls = LineString((0, 0), (1, 1))
>>> ls = LineString(Point(0, 0), Point(1, 1))
```

In addition, `LineString` objects may also be created by passing in a
single sequence of coordinate or [`Point`](#django.contrib.gis.geos.Point) objects:

```pycon
>>> ls = LineString(((0, 0), (1, 1)))
>>> ls = LineString([Point(0, 0), Point(1, 1)])
```

Empty `LineString` objects may be instantiated by passing no arguments
or an empty sequence. The following are equivalent:

```pycon
>>> ls = LineString()
>>> ls = LineString([])
```

#### `closed`

Mengembalikan apakah atau tidak `LineString` ini ditutup.

### `LinearRing`

#### `class LinearRing(*args, **kwargs)`

`LinearRing` objects are constructed in the exact same way as
[`LineString`](#django.contrib.gis.geos.LineString) objects, however the coordinates must be *closed*, in
other words, the first coordinates must be the same as the last
coordinates. For example:

```pycon
>>> ls = LinearRing((0, 0), (0, 1), (1, 1), (0, 0))
```

Perhatikan bahwa `(0, 0)` adalah kordinat pertama dan terakhir -- jika mereka tidak setara, sebuah kesalahan akan dimunculkan.

#### `is_counterclockwise`

Returns whether this `LinearRing` is counterclockwise.

### `Polygon`

#### `class Polygon(*args, **kwargs)`

`Polygon` objects may be instantiated by passing in parameters that
represent the rings of the polygon. The parameters must either be
[`LinearRing`](#django.contrib.gis.geos.LinearRing) instances, or a sequence that may be used to construct
a [`LinearRing`](#django.contrib.gis.geos.LinearRing):

```pycon
>>> ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
>>> int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 0.4))
>>> poly = Polygon(ext_coords, int_coords)
>>> poly = Polygon(LinearRing(ext_coords), LinearRing(int_coords))
```

#### `classmethod from_bbox(bbox)`

Mengembalikan sebuah obyek poligon dari kotak-dikelilingi diberikan, 4-tuple meliputi `(xmin, ymin, xmax, ymax)`.

#### `num_interior_rings`

Mengembalikan sejumlah lingkaran interior di geometri ini.

> **Membandingkan Polygon**
>
> Note that it is possible to compare `Polygon` objects directly with `<`
> or `>`, but as the comparison is made through Polygon's
> [`LineString`](#django.contrib.gis.geos.LineString), it does not mean much (but is consistent and quick).
> You can always force the comparison with the [`area`](#django.contrib.gis.geos.GEOSGeometry.area)
> property:
>
> ```pycon
> >>> if poly_1.area > poly_2.area:
> ...     pass
> ...
> ```

## Kumpulan Geometri

### `MultiPoint`

#### `class MultiPoint(*args, **kwargs)`

`MultiPoint` objects may be instantiated by passing in [`Point`](#django.contrib.gis.geos.Point)
objects as arguments, or a single sequence of [`Point`](#django.contrib.gis.geos.Point) objects:

```pycon
>>> mp = MultiPoint(Point(0, 0), Point(1, 1))
>>> mp = MultiPoint((Point(0, 0), Point(1, 1)))
```

### `MultiLineString`

#### `class MultiLineString(*args, **kwargs)`

`MultiLineString` objects may be instantiated by passing in
[`LineString`](#django.contrib.gis.geos.LineString) objects as arguments, or a single sequence of
[`LineString`](#django.contrib.gis.geos.LineString) objects:

```pycon
>>> ls1 = LineString((0, 0), (1, 1))
>>> ls2 = LineString((2, 2), (3, 3))
>>> mls = MultiLineString(ls1, ls2)
>>> mls = MultiLineString([ls1, ls2])
```

#### `merged`

Mengembalikan sebuah [`LineString`](#django.contrib.gis.geos.LineString) mewakili baris menggabungkan semua komponen di `MultiLineString` ini.

#### `closed`

Returns `True` if and only if all elements are closed.

### `MultiPolygon`

#### `class MultiPolygon(*args, **kwargs)`

`MultiPolygon` objects may be instantiated by passing [`Polygon`](#django.contrib.gis.geos.Polygon)
objects as arguments, or a single sequence of [`Polygon`](#django.contrib.gis.geos.Polygon) objects:

```pycon
>>> p1 = Polygon(((0, 0), (0, 1), (1, 1), (0, 0)))
>>> p2 = Polygon(((1, 1), (1, 2), (2, 2), (1, 1)))
>>> mp = MultiPolygon(p1, p2)
>>> mp = MultiPolygon([p1, p2])
```

### `GeometryCollection`

#### `class GeometryCollection(*args, **kwargs)`

`GeometryCollection` objects may be instantiated by passing in other
[`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) as arguments, or a single sequence of
[`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) objects:

```pycon
>>> poly = Polygon(((0, 0), (0, 1), (1, 1), (0, 0)))
>>> gc = GeometryCollection(Point(0, 0), MultiPoint(Point(0, 0), Point(1, 1)), poly)
>>> gc = GeometryCollection((Point(0, 0), MultiPoint(Point(0, 0), Point(1, 1)), poly))
```

## Prepared Geometry

In order to obtain a prepared geometry, access the
[`GEOSGeometry.prepared`](#django.contrib.gis.geos.GEOSGeometry.prepared) property. Once you have a `PreparedGeometry`
instance its spatial predicate methods, listed below, may be used with other
`GEOSGeometry` objects. An operation with a prepared geometry can be orders
of magnitude faster -- the more complex the geometry that is prepared, the
larger the speedup in the operation. For more information, please consult the
[GEOS wiki page on prepared geometries](https://trac.osgeo.org/geos/wiki/PreparedGeometry).

Sebagai contoh:

```pycon
>>> from django.contrib.gis.geos import Point, Polygon
>>> poly = Polygon.from_bbox((0, 0, 5, 5))
>>> prep_poly = poly.prepared
>>> prep_poly.contains(Point(2.5, 2.5))
True
```

### `PreparedGeometry`

#### `class PreparedGeometry`

Semua metode pada `PreparedGeometry` mengambil sebuah argumen `other`, yang harus berupa instance [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry).

#### `contains(other)`

#### `contains_properly(other)`

#### `covers(other)`

#### `crosses(other)`

#### `disjoint(other)`

#### `intersects(other)`

#### `overlaps(other)`

#### `touches(other)`

#### `within(other)`

## Pabrik Geometri

#### `fromfile(file_h)`

**Parameter:** `file_h` (a Python `file` object or a string path to the file) -- masukan berkas yang mengandung data spasial

**Jenis Kembalian:** [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) berhubungan ke data spasial dalam berkas

Example:

```pycon
>>> from django.contrib.gis.geos import fromfile
>>> g = fromfile("/home/bob/geom.wkt")
```

#### `fromstr(string, srid=None)`

**Parameter:** - `string` ([`str`](https://docs.python.org/3/library/stdtypes.html#str)) -- deretan karakter yang mengandung data spasial
- `srid` ([`int`](https://docs.python.org/3/library/functions.html#int)) -- penciri acuan spasial

**Jenis Kembalian:** [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) terkait pada data spasial di deretan karakter

`fromstr(string, srid)` setara dengan [`GEOSGeometry(string, srid)`](#django.contrib.gis.geos.GEOSGeometry).

Example:

```pycon
>>> from django.contrib.gis.geos import fromstr
>>> pnt = fromstr("POINT(-90.5 29.5)", srid=4326)
```

## Obyek I/O

### Obyek Pembaca

The reader I/O classes return a [`GEOSGeometry`](#django.contrib.gis.geos.GEOSGeometry) instance from the WKB
and/or WKT input given to their `read(geom)` method.

#### `class WKBReader`

Example:

```pycon
>>> from django.contrib.gis.geos import WKBReader
>>> wkb_r = WKBReader()
>>> wkb_r.read("0101000000000000000000F03F000000000000F03F")
<Point object at 0x103a88910>
```

#### `class WKTReader`

Example:

```pycon
>>> from django.contrib.gis.geos import WKTReader
>>> wkt_r = WKTReader()
>>> wkt_r.read("POINT(1 1)")
<Point object at 0x103a88b50>
```

### Obyek Penulis

All writer objects have a `write(geom)` method that returns either the
WKB or WKT of the given geometry. In addition, [`WKBWriter`](#django.contrib.gis.geos.WKBWriter) objects
also have properties that may be used to change the byte order, and or
include the SRID value (in other words, EWKB).

#### `class WKBWriter(dim=2)`

`WKBWriter` provides the most control over its output. By default it
returns OGC-compliant WKB when its `write` method is called. However,
it has properties that allow for the creation of EWKB, a superset of the
WKB standard that includes additional information. See the
[`WKBWriter.outdim`](#django.contrib.gis.geos.WKBWriter.outdim) documentation for more details about the `dim`
argument.

#### `write(geom)`

Returns the WKB of the given geometry as a Python `buffer` object.
Example:

```pycon
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> pnt = Point(1, 1)
>>> wkb_w = WKBWriter()
>>> wkb_w.write(pnt)
<read-only buffer for 0x103a898f0, size -1, offset 0 at 0x103a89930>
```

#### `write_hex(geom)`

Returns WKB of the geometry in hexadecimal. Example:

```pycon
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> pnt = Point(1, 1)
>>> wkb_w = WKBWriter()
>>> wkb_w.write_hex(pnt)
'0101000000000000000000F03F000000000000F03F'
```

#### `byteorder`

Milik ini mungkin disetel untuk merubah urutan-byte dari perwakilan geometri.

| Nilai Byteorder | Deskripsi |
| --- | --- |
| 0 | Big Endian (misalnya, cocok dengan sistem RISC) |
| 1 | Little Endian (misalnya, cocok dengan sistem x86) |

Example:

```pycon
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> wkb_w = WKBWriter()
>>> pnt = Point(1, 1)
>>> wkb_w.write_hex(pnt)
'0101000000000000000000F03F000000000000F03F'
>>> wkb_w.byteorder = 0
'00000000013FF00000000000003FF0000000000000'
```

#### `outdim`

This property may be set to change the output dimension of the geometry
representation. In other words, if you have a 3D geometry then set to 3
so that the Z value is included in the WKB.

| Nilai Outdim | Deskripsi |
| --- | --- |
| 2 | Awalan, keluaran 2D WKB. |
| 3 | Keluaran 3D WKB. |

Example:

```pycon
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> wkb_w = WKBWriter()
>>> wkb_w.outdim
2
>>> pnt = Point(1, 1, 1)
>>> wkb_w.write_hex(pnt)  # By default, no Z value included:
'0101000000000000000000F03F000000000000F03F'
>>> wkb_w.outdim = 3  # Tell writer to include Z values
>>> wkb_w.write_hex(pnt)
'0101000080000000000000F03F000000000000F03F000000000000F03F'
```

#### `srid`

Set this property with a boolean to indicate whether the SRID of the
geometry should be included with the WKB representation. Example:

```pycon
>>> from django.contrib.gis.geos import Point, WKBWriter
>>> wkb_w = WKBWriter()
>>> pnt = Point(1, 1, srid=4326)
>>> wkb_w.write_hex(pnt)  # By default, no SRID included:
'0101000000000000000000F03F000000000000F03F'
>>> wkb_w.srid = True  # Tell writer to include SRID
>>> wkb_w.write_hex(pnt)
'0101000020E6100000000000000000F03F000000000000F03F'
```

#### `class WKTWriter(dim=2, trim=False, precision=None)`

Kelas ini mengeizinkan pengeluaran perwakilan WKT dari geometri. Lihat atribut [`WKBWriter.outdim`](#django.contrib.gis.geos.WKBWriter.outdim), [`trim`](#django.contrib.gis.geos.WKTWriter.trim), dan [`precision`](#django.contrib.gis.geos.WKTWriter.precision) untuk rincian tentang argumen pembangun.

#### `write(geom)`

Returns the WKT of the given geometry. Example:

```pycon
>>> from django.contrib.gis.geos import Point, WKTWriter
>>> pnt = Point(1, 1)
>>> wkt_w = WKTWriter()
>>> wkt_w.write(pnt)
'POINT (1.0000000000000000 1.0000000000000000)'
```

#### `outdim`

Lihat [`WKBWriter.outdim`](#django.contrib.gis.geos.WKBWriter.outdim).

#### `trim`

Sifat ini digunakan untuk mengadakan atau meniadakan memangkas dari desimal yang tidak diperlukan.

```pycon
>>> from django.contrib.gis.geos import Point, WKTWriter
>>> pnt = Point(1, 1)
>>> wkt_w = WKTWriter()
>>> wkt_w.trim
False
>>> wkt_w.write(pnt)
'POINT (1.0000000000000000 1.0000000000000000)'
>>> wkt_w.trim = True
>>> wkt_w.write(pnt)
'POINT (1 1)'
```

#### `precision`

Sifat ini mengendalikan ketelitian pembulatan dari kordinat; jika disetel menjadi `None` pembulatan adalah ditiadakan.

```
>>> from django.contrib.gis.geos import Point, WKTWriter
>>> pnt = Point(1.44, 1.66)
>>> wkt_w = WKTWriter()
>>> print(wkt_w.precision)
None
>>> wkt_w.write(pnt)
'POINT (1.4399999999999999 1.6599999999999999)'
>>> wkt_w.precision = 0
>>> wkt_w.write(pnt)
'POINT (1 2)'
>>> wkt_w.precision = 1
>>> wkt_w.write(pnt)
'POINT (1.4 1.7)'
```

**Catatan kaki**

[^1]: *Lihat* [PostGIS EWKB, EWKT and Canonical Forms](https://postgis.net/docs/using_postgis_dbmanagement.html#EWKB_EWKT), Dokumentasi PostGIS bab 4.1.2.

## Pengaturan

### `GEOS_LIBRARY_PATH`

A string specifying the location of the GEOS C library. Typically,
this setting is only used if the GEOS C library is in a non-standard
location (e.g., `/home/bob/lib/libgeos_c.so`).

> **Note**
>
> Pengaturan harus berupa jalur *penuh* pada pustaka berbagi *C*; dengan kata lain anda ingin menggunakan `libgeos_c.so`, bukan `libgeos.so`.

## Pengecualian

#### `exception GEOSException`

Pengecualian GEOS dasar, menunjukkan kesalahan terkait-GEOS.
