@@ -211,3 +211,95 @@ def st_difference(
211
211
in other.
212
212
"""
213
213
return series ._apply_binary_op (other , ops .geo_st_difference_op )
214
+
215
+
216
+ def st_intersection (
217
+ series : bigframes .series .Series , other : bigframes .series .Series
218
+ ) -> bigframes .series .Series :
219
+ """
220
+ Returns a `GEOGRAPHY` that represents the point set intersection of the two
221
+ input `GEOGRAPHYs`. Thus, every point in the intersection appears in both
222
+ `geography_1` and `geography_2`.
223
+
224
+ .. note::
225
+ BigQuery's Geography functions, like `st_intersection`, interpret the geometry
226
+ data type as a point set on the Earth's surface. A point set is a set
227
+ of points, lines, and polygons on the WGS84 reference spheroid, with
228
+ geodesic edges. See: https://cloud.google.com/bigquery/docs/geospatial-data
229
+
230
+ **Examples:**
231
+
232
+ >>> import bigframes as bpd
233
+ >>> import bigframes.bigquery as bbq
234
+ >>> import bigframes.geopandas
235
+ >>> from shapely.geometry import Polygon, LineString, Point
236
+ >>> bpd.options.display.progress_bar = None
237
+
238
+ We can check two GeoSeries against each other, row by row.
239
+
240
+ >>> s1 = bigframes.geopandas.GeoSeries(
241
+ ... [
242
+ ... Polygon([(0, 0), (2, 2), (0, 2)]),
243
+ ... Polygon([(0, 0), (2, 2), (0, 2)]),
244
+ ... LineString([(0, 0), (2, 2)]),
245
+ ... LineString([(2, 0), (0, 2)]),
246
+ ... Point(0, 1),
247
+ ... ],
248
+ ... )
249
+ >>> s2 = bigframes.geopandas.GeoSeries(
250
+ ... [
251
+ ... Polygon([(0, 0), (1, 1), (0, 1)]),
252
+ ... LineString([(1, 0), (1, 3)]),
253
+ ... LineString([(2, 0), (0, 2)]),
254
+ ... Point(1, 1),
255
+ ... Point(0, 1),
256
+ ... ],
257
+ ... index=range(1, 6),
258
+ ... )
259
+
260
+ >>> s1
261
+ 0 POLYGON ((0 0, 2 2, 0 2, 0 0))
262
+ 1 POLYGON ((0 0, 2 2, 0 2, 0 0))
263
+ 2 LINESTRING (0 0, 2 2)
264
+ 3 LINESTRING (2 0, 0 2)
265
+ 4 POINT (0 1)
266
+ dtype: geometry
267
+
268
+ >>> s2
269
+ 1 POLYGON ((0 0, 1 1, 0 1, 0 0))
270
+ 2 LINESTRING (1 0, 1 3)
271
+ 3 LINESTRING (2 0, 0 2)
272
+ 4 POINT (1 1)
273
+ 5 POINT (0 1)
274
+ dtype: geometry
275
+
276
+ >>> bbq.st_intersection(s1, s2)
277
+ 0 None
278
+ 1 POLYGON ((0 0, 0.99954 1, 0 1, 0 0))
279
+ 2 POINT (1 1.00046)
280
+ 3 LINESTRING (2 0, 0 2)
281
+ 4 GEOMETRYCOLLECTION EMPTY
282
+ 5 None
283
+ dtype: geometry
284
+
285
+ We can also do intersection of each geometry and a single shapely geometry:
286
+
287
+ >>> bbq.st_intersection(s1, bigframes.geopandas.GeoSeries([Polygon([(0, 0), (1, 1), (0, 1)])]))
288
+ 0 POLYGON ((0 0, 0.99954 1, 0 1, 0 0))
289
+ 1 None
290
+ 2 None
291
+ 3 None
292
+ 4 None
293
+ dtype: geometry
294
+
295
+ Args:
296
+ other (GeoSeries or geometric object):
297
+ The Geoseries (elementwise) or geometric object to find the
298
+ intersection with.
299
+
300
+ Returns:
301
+ bigframes.geopandas.GeoSeries:
302
+ The Geoseries (elementwise) of the intersection of points in
303
+ each aligned geometry with other.
304
+ """
305
+ return series ._apply_binary_op (other , ops .geo_st_intersection_op )
0 commit comments