Geospatial#
- class polars_extensions.geo.GeometryExtensionNamespace(expr: Expr)[source]#
Bases:
objectGeometry utilities for handling WKB, WKT, and coordinate conversion.
Methods
Convert Coordinates to Well-Known Binary
Convert Coordinates to Well-Known Text
Convert Well-Known Binary to Coordinates
Convert Well-Known Binary to Well-Known Text
Convert Well-Known Text to Coordinates
wkt_to_wkb([format])Convert Well-Known Text to Well-Known Binary
- coords_to_wkb() Expr[source]#
Convert Coordinates to Well-Known Binary
Examples
import polars as pl import polars_extensions as plx data = pl.DataFrame({ "geometry": [ [-101.044612343761, 45.139066210329], [-101.044119223429, 48.1390850482555], [-102.044733837176, 43.1389478003816], [-114.04470525049, 43.1385010700204], ] },schema_overrides={'geometry':pl.Object}) data.with_columns(pl.col('geometry').geo_ext.coords_to_wkb().alias('wkb'))
shape: (4, 2) ┌─────────────────────────────────┬─────────────────────────────────┐ │ geometry ┆ wkb │ │ --- ┆ --- │ │ object ┆ str │ ╞═════════════════════════════════╪═════════════════════════════════╡ │ [-101.044612343761, 45.1390662… ┆ 0101000000e45cbbedda4259c0bdab… │ │ [-101.044119223429, 48.1390850… ┆ 010100000029706fd9d24259c05bcf… │ │ [-102.044733837176, 43.1389478… ┆ 010100000083ec4febdc8259c0bc3e… │ │ [-114.04470525049, 43.13850107… ┆ 010100000019346973dc825cc06d19… │ └─────────────────────────────────┴─────────────────────────────────┘
- coords_to_wkt() Expr[source]#
Convert Coordinates to Well-Known Text
Examples
import polars as pl import polars_extensions as plx data = pl.DataFrame({ "geometry": [ [-101.044612343761, 45.139066210329], [-101.044119223429, 48.1390850482555], [-102.044733837176, 43.1389478003816], [-114.04470525049, 43.1385010700204], ] },schema_overrides={'geometry':pl.Object}) data.with_columns(pl.col('geometry').geo_ext.coords_to_wkt().alias('wkb'))
shape: (4, 2) ┌─────────────────────────────────┬─────────────────────────────────┐ │ geometry ┆ wkb │ │ --- ┆ --- │ │ object ┆ str │ ╞═════════════════════════════════╪═════════════════════════════════╡ │ [-101.044612343761, 45.1390662… ┆ POINT (-101.044612343761 45.13… │ │ [-101.044119223429, 48.1390850… ┆ POINT (-101.044119223429 48.13… │ │ [-102.044733837176, 43.1389478… ┆ POINT (-102.044733837176 43.13… │ │ [-114.04470525049, 43.13850107… ┆ POINT (-114.04470525049 43.138… │ └─────────────────────────────────┴─────────────────────────────────┘
- wkb_to_coords() Expr[source]#
Convert Well-Known Binary to Coordinates
Examples
import polars as pl import polars_extensions as plx data = pl.DataFrame({ "geometry": [ [-101.044612343761, 45.139066210329], [-101.044119223429, 48.1390850482555], [-102.044733837176, 43.1389478003816], [-114.04470525049, 43.1385010700204], ] },schema_overrides={'geometry':pl.Object}) data.with_columns(pl.col('geometry').geo_ext.coords_to_wkt().alias('wkt'))
shape: (4, 2) ┌─────────────────────────────────┬─────────────────────────────────┐ │ geometry ┆ wkt │ │ --- ┆ --- │ │ object ┆ str │ ╞═════════════════════════════════╪═════════════════════════════════╡ │ [-101.044612343761, 45.1390662… ┆ POINT (-101.044612343761 45.13… │ │ [-101.044119223429, 48.1390850… ┆ POINT (-101.044119223429 48.13… │ │ [-102.044733837176, 43.1389478… ┆ POINT (-102.044733837176 43.13… │ │ [-114.04470525049, 43.13850107… ┆ POINT (-114.04470525049 43.138… │ └─────────────────────────────────┴─────────────────────────────────┘
- wkb_to_wkt() Expr[source]#
Convert Well-Known Binary to Well-Known Text
Examples
import polars as pl import polars_extensions as plx data = pl.DataFrame({ "wkb": [ '0101000000e45cbbedda4259c0bdabecebcc914640', '010100000029706fd9d24259c05bcff289cd114840', '010100000083ec4febdc8259c0bc3ea10ac9914540', '010100000019346973dc825cc06d192f67ba914540', ] }) data.with_columns(pl.col('wkb').geo_ext.wkb_to_wkt().alias('wkt'))
shape: (4, 2) ┌─────────────────────────────────┬─────────────────────────────────┐ │ wkb ┆ wkt │ │ --- ┆ --- │ │ str ┆ str │ ╞═════════════════════════════════╪═════════════════════════════════╡ │ 0101000000e45cbbedda4259c0bdab… ┆ POINT (-101.044612343761 45.13… │ │ 010100000029706fd9d24259c05bcf… ┆ POINT (-101.044119223429 48.13… │ │ 010100000083ec4febdc8259c0bc3e… ┆ POINT (-102.044733837176 43.13… │ │ 010100000019346973dc825cc06d19… ┆ POINT (-114.04470525049 43.138… │ └─────────────────────────────────┴─────────────────────────────────┘
- wkt_to_coords() Expr[source]#
Convert Well-Known Text to Coordinates
Examples
import polars as pl import polars_extensions as plx data = pl.DataFrame({ "geometry": [ "POINT (-101.044612343761 45.139066210329)", "POINT (-101.044119223429 48.1390850482555)", "POINT (-102.044733837176 43.1389478003816)", "POINT (-114.04470525049 43.1385010700204)", ] }) data.with_columns(pl.col('geometry').geo_ext.wkt_to_coords().alias('coords'))
shape: (4, 2) ┌─────────────────────────────────┬─────────────────────────────────┐ │ geometry ┆ coords │ │ --- ┆ --- │ │ str ┆ object │ ╞═════════════════════════════════╪═════════════════════════════════╡ │ POINT (-101.044612343761 45.13… ┆ [-101.044612343761, 45.1390662… │ │ POINT (-101.044119223429 48.13… ┆ [-101.044119223429, 48.1390850… │ │ POINT (-102.044733837176 43.13… ┆ [-102.044733837176, 43.1389478… │ │ POINT (-114.04470525049 43.138… ┆ [-114.04470525049, 43.13850107… │ └─────────────────────────────────┴─────────────────────────────────┘
- wkt_to_wkb(format='raw') Expr[source]#
Convert Well-Known Text to Well-Known Binary
Examples
import polars as pl import polars_extensions as plx data = pl.DataFrame({ "geometry": [ "POINT (-101.044612343761 45.139066210329)", "POINT (-101.044119223429 48.1390850482555)", "POINT (-102.044733837176 43.1389478003816)", "POINT (-114.04470525049 43.1385010700204)", ] }) data.with_columns( pl.col('geometry').geo_ext.wkt_to_wkb().alias('coords'))
shape: (4, 2) ┌─────────────────────────────────┬─────────────────────────────────┐ │ geometry ┆ coords │ │ --- ┆ --- │ │ str ┆ binary │ ╞═════════════════════════════════╪═════════════════════════════════╡ │ POINT (-101.044612343761 45.13… ┆ b"ä\xb… │ │ POINT (-101.044119223429 48.13… ┆ b")poÙ\… │ │ POINT (-102.044733837176 43.13… ┆ b"ì… │ │ POINT (-114.04470525049 43.138… ┆ b"4is\… │ └─────────────────────────────────┴─────────────────────────────────┘