Skip to content

GeoExpr

polars_st.GeoExpr #

Bases: Expr

A GeoExpr is a regular polars.Expr with type annotations added for the st namespace.

st property #

polars_st.GeoExprNameSpace #

polars_st.GeoExprNameSpace.geometry_type #

geometry_type() -> Expr

Return the type ID of each geometry.

  • 0 = Unknown
  • 1 = Point
  • 2 = LineString
  • 3 = Polygon
  • 4 = MultiPoint
  • 5 = MultiLineString
  • 6 = MultiPolygon
  • 7 = GeometryCollection
  • 8 = CircularString
  • 9 = CompoundCurve
  • 10 = CurvePolygon
  • 11 = MultiCurve
  • 12 = MultiSurface
  • 13 = Curve
  • 14 = Surface
  • 15 = PolyhedralSurface
  • 16 = Tin
  • 17 = Triangle

Examples:

>>> gdf = st.GeoDataFrame([
...     "POINT(0 0)",
...     "LINESTRING(0 0, 1 2)",
...     "POLYGON((0 0, 1 1, 1 0, 0 0))"
... ])
>>> gdf.select(st.geom().st.geometry_type())
shape: (3, 1)
┌──────────┐
│ geometry │
│ ---      │
│ u32      │
╞══════════╡
│ 1        │
│ 2        │
│ 3        │
└──────────┘

polars_st.GeoExprNameSpace.dimensions #

dimensions() -> Expr

Return the inherent dimensionality of each geometry.

The inherent dimension is 0 for points, 1 for linestrings and linearrings, and 2 for polygons. For geometrycollections it is the max of the containing elements.

Examples:

>>> gdf = st.GeoDataFrame([
...     "POINT(0 0)",
...     "LINESTRING(0 0, 1 2)",
...     "POLYGON((0 0, 1 1, 1 0, 0 0))"
... ])
>>> gdf.select(st.geom().st.dimensions())
shape: (3, 1)
┌──────────┐
│ geometry │
│ ---      │
│ u32      │
╞══════════╡
│ 0        │
│ 1        │
│ 2        │
└──────────┘

polars_st.GeoExprNameSpace.coordinate_dimension #

coordinate_dimension() -> Expr

Return the coordinate dimension (2, 3 or 4) of each geometry.

polars_st.GeoExprNameSpace.area #

area() -> Expr

Return the area of each geometry.

polars_st.GeoExprNameSpace.bounds #

bounds() -> Expr

Return the bounds of each geometry.

polars_st.GeoExprNameSpace.length #

length() -> Expr

Return the length of each geometry.

polars_st.GeoExprNameSpace.minimum_clearance #

minimum_clearance() -> Expr

Return the geometry minimum clearance.

polars_st.GeoExprNameSpace.x #

x() -> Expr

Return the x value of Point geometries.

polars_st.GeoExprNameSpace.y #

y() -> Expr

Return the y value of Point geometries.

polars_st.GeoExprNameSpace.z #

z() -> Expr

Return the z value of Point geometries.

polars_st.GeoExprNameSpace.m #

m() -> Expr

Return the m value of Point geometries.

polars_st.GeoExprNameSpace.count_coordinates #

count_coordinates() -> Expr

Return the number of coordinates in each geometry.

polars_st.GeoExprNameSpace.coordinates #

coordinates(output_dimension: Literal[2, 3] = 2) -> Expr

Return the coordinates of each geometry.

polars_st.GeoExprNameSpace.count_geometries #

count_geometries() -> Expr

Return the number of parts in multipart geometries.

polars_st.GeoExprNameSpace.get_geometry #

get_geometry(index: IntoIntegerExpr) -> GeoExpr

Return the nth part of multipart geometries.

polars_st.GeoExprNameSpace.count_points #

count_points() -> Expr

Return the number of points in LineString geometries.

polars_st.GeoExprNameSpace.get_point #

get_point(index: IntoIntegerExpr) -> GeoExpr

Return the nth point of LineString geometries.

polars_st.GeoExprNameSpace.count_interior_rings #

count_interior_rings() -> Expr

Return the number of interior rings in Polygon geometries.

polars_st.GeoExprNameSpace.get_interior_ring #

get_interior_ring(index: IntoIntegerExpr) -> GeoExpr

Return the nth ring of Polygon geometries.

polars_st.GeoExprNameSpace.exterior_ring #

exterior_ring() -> GeoExpr

Return the exterior ring of Polygon geometries.

polars_st.GeoExprNameSpace.rings #

rings() -> Expr

Return the list of rings for Polygon geometries.

polars_st.GeoExprNameSpace.parts #

parts() -> Expr

Return the list of parts for multipart geometries.

polars_st.GeoExprNameSpace.precision #

precision() -> Expr

Return the precision of each geometry.

polars_st.GeoExprNameSpace.set_precision #

set_precision(
    grid_size: IntoDecimalExpr,
    mode: Literal["valid_output", "no_topo", "keep_collapsed"] = "valid_output",
) -> GeoExpr

Set the precision of each geometry to a certain grid size.

polars_st.GeoExprNameSpace.distance #

distance(other: IntoGeoExprColumn) -> Expr

Return the distance from each geometry to other.

polars_st.GeoExprNameSpace.hausdorff_distance #

hausdorff_distance(
    other: IntoGeoExprColumn, densify: float | None = None
) -> Expr

Return the hausdorff distance from each geometry to other.

polars_st.GeoExprNameSpace.frechet_distance #

frechet_distance(
    other: IntoGeoExprColumn, densify: float | None = None
) -> Expr

Return the frechet distance from each geometry to other.

polars_st.GeoExprNameSpace.srid #

srid() -> Expr

Return the geometry SRID.

polars_st.GeoExprNameSpace.set_srid #

set_srid(srid: IntoIntegerExpr) -> GeoExpr

Set the SRID of each geometry to a given value.

Parameters:

  • srid (IntoIntegerExpr) –

    The geometry new SRID

polars_st.GeoExprNameSpace.to_srid #

to_srid(srid: IntoIntegerExpr) -> GeoExpr

Transform the coordinates of each geometry into a new CRS.

Parameters:

  • srid (IntoIntegerExpr) –

    The geometry new SRID

polars_st.GeoExprNameSpace.to_wkt #

to_wkt(
    rounding_precision: int | None = 6,
    trim: bool = True,
    output_dimension: Literal[2, 3, 4] = 3,
    old_3d: bool = False,
) -> Expr

Serialize each geometry as WKT (Well-Known Text).

Parameters:

  • rounding_precision (int | None, default: 6 ) –

    The rounding precision when writing the WKT string. Set to None to indicate the full precision.

  • trim (bool, default: True ) –

    If True, trim unnecessary decimals (trailing zeros).

  • output_dimension (Literal[2, 3, 4], default: 3 ) –

    The output dimension for the WKT string. Specifying 3 means that up to 3 dimensions will be written but 2D geometries will still be represented as 2D in the WKT string.

  • old_3d (bool, default: False ) –

    Enable old style 3D/4D WKT generation. By default, new style 3D/4D WKT (ie. “POINT Z (10 20 30)”) is returned, but with old_3d=True the WKT will be formatted in the style “POINT (10 20 30)”.

polars_st.GeoExprNameSpace.to_ewkt #

to_ewkt(
    rounding_precision: int | None = 6,
    trim: bool = True,
    output_dimension: Literal[2, 3, 4] = 3,
    old_3d: bool = False,
) -> Expr

Serialize each geometry as EWKT (Extended Well-Known Text).

Parameters:

  • rounding_precision (int | None, default: 6 ) –

    The rounding precision when writing the WKT string. Set to None to indicate the full precision.

  • trim (bool, default: True ) –

    If True, trim unnecessary decimals (trailing zeros).

  • output_dimension (Literal[2, 3, 4], default: 3 ) –

    The output dimension for the WKT string. Specifying 3 means that up to 3 dimensions will be written but 2D geometries will still be represented as 2D in the WKT string.

  • old_3d (bool, default: False ) –

    Enable old style 3D/4D WKT generation. By default, new style 3D/4D WKT (ie. “POINT Z (10 20 30)”) is returned, but with old_3d=True the WKT will be formatted in the style “POINT (10 20 30)”.

polars_st.GeoExprNameSpace.to_wkb #

to_wkb(
    output_dimension: Literal[2, 3, 4] = 3,
    byte_order: Literal[0, 1] | None = None,
    include_srid: bool = False,
) -> Expr

Serialize each geometry as WKB (Well-Known Binary).

Parameters:

  • output_dimension

    The output dimension for the WKB. Specifying 3 means that up to 3 dimensions will be written but 2D geometries will still be represented as 2D in the WKB representation.

  • byte_order (Literal[0, 1] | None, default: None ) –

    Defaults to native machine byte order (None). Use 0 to force big endian and 1 for little endian.

  • include_srid (bool, default: False ) –

    If True, the SRID is be included in WKB (this is an extension to the OGC WKB specification).

polars_st.GeoExprNameSpace.to_geojson #

to_geojson(indent: int | None = None) -> Expr

Serialize each geometry as GeoJSON.

Parameters:

  • indent (int | None, default: None ) –

    If indent is not None, then GeoJSON will be pretty-printed. An indent level of 0 will only insert newlines. None (the default) outputs the most compact representation.

polars_st.GeoExprNameSpace.to_shapely #

to_shapely() -> Expr

Convert each geometry to a Shapely object.

polars_st.GeoExprNameSpace.to_dict #

to_dict() -> Expr

Convert each geometry to a GeoJSON-like Python dict object.

polars_st.GeoExprNameSpace.has_z #

has_z() -> Expr

Return True for each geometry with z coordinate values.

polars_st.GeoExprNameSpace.has_m #

has_m() -> Expr

Return True for each geometry with m coordinate values.

polars_st.GeoExprNameSpace.is_ccw #

is_ccw() -> Expr

Return True for linear geometries with counter-clockwise coord sequence.

polars_st.GeoExprNameSpace.is_closed #

is_closed() -> Expr

Return True for closed linear geometries.

polars_st.GeoExprNameSpace.is_empty #

is_empty() -> Expr

Return True for empty geometries.

polars_st.GeoExprNameSpace.is_ring #

is_ring() -> Expr

Return True for ring geometries.

polars_st.GeoExprNameSpace.is_simple #

is_simple() -> Expr

Return True for simple geometries.

polars_st.GeoExprNameSpace.is_valid #

is_valid() -> Expr

Return True for valid geometries.

polars_st.GeoExprNameSpace.is_valid_reason #

is_valid_reason() -> Expr

Return an explanation string for the invalidity of each geometry.

polars_st.GeoExprNameSpace.crosses #

crosses(other: IntoGeoExprColumn) -> Expr

Return True when each geometry crosses other.

polars_st.GeoExprNameSpace.contains #

contains(other: IntoGeoExprColumn) -> Expr

Return True when each geometry contains other.

polars_st.GeoExprNameSpace.contains_properly #

contains_properly(other: IntoGeoExprColumn) -> Expr

Return True when each geometry properly contains other.

polars_st.GeoExprNameSpace.covered_by #

covered_by(other: IntoGeoExprColumn) -> Expr

Return True when each geometry is covered by other.

polars_st.GeoExprNameSpace.covers #

covers(other: IntoGeoExprColumn) -> Expr

Return True when each geometry covers other.

polars_st.GeoExprNameSpace.disjoint #

disjoint(other: IntoGeoExprColumn) -> Expr

Return True when each geometry is disjoint from other.

polars_st.GeoExprNameSpace.dwithin #

dwithin(other: IntoGeoExprColumn, distance: float) -> Expr

Return True when each geometry is within a given distance to other.

polars_st.GeoExprNameSpace.intersects #

intersects(other: IntoGeoExprColumn) -> Expr

Return True when each geometry intersects other.

polars_st.GeoExprNameSpace.overlaps #

overlaps(other: IntoGeoExprColumn) -> Expr

Return True when each geometry overlaps other.

polars_st.GeoExprNameSpace.touches #

touches(other: IntoGeoExprColumn) -> Expr

Return True when each geometry touches other.

polars_st.GeoExprNameSpace.within #

within(other: IntoGeoExprColumn) -> Expr

Return True when each geometry is within other.

polars_st.GeoExprNameSpace.equals #

equals(other: IntoGeoExprColumn) -> Expr

Return True when each geometry is equal to other.

polars_st.GeoExprNameSpace.equals_exact #

equals_exact(other: IntoGeoExprColumn, tolerance: float = 0.0) -> Expr

Return True when each geometry is equal to other.

polars_st.GeoExprNameSpace.equals_identical #

equals_identical(other: IntoGeoExprColumn) -> Expr

Return True when each geometry is equal to other.

polars_st.GeoExprNameSpace.relate #

relate(other: IntoGeoExprColumn) -> Expr

Return the DE-9IM intersection matrix of each geometry with other.

polars_st.GeoExprNameSpace.relate_pattern #

relate_pattern(other: IntoGeoExprColumn, pattern: str) -> Expr

Return True when the DE-9IM intersection matrix of geometry with other matches a given pattern.

polars_st.GeoExprNameSpace.union #

union(other: IntoGeoExprColumn, grid_size: float | None = None) -> GeoExpr

Return the union of each geometry with other.

polars_st.GeoExprNameSpace.unary_union #

unary_union(grid_size: float | None = None) -> GeoExpr

Return the unary union of each geometry.

polars_st.GeoExprNameSpace.coverage_union #

coverage_union() -> GeoExpr

Return the coverage union of each geometry with other.

polars_st.GeoExprNameSpace.intersection #

intersection(
    other: IntoGeoExprColumn, grid_size: float | None = None
) -> GeoExpr

Return the intersection of each geometry with other.

polars_st.GeoExprNameSpace.difference #

difference(other: IntoGeoExprColumn, grid_size: float | None = None) -> GeoExpr

Return the difference of each geometry with other.

polars_st.GeoExprNameSpace.symmetric_difference #

symmetric_difference(
    other: IntoGeoExprColumn, grid_size: float | None = None
) -> GeoExpr

Return the symmetric difference of each geometry with other.

polars_st.GeoExprNameSpace.boundary #

boundary() -> GeoExpr

Return the topological boundary of each geometry.

polars_st.GeoExprNameSpace.buffer #

buffer(
    distance: IntoDecimalExpr,
    quad_segs: int = 8,
    cap_style: Literal["round", "square", "flat"] = "round",
    join_style: Literal["round", "mitre", "bevel"] = "round",
    mitre_limit: float = 5.0,
    single_sided: bool = False,
) -> GeoExpr

Return a buffer around each geometry.

polars_st.GeoExprNameSpace.offset_curve #

offset_curve(
    distance: IntoDecimalExpr,
    quad_segs: int = 8,
    join_style: Literal["round", "mitre", "bevel"] = "round",
    mitre_limit: float = 5.0,
) -> GeoExpr

Return a line at a given distance of each geometry.

polars_st.GeoExprNameSpace.centroid #

centroid() -> GeoExpr

Return the centroid of each geometry.

polars_st.GeoExprNameSpace.clip_by_rect #

clip_by_rect(xmin: float, ymin: float, xmax: float, ymax: float) -> GeoExpr

Clip each geometry by a bounding rectangle.

polars_st.GeoExprNameSpace.convex_hull #

convex_hull() -> GeoExpr

Return the convex hull of each geometry.

polars_st.GeoExprNameSpace.concave_hull #

concave_hull(ratio: float = 0.0, allow_holes: bool = False) -> GeoExpr

Return the concave hull of each geometry.

polars_st.GeoExprNameSpace.segmentize #

segmentize(max_segment_length: IntoDecimalExpr) -> GeoExpr

polars_st.GeoExprNameSpace.envelope #

envelope() -> GeoExpr

Return the envelope of each geometry.

polars_st.GeoExprNameSpace.extract_unique_points #

extract_unique_points() -> GeoExpr

polars_st.GeoExprNameSpace.build_area #

build_area() -> GeoExpr

polars_st.GeoExprNameSpace.make_valid #

make_valid() -> GeoExpr

polars_st.GeoExprNameSpace.normalize #

normalize() -> GeoExpr

polars_st.GeoExprNameSpace.node #

node() -> GeoExpr

polars_st.GeoExprNameSpace.point_on_surface #

point_on_surface() -> GeoExpr

Return a point that intersects of each geometry.

polars_st.GeoExprNameSpace.remove_repeated_points #

remove_repeated_points(tolerance: IntoDecimalExpr = 0.0) -> GeoExpr

Remove the repeated points for each geometry.

polars_st.GeoExprNameSpace.reverse #

reverse() -> GeoExpr

Reverse the coordinates order of each geometry.

polars_st.GeoExprNameSpace.simplify #

simplify(tolerance: IntoDecimalExpr, preserve_topology: bool = True) -> GeoExpr

Simplify each geometry with a given tolerance.

polars_st.GeoExprNameSpace.minimum_rotated_rectangle #

minimum_rotated_rectangle() -> GeoExpr

polars_st.GeoExprNameSpace.snap #

snap(other: IntoGeoExprColumn, tolerance: IntoDecimalExpr) -> GeoExpr

polars_st.GeoExprNameSpace.shortest_line #

shortest_line(other: IntoGeoExprColumn) -> GeoExpr

Return the shortest line between each geometry and other.

polars_st.GeoExprNameSpace.interpolate #

interpolate(distance: IntoDecimalExpr, normalized: bool = False) -> GeoExpr

polars_st.GeoExprNameSpace.line_merge #

line_merge(directed: bool = False) -> GeoExpr

polars_st.GeoExprNameSpace.shared_paths #

shared_paths(other: IntoGeoExprColumn) -> GeoExpr

polars_st.GeoExprNameSpace.total_bounds #

total_bounds() -> Expr

Return the total bounds of all geometries.

polars_st.GeoExprNameSpace.multipoint #

multipoint() -> GeoExpr

Aggregate Point geometries into a single MultiPoint.

polars_st.GeoExprNameSpace.multilinestring #

multilinestring() -> GeoExpr

Aggregate LineString geometries into a single MultiLineString.

polars_st.GeoExprNameSpace.multipolygon #

multipolygon() -> GeoExpr

Aggregate Polygon geometries into a single MultiPolygon.

polars_st.GeoExprNameSpace.geometrycollection #

geometrycollection() -> GeoExpr

Aggregate geometries into a single GeometryCollection.

polars_st.GeoExprNameSpace.collect #

collect() -> GeoExpr

Aggregate geometries into a single MultiPart geometry or GeometryCollection.

polars_st.GeoExprNameSpace.union_all #

union_all(grid_size: float | None = None) -> GeoExpr

Return the union of all geometries.

polars_st.GeoExprNameSpace.coverage_union_all #

coverage_union_all() -> GeoExpr

Return the coverage union of all geometries.

polars_st.GeoExprNameSpace.intersection_all #

intersection_all(grid_size: float | None = None) -> GeoExpr

Return the intersection of all geometries.

polars_st.GeoExprNameSpace.difference_all #

difference_all(grid_size: float | None = None) -> GeoExpr

Return the difference of all geometries.

polars_st.GeoExprNameSpace.symmetric_difference_all #

symmetric_difference_all(grid_size: float | None = None) -> GeoExpr

Return the symmetric difference of all geometries.

polars_st.GeoExprNameSpace.polygonize #

polygonize() -> GeoExpr

polars_st.GeoExprNameSpace.voronoi_polygons #

voronoi_polygons(
    tolerance: float = 0.0,
    extend_to: bytes | None = None,
    only_edges: bool = False,
) -> GeoExpr

Return a Voronoi diagram of all geometries vertices.

polars_st.GeoExprNameSpace.delaunay_triangles #

delaunay_triangles(tolerance: float = 0.0, only_edges: bool = False) -> GeoExpr

Return a Delaunay triangulation of all geometries vertices.