snowflake.snowpark.functions.try_to_geometry

snowflake.snowpark.functions.try_to_geometry(input_expr: Union[snowflake.snowpark.column.Column, str], srid: Union[snowflake.snowpark.column.Column, str] = None, allow_invalid: Union[snowflake.snowpark.column.Column, str] = None) Column[source]

Attempts to parse a string or binary value as a GEOMETRY object. Returns None if the input cannot be parsed as a valid geometry.

Parameters:
  • input_expr (ColumnOrName) – The GEOMETRY data to parse.

  • srid (ColumnOrName, optional) – The spatial reference system identifier to assign to the GEOMETRY.

  • allow_invalid (ColumnOrName, optional) – Whether to allow invalid geometries to be returned.

Returns:

A GEOMETRY object if parsing succeeds, None otherwise

Return type:

Column

Examples::
>>> df1 = session.create_dataframe([["POINT(1 2)"]], schema=["geom_str"])
>>> df1.select(try_to_geometry(df1["geom_str"]).alias("geometry")).collect()
[Row(GEOMETRY='{\n  "coordinates": [\n    1.000000000000000e+00,\n    2.000000000000000e+00\n  ],\n  "type": "Point"\n}')]
Copy
>>> df2 = session.create_dataframe([["POINT(1 2)"]], schema=["geom_str"])
>>> df2.select(try_to_geometry(df2["geom_str"], lit(4326)).alias("geometry")).collect()
[Row(GEOMETRY='{\n  "coordinates": [\n    1.000000000000000e+00,\n    2.000000000000000e+00\n  ],\n  "type": "Point"\n}')]
Copy
>>> df3 = session.create_dataframe([["INVALID INPUT"]], schema=["geom_str"])
>>> df3.select(try_to_geometry(df3["geom_str"]).alias("geometry")).collect()
[Row(GEOMETRY=None)]
Copy
>>> df4 = session.create_dataframe([["POINT(1 2)"]], schema=["geom_str"])
>>> df4.select(try_to_geometry(df4["geom_str"], lit(4326), lit(True)).alias("geometry")).collect()
[Row(GEOMETRY='{\n  "coordinates": [\n    1.000000000000000e+00,\n    2.000000000000000e+00\n  ],\n  "type": "Point"\n}')]
Copy
>>> df5 = session.create_dataframe([["POINT(1 2)"]], schema=["geom_str"])
>>> df5.select(try_to_geometry(df5["geom_str"], allow_invalid=lit(True)).alias("geometry")).collect()
[Row(GEOMETRY='{\n  "coordinates": [\n    1.000000000000000e+00,\n    2.000000000000000e+00\n  ],\n  "type": "Point"\n}')]
Copy