Geometry

Luo_Suppe2026-08-15

gma.gio.Geometry

class Geometry(data = None, gtype = None, crs = None):

Geometry object for vector data. Create a Geometry object.

Parameters:

data: varioustypes. Default None.

The data to create the geometry from. It can be: - None: create an empty geometry of type gtype.

- str: a string representation of the geometry in WKT, GeoJSON, GML, etc.

- list, tuple or np.ndarray: a collection of points to create the geometry from.

gtype: str. Default None.

The geometry type to create. It can be 'Point', 'LineString', 'Polygon', etc.

This parameter is required if data is a list, tuple or np.ndarray.

crs: str. Default None.

The projection of the geometry. If None, no projection is set.


Methods

add_geometry

[method] .add_geometry(other):

Add a geometry to this geometry.

Parameters:

other: Geometry.

The other geometry to add.


add_point

[method] .add_point(point):

Add a point to this geometry.

Parameters:

point: list||tuple.

The point coordinates to add. Should be a list or tuple of length 2, 3 or 4 depending on the geometry dimension.


buffer

[method] .buffer(distance, quadsecs = 30):

Compute buffer of geometry.

Parameters:

distance: float.

The buffer distance to be applied. Should be expressed into the same unit as the coordinates of the geometry.

Optional:

quadsecs = int. Default 30.

The number of segments used to approximate a 90 degree (quadrant) of curvature.

Returns:

Geometry:

The newly created geometry.


centroid

[method] .centroid():

Compute the geometry centroid.

Returns:

Geometry.


close_rings

[method] .close_rings():

Force rings to be closed.


concave_hull

[method] .concave_hull(ratio = 0.0, allow_holes = True):

concave_hull(double ratio, bool allowHoles) -> Geometry


contains

[method] .contains(other):

Test for containment.

Parameters:

other: Geometry.

the other geometry to compare.

Returns:

bool:

True if this contains the other geometry, otherwise False.


convex_hull

[method] .convex_hull():

Compute convex hull.

Returns:

Geometry:

a handle to A newly allocated geometry now owned by the caller.


copy

[method] .copy():

Make a copy of this object.

Returns:

Geometry:

The copy of the geometry with the same spatial reference system as the original.


crosses

[method] .crosses(other):

Test for crossing.

Parameters:

other: Geometry.

the other geometry to compare.

Returns:

bool:

True if they are crossing, otherwise False.


delaunay_triangulation

[method] .delaunay_triangulation(tolerance = 0.0, only_edges = True):

Return a Delaunay triangulation of the vertices of the geometry.

Optional:

dfTolerance = float||default0.

optional snapping tolerance to use for improved robustness

bOnlyEdges = bool||defaultTrue.

If True, will return a MULTILINESTRING, otherwise it will return a GEOMETRYCOLLECTION containing triangular POLYGONs.

Returns:

Geometry:

The geometry resulting from the Delaunay triangulation.


difference

[method] .difference(other):

Perform spatial difference between two Geometries.

Parameters:

other: Geometry.

The other geometry to overlay.

Returns:

Geometry:

A new geometry.


disjoint

[method] .disjoint(other):

Test for disjointness.

Parameters:

other: Geometry.

The other geometry to compare.

Returns:

bool:

True if they are disjoint, otherwise False.


distance

[method] .distance(other):

Compute distance between two geometries.

Parameters:

other: Geometry.

The other geometry to compare against.

Returns:

float:

The distance between the geometries or -1 if an error occurs.


empty

[method] .empty():

Clear geometry information.


equals

[method] .equals(other):

Parameters:

other: Geometry.

The other geometry to test against.

Returns:

bool:

True if equivalent or False otherwise.


extent

[method] .extent():

The extent of a geometry is the bounding rectangle.

Returns:

Type: Geometry.


flatten

[method] .flatten():

Convert geometry to strictly 2D.


get_area

[method] .get_area(geodesic = False):

Compute geometry area.

Optional:

geodesic = bool. Default False.

whether considered as a surface on the underlying ellipsoid of the SRS attached to the geometry.

Returns:

float:

the area in square meters, or a negative value for unsupported geometry types.


get_length

[method] .get_length(geodesic = False):

Compute geometry length.

Optional:

geodesic = bool. Default False.

whether considered as a surface on the underlying ellipsoid of the SRS attached to the geometry.

Returns:

float:

the area in meters, or a negative value for unsupported geometry types.


intersection

[method] .intersection(other):

Perform spatial intersection between two Geometries.

Parameters:

other: Geometry.

The other geometry to overlay.

Returns:

Geometry:

A new geometry.


intersects

[method] .intersects(other):

Determines whether two geometries intersect.

Parameters:

other: Geometry.

The other geometry to test against.

Returns:

bool:

True if the geometries intersect, otherwise False.


is_empty

[method] .is_empty():

Test if the geometry is empty.

Returns:

bool:

True if the geometry has no points, otherwise False.


is_measured

[method] .is_measured():

See whether this geometry is measured.

Returns:

bool:

True if the geometry has M coordinates.


is_ring

[method] .is_ring():

Test if the geometry is a ring.

Returns:

bool:

True if the geometry has no points, otherwise False.


is_simple

[method] .is_simple():

Returns:

bool:

True if object is simple, otherwise False.


is_valid

[method] .is_valid():

Test if the geometry is valid.

Returns:

bool:

True if the geometry has no points, otherwise False.


make_valid

[method] .make_valid(options = []):

Attempts to make an invalid geometry valid without losing vertices.

Optional:

options = list[str]. Default [].

papszOptions to be passed in. For example: ["METHOD=STRUCTURE"].

Returns:

Geometry:

A newly allocated geometry now owned by the caller.


normalize

[method] .normalize():

Attempts to bring geometry into normalized/canonical form.

Returns:

Geometry:

A newly allocated geometry now owned by the caller.


overlaps

[method] .overlaps(other):

Test for overlap.

Parameters:

other: Geometry.

the other geometry to compare.

Returns:

bool:

True if they are overlapping, otherwise False.


plot

[method] .plot(ax = None, **kwargs):

Make plots of Geometry.

Optional:

ax = None||matplotlib.~.AxesSubplot. Default None.

A matplotlib subplot. If None, a default axes will be created.

**kwargs.

Other plotting parameters. For more, see: ~.carto.utils.PolyCollection/LineCollection/PointCollection.

Returns:

matplotlib.~.AxesSubplot.


point_on_surface

[method] .point_on_surface():

Returns:

Geometry:

A point guaranteed to lie on the surface.


remove_geometry

[method] .remove_geometry(i):

remove_geometry(int iSubGeom)

Parameters:

i: int.

Sub geom's id.


remove_lower_dimension_sub_geoms

[method] .remove_lower_dimension_sub_geoms():

remove lower dimension sub geoms.


segmentize

[method] .segmentize(max_length):

Modify the geometry such it has no segment longer then the given distance.

Parameters:

max_length: float.

the maximum distance between 2 points after segmentization


set_crs

[method] .set_crs(crs):

Set the geometry's crs.

Parameters:

crs: str||int.

The output coordinate system. Can be EPSG, WKT, Proj4, and other types of coordinate characters. The default is no coordinate system!


set_dim

[method] .set_dim(dim = "XY"):

Set space dimension of geometry.

Optional:

dim = str. Default 'XY'.

Space dimensions. Can be 'XY', 'XYZ', 'XYM' or 'XYZM'.


simplify

[method] .simplify(tolerance, preserve_topology = False):

Compute a simplified geometry.

Parameters:

tolerance: float.

The distance tolerance for the simplification.

Optional:

preserve_topology = bool. Default False.

Simplify the geometry while preserving topology.

Returns:

Geometry:

The simplified geometry or None if an error occurs.


swap

[method] .swap():

Swap x and y coordinates.


sym_difference

[method] .sym_difference(other):

Perform spatial symmetric difference between two Geometries.

Parameters:

other: Geometry.

The other geometry to overlay.

Returns:

Geometry:

A new geometry.


to_bytearray

[method] .to_bytearray(stype = "wkb"):

Convert a geometry into bytearray.

Optional:

stype = str. Default 'wkb'.

Export string type: 'iso_wkb' or 'wkb'.

Returns:

bytes or str.


to_crs

[method] .to_crs(crs, copy = True):

Reproject geometry to new spatial reference system.

Parameters:

crs: CoordinateReferenceSystem.

The spatial reference system to apply.

Optional:

copy = bool. Default True.

Whether to return a copy of the reprojected geometry.

Returns:

Geometry(copy = True) or None(copy = False):


to_geom_base

[method] .to_geom_base():

Split complex geometry into basic geometries.

Returns:

dict of list of Geometry:

A dictionary containing lists of basic geometries categorized by their types: 'Polygon', 'LineString', and 'Point'.


to_points

[method] .to_points(ndim = 2, node = False):

Get all points from the geometry.

Parameters:

ndim: int. Default 0.

The number of dimensions for each point: 2, 3 or 4. If 0, it will use the geometry's own dimension.

Optional:

node = bool||defaultFalse.

Whether to add node markers for points.

Returns:

list of x, y points, vert's codes(codes = True):

A list containing all points in the geometry.


to_precision

[method] .to_precision(precision):

Set the geometry's precision.

Parameters:

precision: float.

Geometric coordinate precision. e.g: 0.001.


to_str

[method] .to_str(stype = "wkt"):

Convert a geometry into str / bytes.

Optional:

stype = str. Default 'wkt'.

Export string type: 'iso_wkt', 'json', 'kml' or 'wkt'.

Returns:

str.


touches

[method] .touches(other):

Test for touching.

Parameters:

other: Geometry.

the other geometry to compare.

Returns:

bool:

True if they are touching, otherwise False.


unary_union

[method] .unary_union():

Union all sum Geometries.

Returns:

Geometry.


union

[method] .union(other):

Perform spatial union between two Geometries.

Parameters:

other: Geometry.

The other geometry to overlay.

Returns:

Geometry:

A new geometry.


within

[method] .within(other):

Test for containment.

Parameters:

other: Geometry.

the other geometry to compare.

Returns:

bool:

True if this is within other, otherwise False.


wkb_size

[method] .wkb_size():

Returns:

int.


Property

boundary

Compute boundary.

Returns:

Geometry:

A new geometry.


bounds

Computes and returns the bounds for this geometry in the passed psEnvelope structure.

Returns:

list of float:

minx, maxx, miny, maxy


crs

Geometry coordinate reference system. -> CoordinateReferenceSystem


dim

The dimension of the geometry. -> str(XY(2), XYZ(3) and XYM(3), XYZM(4)).


gtype

Fetch WKT name for geometry type. -> str


Last Updated 8/15/2026, 8:42:21 AM