Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add points_from_xy to GeoSeries class #214

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion py-geopolars/python/geopolars/internals/geoseries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Iterable, TYPE_CHECKING

import polars as pl

Expand Down Expand Up @@ -205,6 +205,29 @@ def geoarrow_coords_to_numpy(struct_array: pyarrow.StructArray):

raise ValueError()

@classmethod
def points_from_xy(cls, x, y,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also want the type hints on x and y? Note that Iterable | pl.Series is a strict subset of what you can pass into pyarrow.StructArray; it also accepts numpy arrays and pyarrow arrays I think

z: Iterable | pl.Series | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the underlying geo algorithms support 3-dimensional data at this point, so my inclination was to not try to support 3d coordinates.

crs: str | pyproj.CRS | None = None
):
"""Generate a ``GeoSeries`` of ``POINT`` geometries
from ``x``, ``y`` (, ``z``) coordinates.

Parameters
----------
x, y, z: Iterable, pl.Series or NoneType
Point coordinates
crs: str, pyproj.CRS or NoneType, default None
Coordinate reference system
"""
coords = [x, y]
dims = ["x", "y"]
if z is not None:
coords.append(z)
dims.append("z")
parr = pyarrow.StructArray.from_arrays(coords, dims)
return cls(parr, _geom_type=GeometryType.POINT, crs=crs)

def affine_transform(self, matrix) -> GeoSeries:
"""Returns a ``GeoSeries`` with translated geometries.

Expand Down