Run Multiple Geospatial Functions | Teradata Vantage - Use Case 2: Run Multiple Geospatial Functions - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.10
Published
May 2022
Language
English (United States)
Last Update
2022-08-18
dita:mapPath
rsu1641592952675.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage
There are scenarios when user needs to run multiple functions on single column or multiple columns. For example, there are two columns containing Geospatial data, 'geom_col1' and 'geom_col2', and you want to:
  • Check if geometry values in 'geom_col1' column intersects with geometry values from column 'geom_col2' or not. (Use: intersects)
  • Check if geometry values in 'geom_col1' column are spatially equal to geometry values from column 'geom_col2' or not. (Use: geom_Equals)
  • Calculate point set symmetric difference between geometry values in columns 'geom_col1' and 'geom_col2'. (Use: sym_difference)
  • Calculate point set difference between geometry values in columns 'geom_col1' and 'geom_col2'. (Use: difference)

With GeoDataFrame, several steps are required to get the desired result. With GeoDataFrame execution, each function is ran individually and then the results of all are joined to get the final result.

With teradataml GeoDataFrameColumn, this can be achieved using a single step to run multiple Geospatial functions, see Approach 2.

Approach 1: Run function individually on GeoDataFrameColumn and pass the results to 'assign()'

# Create GeoDataFrame on a table containing Geospatial data.
geoDF = GeoDataFrame("sample_shapes")
geo_intersect = geoDF.geom_col1.intersects(geoDF.geom_col2)
geo_equals = geoDF.geom_col1.equals("geom_col2")
geo_setdiff = geoDF.geom_col1.difference(geoDF.geom_col2)
geo_symdiff = geoDF.geom_col1.symmetric_difference(geoDF.geom_col2)
geoDF.assign(intersect_result = geo_intersect,
             equals_result = geo_equals,
             set_diff_result = geo_setdiff,
             symmetric_set_result = geo_symdiff)

Approach 2: Run multiple functions in one step

# Create GeoDataFrame on a table containing Geospatial data.
geoDF = GeoDataFrame("sample_shapes")
# ColumnExpression a.k.a GeoDataFrameColumn object.
geocol1 = geoDF.geom_col1
# This can be achieved using GeoDataFrame.assign() and GeoDataFrameColumn methods.
geoDF.assign(intersect_result = geocol1.intersects(geoDF.geom_col2),
             equals_result = geocol1.equals(geoDF.geom_col2),
             set_diff_result = geocol1.difference(geoDF.geom_col2),
             symmetric_set_result = geocol1.symmetric_difference(geoDF.geom_col2),
            )
  • User can use 'geoDF.geometry' property to invoke GeoDataFrameColumn method instead of 'geoDF.geom_col1', if geometry points to 'geom_col1'.
  • User can pass column name as string, that is, 'geom_col2', instead of GeoDataFrameColumn object of the column.
  • In Approach 2, a variable 'geocol1' is created. Creation of the variable is optional. User can directly use 'geoDF.geom_col1' instead of 'geo_col1' in assign() function call.