Teradata Package for Python Function Reference | 17.10 - distance_3D - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference
- Product
- Teradata Package for Python
- Release Number
- 17.10
- Published
- April 2022
- Language
- English (United States)
- Last Update
- 2022-08-19
- lifecycle
- previous
- Product Category
- Teradata Vantage
- teradataml.geospatial.geodataframecolumn.GeoDataFrameColumn.distance_3D = distance_3D(self, geom_column)
- DESCRIPTION:
Returns the distance between two Geometry values. Function
considers Z coordinate values, if they exist in the geometries passed to
it.
Notes:
* distance() returns NULL if the geometry value passed to it is the
empty set.
* Both geometries must use the same spatial reference system (have the
same SRS ID).
* If a geospatial index is defined on the geospatial data column to
which this method is applied, the index will only be used if method
appears in the slice filtering such that the distance between the
geometries is less than or equal to a constant.
For example:
* geodf[geodf.geometry.distance(otherGeom) < 10]
* geodf[10 >= geodf.geometry.distance(otherGeom)]
PARAMETERS:
geom_column:
Required Argument.
Specifies the other Geometry value.
Types: str, ColumnExpression, GeometryType
SUPPORTED GEOMETRY TYPES:
ST_Point, ST_MultiPoint, ST_LineString, and ST_MultiLineString
To be valid with distance_3D, these shapes must include Z coordinates.
RAISES:
TypeError, ValueError, TeradataMlException
RETURNS:
GeoDataFrameColumn
Resultant column contains:
* a NULL, if the Geometry is an empty set.
* 0, if the two geometries intersect.
* a float in all other cases. The distance units are those of
the two input geometries.
EXAMPLES:
from teradataml import GeoDataFrame, load_example_data
from teradataml import Point, LineString, Polygon, GeometryCollection
# Load example data.
load_example_data("geodataframe", "sample_shapes")
# Create a GeoDataFrame.
geodf = GeoDataFrame("sample_shapes")
print(geodf)
# Function works with only 3D geometries, hence let's select only few columns from GeoDataFrame
# and filter the rows which contains 3D geometries.
points_lines = geodf.select(["skey", "points", "linestrings"])[geodf.points.is_3D == 1]
# Example 1: Calculate the distance between 3D geometries in column 'linestrings' and 3D
# geometries in column 'points'.
distance1_expr = points_lines.points.distance_3D(geom_column=points_lines.linestrings)
points_lines.assign(res = distance1_expr)
# Example 2: Calculate the distance between 3D geometries in column 'linestrings' and 3D Point
# GeometryType object.
# Create a 3D Point GeometryType object.
p1 = Point(3, 1, 0)
# Pass the Point() GeometryType object as input to "geom_column" argument.
distance1_expr = points_lines.points.distance_3D(geom_column=p1)
points_lines.assign(res = distance1_expr)
# Example 3: Get all the rows where the distance between 3D geometries in column 'linestrings' and 3D
# geometries in column 'points' is greater than 30 but less than 50.
distance1_expr = points_lines.points.distance_3D(geom_column=points_lines.linestrings)
points_lines[(distance1_expr > 30) & (distance1_expr < 50)]