Teradata Package for Python Function Reference | 20.00 - distance - 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 - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-10
dita:id
TeradataPython_FxRef_Enterprise_2000
Product Category
Teradata Vantage
teradataml.geospatial.geodataframecolumn.GeoDataFrameColumn.distance = distance(self, geom_column)
DESCRIPTION:
    Returns the distance between two Geometry values.
    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:
    All Geometry types.
 
RAISES:
    TypeError, ValueError, TeradataMlException
 
RETURNS:
    GeoDataFrameColumn
 
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)
 
    # Let's select only few columns from GeoDataFrame.
    points_lines = geodf.select(["skey", "points", "linestrings"])
 
    # Example 1: Calculate the distance between (ST_Linestring/ST_MultiLinestring) geometries in column
    #            'linestrings' and (ST_Point/ST_MultiPoint) geometries in column 'points'.
    distance1_expr = points_lines.points.distance(geom_column=points_lines.linestrings)
    points_lines.assign(res = distance1_expr)
 
    # Example 2: Calculate the distance between (ST_Linestring/ST_MultiLinestring) geometries in column
    #            'linestrings' and the geometry specified by a GeometryType object - Point.
    # Create an object of Point GeometryType.
    p1 = Point(3, 1)
    # Pass the Point() GeometryType object as input to "geom_column" argument.
    distance2_expr = points_lines.points.distance(geom_column=p1)
    points_lines.assign(res = distance2_expr)
 
    # Example 3: Get all the rows where distance between (ST_Linestring/ST_MultiLinestring) geometries in column
    #            'linestrings' and (ST_Point/ST_MultiPoint) geometries in column 'points' is > 10 and less than 100.
    distance1_expr = points_lines.points.distance(geom_column=points_lines.linestrings)
    points_lines[(distance1_expr > 10) & (distance1_expr < 100)]