Skip to content

feat: add GeoSeries.boundary() #1435

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

Merged
merged 8 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 18 additions & 8 deletions bigframes/core/compile/scalar_op_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,14 +1001,9 @@ def normalize_op_impl(x: ibis_types.Value):


# Geo Ops
@scalar_op_compiler.register_unary_op(ops.geo_x_op)
def geo_x_op_impl(x: ibis_types.Value):
return typing.cast(ibis_types.GeoSpatialValue, x).x()


@scalar_op_compiler.register_unary_op(ops.geo_y_op)
def geo_y_op_impl(x: ibis_types.Value):
return typing.cast(ibis_types.GeoSpatialValue, x).y()
@scalar_op_compiler.register_unary_op(ops.geo_st_boundary_op, pass_op=False)
def geo_st_boundary_op_impl(x: ibis_types.Value):
return st_boundary(x)


@scalar_op_compiler.register_unary_op(ops.geo_area_op)
Expand All @@ -1035,6 +1030,16 @@ def geo_st_geogpoint_op_impl(x: ibis_types.Value, y: ibis_types.Value):
)


@scalar_op_compiler.register_unary_op(ops.geo_x_op)
def geo_x_op_impl(x: ibis_types.Value):
return typing.cast(ibis_types.GeoSpatialValue, x).x()


@scalar_op_compiler.register_unary_op(ops.geo_y_op)
def geo_y_op_impl(x: ibis_types.Value):
return typing.cast(ibis_types.GeoSpatialValue, x).y()


# Parameterized ops
@scalar_op_compiler.register_unary_op(ops.StructFieldOp, pass_op=True)
def struct_field_op_impl(x: ibis_types.Value, op: ops.StructFieldOp):
Expand Down Expand Up @@ -1965,6 +1970,11 @@ def unix_millis(a: ibis_dtypes.timestamp) -> int: # type: ignore
"""Convert a timestamp to milliseconds"""


@ibis_udf.scalar.builtin
def st_boundary(a: ibis_dtypes.geography) -> ibis_dtypes.geography: # type: ignore
"""Find the boundary of a geography."""


@ibis_udf.scalar.builtin
def unix_micros(a: ibis_dtypes.timestamp) -> int: # type: ignore
"""Convert a timestamp to microseconds"""
Expand Down
6 changes: 6 additions & 0 deletions bigframes/geopandas/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def area(self, crs=None) -> bigframes.series.Series: # type: ignore
f"GeoSeries.area is not supported. Use bigframes.bigquery.st_area(series), instead. {constants.FEEDBACK_LINK}"
)

@property
def boundary(self) -> bigframes.series.Series: # type: ignore
series = self._apply_unary_op(ops.geo_st_boundary_op)
series.name = None
return series

@classmethod
def from_wkt(cls, data, index=None) -> GeoSeries:
series = bigframes.series.Series(data, index=index)
Expand Down
2 changes: 2 additions & 0 deletions bigframes/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
from bigframes.operations.geo_ops import (
geo_area_op,
geo_st_astext_op,
geo_st_boundary_op,
geo_st_geogfromtext_op,
geo_st_geogpoint_op,
geo_x_op,
Expand Down Expand Up @@ -364,6 +365,7 @@
"manhattan_distance_op",
# Geo ops
"geo_area_op",
"geo_st_boundary_op",
"geo_st_astext_op",
"geo_st_geogfromtext_op",
"geo_st_geogpoint_op",
Expand Down
36 changes: 21 additions & 15 deletions bigframes/operations/geo_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,26 @@
from bigframes.operations import base_ops
import bigframes.operations.type as op_typing

geo_x_op = base_ops.create_unary_op(
name="geo_x",
type_signature=op_typing.FixedOutputType(
dtypes.is_geo_like, dtypes.FLOAT_DTYPE, description="geo-like"
),
)

geo_y_op = base_ops.create_unary_op(
name="geo_y",
type_signature=op_typing.FixedOutputType(
dtypes.is_geo_like, dtypes.FLOAT_DTYPE, description="geo-like"
),
)

geo_area_op = base_ops.create_unary_op(
name="geo_area",
type_signature=op_typing.FixedOutputType(
dtypes.is_geo_like, dtypes.FLOAT_DTYPE, description="geo-like"
),
)


geo_st_astext_op = base_ops.create_unary_op(
name="geo_st_astext",
type_signature=op_typing.FixedOutputType(
dtypes.is_geo_like, dtypes.STRING_DTYPE, description="geo-like"
),
)

geo_st_boundary_op = base_ops.create_unary_op(
name="geo_st_boundary",
type_signature=op_typing.FixedOutputType(
dtypes.is_geo_like, dtypes.GEO_DTYPE, description="geo-like"
),
)

geo_st_geogfromtext_op = base_ops.create_unary_op(
name="geo_st_geogfromtext",
Expand All @@ -53,6 +44,21 @@
),
)


geo_st_geogpoint_op = base_ops.create_binary_op(
name="geo_st_geogpoint", type_signature=op_typing.BinaryNumericGeo()
)

geo_x_op = base_ops.create_unary_op(
name="geo_x",
type_signature=op_typing.FixedOutputType(
dtypes.is_geo_like, dtypes.FLOAT_DTYPE, description="geo-like"
),
)

geo_y_op = base_ops.create_unary_op(
name="geo_y",
type_signature=op_typing.FixedOutputType(
dtypes.is_geo_like, dtypes.FLOAT_DTYPE, description="geo-like"
),
)
Loading