Skip to content

Geometry Parsing

polars_st.from_wkb #

from_wkb(expr: IntoExprColumn) -> GeoExpr

Parse geometries from Well-Known Binary (WKB) representation.

Examples:

>>> df = pl.read_database(
...     query="SELECT ST_AsEWKB(geom) AS geometry FROM test_data",
...     connection=user_conn,
... )
>>> gdf = df.select(st.from_wkb("geometry"))

polars_st.from_wkt #

from_wkt(expr: IntoExprColumn) -> GeoExpr

Parse geometries from Well-Known Text (WKT) representation.

Examples:

>>> df = pl.Series("geometry", [
...     "POINT(0 0)",
...     "POINT(1 2)",
... ]).to_frame()
>>> gdf = df.select(st.from_wkt("geometry"))

polars_st.from_ewkt #

from_ewkt(expr: IntoExprColumn) -> GeoExpr

Parse geometries from Extended Well-Known Text (EWKT) representation.

Examples:

>>> df = pl.Series("geometry", [
...     "SRID=4326;POINT(0 0)",
...     "SRID=3857;POINT(1 2)",
... ]).to_frame()
>>> gdf = df.select(st.from_ewkt("geometry"))

polars_st.from_geojson #

from_geojson(expr: IntoExprColumn) -> GeoExpr

Parse geometries from GeoJSON representation.

Examples:

>>> df = pl.Series("geometry", [
...     '{"type": "Point", "coordinates": [0, 0]}',
...     '{"type": "Point", "coordinates": [1, 2]}',
... ]).to_frame()
>>> gdf = df.select(st.from_geojson("geometry"))

polars_st.from_xy #

from_xy(
    x: IntoDecimalExpr, y: IntoDecimalExpr, z: IntoDecimalExpr | None = None
) -> GeoExpr

Create points from x, y (, z) coordinates.

Examples:

>>> df = pl.DataFrame({
...     "x": [0, 1],
...     "y": [0, 2],
... })
>>> gdf = df.select(st.from_xy("x", "y"))

polars_st.from_shapely #

from_shapely(expr: IntoExprColumn) -> GeoExpr

Parse geometries from shapely objects.

Examples:

>>> import shapely
>>> df = pl.Series("geometry", [
...     shapely.Point(0, 0),
...     shapely.Point(1, 2),
... ], dtype=pl.Object).to_frame()
>>> gdf = df.select(st.from_shapely("geometry"))

polars_st.from_geopandas #

from_geopandas(
    data: GeoDataFrame | GeoSeries,
    *,
    schema_overrides: SchemaDict | None = None,
    rechunk: bool = True,
    nan_to_null: bool = True,
    include_index: bool = False
) -> GeoDataFrame | GeoSeries

Create DataFrame or Series from Geopandas GeoDataFrame or GeoSeries.

Examples:

>>> import shapely
>>> import geopandas as gpd
>>> pd_gdf = gpd.GeoDataFrame({
...     "geometry": [shapely.Point(0, 0), shapely.Point(1, 2)]
... }, crs="EPSG:4326")
>>> gdf = st.from_geopandas(pd_gdf)