Encapsulate an OGR geometry.
Attributes
| Attribute | Type | Description |
|---|
| destructor | callable = capi.destroy_geom | The C API function used to destroy the OGR geometry and free its memory. |
| geos_support | boolean = true | A boolean flag indicating whether this geometry class supports conversion to GEOS objects. |
| srs | [SpatialReference](../srs/spatialreference.md?sid=django_contrib_gis_gdal_srs_spatialreference) | Return the Spatial Reference for this Geometry. |
| srid | integer | The Spatial Reference Identifier (SRID) associated with the geometry's spatial reference system. |
| geojson | string | Return the GeoJSON representation of this Geometry. |
Constructor
Signature
def OGRGeometry(
geom_input: str, memoryview, [OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype), or c_void_p,
srs: [SpatialReference](../srs/spatialreference.md?sid=django_contrib_gis_gdal_srs_spatialreference), str, int, or None = None
) - > null
Parameters
| Name | Type | Description |
|---|
| geom_input | str, memoryview, [OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype), or c_void_p | The input data to construct the geometry from, such as WKT, HEX, GeoJSON, WKB bytes, an existing OGR pointer, or a geometry type. |
| srs | [SpatialReference](../srs/spatialreference.md?sid=django_contrib_gis_gdal_srs_spatialreference), str, int, or None = None | The spatial reference system to associate with the geometry. |
Methods
from_bbox()
@classmethod
def from_bbox(
bbox: tuple
) - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Construct a Polygon from a bounding box (4-tuple).
Parameters
| Name | Type | Description |
|---|
| bbox | tuple | A 4-tuple of (xmin, ymin, xmax, ymax) coordinates. |
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new Polygon geometry representing the bounding box. |
from_json()
@classmethod
def from_json(
geom_input: string
) - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Creates an OGRGeometry instance from a GeoJSON string or bytes.
Parameters
| Name | Type | Description |
|---|
| geom_input | string | The GeoJSON string used to define the geometry. |
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry object initialized from the GeoJSON data. |
from_gml()
@classmethod
def from_gml(
gml_string: string
) - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Creates an OGRGeometry instance from a GML string.
Parameters
| Name | Type | Description |
|---|
| gml_string | string | The GML string representing the geometry. |
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry object initialized from the GML data. |
dimension()
@classmethod
def dimension() - > integer
Return 0 for points, 1 for lines, and 2 for surfaces.
Returns
| Type | Description |
|---|
integer | The topological dimension of the geometry. |
coord_dim()
@classmethod
def coord_dim() - > integer
Return the coordinate dimension of the Geometry.
Returns
| Type | Description |
|---|
integer | The number of dimensions for each coordinate (e.g., 2 for XY, 3 for XYZ). |
geom_count()
@classmethod
def geom_count() - > integer
Return the number of elements in this Geometry.
Returns
| Type | Description |
|---|
integer | The count of sub-geometries within a collection or multi-geometry. |
point_count()
@classmethod
def point_count() - > integer
Return the number of Points in this Geometry.
Returns
| Type | Description |
|---|
integer | The total number of vertices in the geometry. |
num_points()
@classmethod
def num_points() - > integer
Alias for point_count (same name method in GEOS API.)
Returns
| Type | Description |
|---|
integer | The total number of vertices. |
num_coords()
@classmethod
def num_coords() - > integer
Alias for point_count.
Returns
| Type | Description |
|---|
integer | The total number of vertices. |
geom_type()
@classmethod
def geom_type() - > [OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype)
Return the Type for this Geometry.
Returns
| Type | Description |
|---|
[OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype) | An object representing the OGR geometry type. |
geom_name()
@classmethod
def geom_name() - > string
Return the Name of this Geometry.
Returns
| Type | Description |
|---|
string | The uppercase string name of the geometry type (e.g., 'POINT'). |
area()
@classmethod
def area() - > float
Return the area for a LinearRing, Polygon, or MultiPolygon; 0 otherwise.
Returns
| Type | Description |
|---|
float | The calculated area of the geometry. |
envelope()
@classmethod
def envelope() - > [Envelope](../envelope/envelope.md?sid=django_contrib_gis_gdal_envelope_envelope)
Return the envelope for this Geometry.
Returns
| Type | Description |
|---|
[Envelope](../envelope/envelope.md?sid=django_contrib_gis_gdal_envelope_envelope) | An Envelope object representing the bounding box. |
empty()
@classmethod
def empty() - > boolean
Checks if the geometry is empty.
Returns
| Type | Description |
|---|
boolean | True if the geometry has no points, False otherwise. |
extent()
@classmethod
def extent() - > tuple
Return the envelope as a 4-tuple, instead of as an Envelope object.
Returns
| Type | Description |
|---|
tuple | A 4-tuple of (xmin, ymin, xmax, ymax). |
is_3d()
@classmethod
def is_3d() - > boolean
Return True if the geometry has Z coordinates.
Returns
| Type | Description |
|---|
boolean | True if the geometry is 3D. |
set_3d()
@classmethod
def set_3d(
value: boolean
)
Set if this geometry has Z coordinates.
Parameters
| Name | Type | Description |
|---|
| value | boolean | Whether to enable or disable Z coordinates. |
is_measured()
@classmethod
def is_measured() - > boolean
Return True if the geometry has M coordinates.
Returns
| Type | Description |
|---|
boolean | True if the geometry includes measurement values. |
set_measured()
@classmethod
def set_measured(
value: boolean
)
Set if this geometry has M coordinates.
Parameters
| Name | Type | Description |
|---|
| value | boolean | Whether to enable or disable M coordinates. |
has_curve()
@classmethod
def has_curve() - > boolean
Return True if the geometry is or has curve geometry.
Returns
| Type | Description |
|---|
boolean | True if the geometry contains non-linear segments. |
get_linear_geometry()
@classmethod
def get_linear_geometry() - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return a linear version of this geometry.
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry where curves are approximated by linear segments. |
get_curve_geometry()
@classmethod
def get_curve_geometry() - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return a curve version of this geometry.
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry where linear segments are converted to curves if possible. |
geos()
@classmethod
def geos() - > [GEOSGeometry](../../geos/geometry/geosgeometry.md?sid=django_contrib_gis_geos_geometry_geosgeometry)
Return a GEOSGeometry object from this OGRGeometry.
Returns
| Type | Description |
|---|
[GEOSGeometry](../../geos/geometry/geosgeometry.md?sid=django_contrib_gis_geos_geometry_geosgeometry) | A GEOS-compatible version of this geometry. |
gml()
@classmethod
def gml() - > string
Return the GML representation of the Geometry.
Returns
| Type | Description |
|---|
string | The GML string. |
hex()
@classmethod
def hex() - > string
Return the hexadecimal representation of the WKB (a string).
Returns
| Type | Description |
|---|
string | The uppercase hex-encoded WKB string. |
json()
@classmethod
def json() - > string
Return the GeoJSON representation of this Geometry.
Returns
| Type | Description |
|---|
string | The GeoJSON string. |
kml()
@classmethod
def kml() - > string
Return the KML representation of the Geometry.
Returns
| Type | Description |
|---|
string | The KML string. |
wkb_size()
@classmethod
def wkb_size() - > integer
Return the size of the WKB buffer.
Returns
| Type | Description |
|---|
integer | The number of bytes required for the WKB representation. |
wkb()
@classmethod
def wkb() - > memoryview
Return the WKB representation of the Geometry.
Returns
| Type | Description |
|---|
memoryview | A memoryview containing the binary WKB data. |
wkt()
@classmethod
def wkt() - > string
Return the WKT representation of the Geometry.
Returns
| Type | Description |
|---|
string | The Well-Known Text string. |
ewkt()
@classmethod
def ewkt() - > string
Return the EWKT representation of the Geometry.
Returns
| Type | Description |
|---|
string | The Extended WKT string including SRID if available. |
clone()
@classmethod
def clone() - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Clone this OGR Geometry.
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new OGRGeometry instance that is a deep copy of the original. |
close_rings()
@classmethod
def close_rings()
If there are any rings within this geometry that have not been closed, this routine will do so by adding the starting point at the end.
@classmethod
def transform(
coord_trans: CoordTransform|SpatialReference|int|str,
clone: boolean = False
) - > OGRGeometry|None
Transform this geometry to a different spatial reference system.
Parameters
| Name | Type | Description |
|---|
| coord_trans | `CoordTransform | SpatialReference |
| clone | boolean = False | If True, returns a transformed copy instead of transforming in-place. |
Returns
| Type | Description |
|---|
| `OGRGeometry | None` |
intersects()
@classmethod
def intersects(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry intersects with the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test for intersection. |
Returns
| Type | Description |
|---|
boolean | True if geometries have at least one point in common. |
equals()
@classmethod
def equals(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry is equivalent to the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test for equality. |
Returns
| Type | Description |
|---|
boolean | True if geometries are spatially identical. |
disjoint()
@classmethod
def disjoint(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry and the other are spatially disjoint.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test for disjointness. |
Returns
| Type | Description |
|---|
boolean | True if geometries have no points in common. |
touches()
@classmethod
def touches(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry touches the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test for contact. |
Returns
| Type | Description |
|---|
boolean | True if geometries touch at least at one point but interiors do not intersect. |
crosses()
@classmethod
def crosses(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry crosses the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test for crossing. |
Returns
| Type | Description |
|---|
boolean | True if geometries cross each other. |
within()
@classmethod
def within(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry is within the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test as the container. |
Returns
| Type | Description |
|---|
boolean | True if this geometry is completely inside the other. |
contains()
@classmethod
def contains(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry contains the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test as the contained object. |
Returns
| Type | Description |
|---|
boolean | True if the other geometry is completely inside this one. |
overlaps()
@classmethod
def overlaps(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > boolean
Return True if this geometry overlaps the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to test for overlap. |
Returns
| Type | Description |
|---|
boolean | True if geometries overlap. |
boundary()
@classmethod
def boundary() - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return the boundary of this geometry.
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry representing the combinatorial boundary. |
convex_hull()
@classmethod
def convex_hull() - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return the smallest convex Polygon that contains all the points in this Geometry.
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new Polygon geometry representing the convex hull. |
difference()
@classmethod
def difference(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return a new geometry consisting of the region which is the difference of this geometry and the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to subtract. |
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry representing the point-set difference. |
intersection()
@classmethod
def intersection(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return a new geometry consisting of the region of intersection of this geometry and the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to intersect with. |
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry representing the shared region. |
sym_difference()
@classmethod
def sym_difference(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return a new geometry which is the symmetric difference of this geometry and the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The other geometry to compare. |
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry representing the symmetric difference. |
union()
@classmethod
def union(
other: [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
) - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return a new geometry consisting of the region which is the union of this geometry and the other.
Parameters
| Name | Type | Description |
|---|
| other | [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | The geometry to combine with. |
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A new geometry representing the combined region. |
centroid()
@classmethod
def centroid() - > [OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return the centroid (a Point) of this Polygon.
Returns
| Type | Description |
|---|
[OGRGeometry](ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A Point geometry representing the geometric center. |