Skip to content

Commit cfc80d5

Browse files
authored
[GH-2830] Add python / scala tests and add SRID-preservation tests for geography functions (#2870)
1 parent dca2035 commit cfc80d5

5 files changed

Lines changed: 702 additions & 27 deletions

File tree

python/sedona/spark/sql/st_constructors.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,123 @@ def ST_GeogFromWKT(
192192
return _call_constructor_function("ST_GeogFromWKT", args)
193193

194194

195+
@validate_argument_types
196+
def ST_GeogFromText(
197+
wkt: ColumnOrName, srid: Optional[ColumnOrNameOrNumber] = None
198+
) -> Column:
199+
"""Generate a geography column from a Well-Known Text (WKT) string column.
200+
This is an alias of ST_GeogFromWKT.
201+
202+
:param wkt: WKT string column to generate from.
203+
:type wkt: ColumnOrName
204+
:return: Geography column representing the WKT string.
205+
:rtype: Column
206+
"""
207+
args = (wkt) if srid is None else (wkt, srid)
208+
209+
return _call_constructor_function("ST_GeogFromText", args)
210+
211+
212+
@validate_argument_types
213+
def ST_GeogFromWKB(
214+
wkb: ColumnOrName, srid: Optional[ColumnOrNameOrNumber] = None
215+
) -> Column:
216+
"""Generate a geography column from a Well-Known Binary (WKB) binary column.
217+
218+
:param wkb: WKB binary column to generate from.
219+
:type wkb: ColumnOrName
220+
:return: Geography column representing the WKB binary.
221+
:rtype: Column
222+
"""
223+
args = (wkb) if srid is None else (wkb, srid)
224+
225+
return _call_constructor_function("ST_GeogFromWKB", args)
226+
227+
228+
@validate_argument_types
229+
def ST_GeogFromEWKB(wkb: ColumnOrName) -> Column:
230+
"""Generate a geography column from an OGC Extended Well-Known Binary (EWKB) binary column.
231+
232+
:param wkb: EWKB binary column to generate from.
233+
:type wkb: ColumnOrName
234+
:return: Geography column representing the EWKB binary.
235+
:rtype: Column
236+
"""
237+
return _call_constructor_function("ST_GeogFromEWKB", wkb)
238+
239+
240+
@validate_argument_types
241+
def ST_GeogFromEWKT(ewkt: ColumnOrName) -> Column:
242+
"""Generate a geography column from an OGC Extended Well-Known Text (EWKT) string column.
243+
244+
:param ewkt: EWKT string column to generate from.
245+
:type ewkt: ColumnOrName
246+
:return: Geography column representing the EWKT string.
247+
:rtype: Column
248+
"""
249+
return _call_constructor_function("ST_GeogFromEWKT", ewkt)
250+
251+
252+
@validate_argument_types
253+
def ST_GeogFromGeoHash(
254+
geohash: ColumnOrName, precision: Optional[Union[ColumnOrName, int]] = None
255+
) -> Column:
256+
"""Generate a geography column from a geohash column at a specified precision.
257+
258+
:param geohash: Geohash string column to generate from.
259+
:type geohash: ColumnOrName
260+
:param precision: Geohash precision to use, either an integer or an integer column.
261+
:type precision: Union[ColumnOrName, int]
262+
:return: Geography column representing the supplied geohash and precision level.
263+
:rtype: Column
264+
"""
265+
args = (geohash) if precision is None else (geohash, precision)
266+
267+
return _call_constructor_function("ST_GeogFromGeoHash", args)
268+
269+
270+
@validate_argument_types
271+
def ST_GeogCollFromText(
272+
wkt: ColumnOrName, srid: Optional[ColumnOrNameOrNumber] = None
273+
) -> Column:
274+
"""Generate a GeometryCollection geography from a GeometryCollection WKT representation.
275+
276+
:param wkt: GeometryCollection WKT string column to generate from.
277+
:type wkt: ColumnOrName
278+
:param srid: SRID for the geography.
279+
:type srid: ColumnOrNameOrNumber
280+
:return: GeometryCollection geography generated from the wkt column.
281+
:rtype: Column
282+
"""
283+
args = (wkt) if srid is None else (wkt, srid)
284+
285+
return _call_constructor_function("ST_GeogCollFromText", args)
286+
287+
288+
@validate_argument_types
289+
def ST_GeogToGeometry(geog: ColumnOrName) -> Column:
290+
"""Convert a geography column into a geometry column.
291+
292+
:param geog: Geography column to convert.
293+
:type geog: ColumnOrName
294+
:return: Geometry column representing the geography.
295+
:rtype: Column
296+
"""
297+
return _call_constructor_function("ST_GeogToGeometry", geog)
298+
299+
300+
@validate_argument_types
301+
def ST_GeomToGeography(geom: ColumnOrName) -> Column:
302+
"""Convert a geometry column into a geography column.
303+
304+
:param geom: Geometry column to convert.
305+
:type geom: ColumnOrName
306+
:return: Geography column representing the geometry.
307+
:rtype: Column
308+
"""
309+
return _call_constructor_function("ST_GeomToGeography", geom)
310+
311+
195312
@validate_argument_types
196313
def ST_GeomFromEWKT(ewkt: ColumnOrName) -> Column:
197314
"""Generate a geometry column from a OGC Extended Well-Known Text (WKT) string column.

0 commit comments

Comments
 (0)