This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathgeoseries.py
More file actions
130 lines (106 loc) · 5.04 KB
/
geoseries.py
File metadata and controls
130 lines (106 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from typing import Optional
import bigframes_vendored.constants as constants
import bigframes_vendored.geopandas.geoseries as vendored_geoseries
import geopandas.array # type: ignore
import bigframes.operations as ops
import bigframes.series
import bigframes.session
class GeoSeries(vendored_geoseries.GeoSeries, bigframes.series.Series):
__doc__ = vendored_geoseries.GeoSeries.__doc__
def __init__(self, data=None, index=None, **kwargs):
super().__init__(
data=data, index=index, dtype=geopandas.array.GeometryDtype(), **kwargs
)
@property
def length(self):
raise NotImplementedError(
"GeoSeries.length is not yet implemented. Please use bigframes.bigquery.st_length(geoseries) instead."
)
@property
def x(self) -> bigframes.series.Series:
series = self._apply_unary_op(ops.geo_x_op)
series.name = None
return series
@property
def y(self) -> bigframes.series.Series:
series = self._apply_unary_op(ops.geo_y_op)
series.name = None
return series
# GeoSeries.area overrides Series.area with something totally different.
# Ignore this type error, as we are trying to be as close to geopandas as
# we can.
@property
def area(self, crs=None) -> bigframes.series.Series: # type: ignore
raise NotImplementedError(
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
@property
def is_closed(self) -> bigframes.series.Series:
# TODO(tswast): GeoPandas doesn't treat Point as closed. Use ST_LENGTH
# when available to filter out "closed" shapes that return false in
# GeoPandas.
raise NotImplementedError(
f"GeoSeries.is_closed is not supported. Use bigframes.bigquery.st_isclosed(series), instead. {constants.FEEDBACK_LINK}"
)
@classmethod
def from_wkt(
cls,
data,
index=None,
*,
session: Optional[bigframes.session.Session] = None,
) -> GeoSeries:
series = bigframes.series.Series(data, index=index, session=session)
return cls(series._apply_unary_op(ops.geo_st_geogfromtext_op))
@classmethod
def from_xy(cls, x, y, index=None, session=None, **kwargs) -> GeoSeries:
# TODO: if either x or y is local and the other is remote. Use the
# session from the remote object.
series_x = bigframes.series.Series(x, index=index, session=session, **kwargs)
series_y = bigframes.series.Series(y, index=index, session=session, **kwargs)
return cls(series_x._apply_binary_op(series_y, ops.geo_st_geogpoint_op))
def to_wkt(self: GeoSeries) -> bigframes.series.Series:
series = self._apply_unary_op(ops.geo_st_astext_op)
series.name = None
return series
def buffer(self: GeoSeries, distance: float) -> bigframes.series.Series: # type: ignore
raise NotImplementedError(
f"GeoSeries.buffer is not supported. Use bigframes.bigquery.st_buffer(series, distance), instead. {constants.FEEDBACK_LINK}"
)
@property
def centroid(self: GeoSeries) -> bigframes.series.Series: # type: ignore
return self._apply_unary_op(ops.geo_st_centroid_op)
@property
def convex_hull(self: GeoSeries) -> bigframes.series.Series: # type: ignore
return self._apply_unary_op(ops.geo_st_convexhull_op)
def difference(self: GeoSeries, other: GeoSeries) -> bigframes.series.Series: # type: ignore
return self._apply_binary_op(other, ops.geo_st_difference_op)
def distance(self: GeoSeries, other: GeoSeries) -> bigframes.series.Series: # type: ignore
raise NotImplementedError(
f"GeoSeries.distance is not supported. Use bigframes.bigquery.st_distance(series, other), instead. {constants.FEEDBACK_LINK}"
)
def intersection(self: GeoSeries, other: GeoSeries) -> bigframes.series.Series: # type: ignore
return self._apply_binary_op(other, ops.geo_st_intersection_op)
def simplify(self, tolerance, preserve_topology=True):
raise NotImplementedError(
f"GeoSeries.simplify is not supported. Use bigframes.bigquery.st_simplify(series, tolerance_meters), instead. {constants.FEEDBACK_LINK}"
)