Filtering using Geospatial Functions | Teradata Vantage - Use Case 3: Filtering using 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

User can run Geospatial functions to filter the data.

In the following example, there are two tables: 'sample_cities' and 'sample_streets'. Both contain a geometry column 'cityShape' and 'streetShape' respectively. The following steps return the street name and city name, if 'cityShape' contains a 'streetShape'.

# Create GeoDataFrame on tables containing Geospatial data.
cities = GeoDataFrame("sample_cities")
streets = GeoDataFrame("sample_streets")
# First we must perform cross join between the two GeoDataFrames.
city_streets = cities.join(streets, how="cross")
# Apply slice filter and invoke Geospatial function contains in the filter and use the same as predicate.
city_streets[city_streets.cityShape.contains(city_streets.streetShape) == 1].select("streetName", "cityName")
# Slice filtering with Geometry Type object passed for comparison.
# Create a LineString object.
line_object = LineString([(2,2), (3,2), (4,1)])
streets[streets.streetShape == line_object]
  • User can use 'city_streets.geometry' property to invoke GeoDataFrameColumn method instead of 'city_streets.cityShape', if geometry points to 'cityShape'.
  • User can pass column name as string, that is, 'streetShape' instead of GeoDataFrameColumn object of the column.