snowflake.snowpark.functions.try_to_geography¶
- snowflake.snowpark.functions.try_to_geography(e: Union[snowflake.snowpark.column.Column, str], allow_invalid: Union[snowflake.snowpark.column.Column, str] = None) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.42.0/src/snowflake/snowpark/_functions/scalar_functions.py#L3887-L3916)¶
- Parses an input and attempts to produce a GEOGRAPHY value. If the input cannot be parsed as a GEOGRAPHY value, the function returns None instead of reporting an error. - Parameters:
- e (ColumnOrName) – A GEOGRAPHY object in WKT, WKB, EWKT, EWKB, or GeoJSON format. 
- allow_invalid (ColumnOrName, optional) – A boolean expression that specifies whether to allow invalid geometries. If True, invalid geometries are allowed and the function attempts to fix them. If False or None, invalid geometries cause the function to return None. 
 
- Returns:
- A GEOGRAPHY object if the input can be parsed successfully, otherwise None. 
- Return type:
 - Examples::
- >>> from snowflake.snowpark.functions import col, lit >>> df = session.create_dataframe([["POINT(-122.35 37.55)"], ["LINESTRING(-124.20 42.00, -120.01 41.99)"], ["Not a valid input"]], schema=["geog_text"]) >>> df.select(try_to_geography(col("geog_text")).alias("geography")).collect() [Row(GEOGRAPHY='{\n "coordinates": [\n -122.35,\n 37.55\n ],\n "type": "Point"\n}'), Row(GEOGRAPHY='{\n "coordinates": [\n [\n -124.2,\n 42\n ],\n [\n -120.01,\n 41.99\n ]\n ],\n "type": "LineString"\n}'), Row(GEOGRAPHY=None)] - >>> df = session.create_dataframe([["LINESTRING(100 102,100 102)"]], schema=["geog_text"]) >>> df.select(try_to_geography(col("geog_text"), lit(True)).alias("geography")).collect() [Row(GEOGRAPHY='{\n "coordinates": [\n [\n 100,\n 102\n ],\n [\n 100,\n 102\n ]\n ],\n "type": "LineString"\n}')]