Polygon | Geospatial Types | Teradata Package for Python - Polygon - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-02-17
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

This function enables end user to create an object for the single Polygon using the coordinates. It allows user to use the same in GeoDataFrame manipulation and processing using any Geospatial function.

Optional argument:

coordinates: Specifies the coordinates of a polygon.
  • If coordinates are not passed, an object for empty polygon is created.
  • When coordinates are passed, you must pass a list of the following types:
    • Two-tuple of int or float;
    • Three-tuple of int or float;
    • Point geometry objects;
    • Polygon geometry objects;
    • Mix of any of these four types.

Example 1: Create a Polygon in 2D, using x and y coordinates

>>> from teradataml import Point, LineString, Polygon
>>> go1 = Polygon([(0, 0), (0, 20), (20, 20), (20, 0), (0, 0)])
>>> # Print the coordinates.
>>> print(go1.coords)
[(0, 0), (0, 20), (20, 20), (20, 0), (0, 0)]
>>> # Print the geometry type.
>>> go1.geom_type
'Polygon'

Example 2: Create a Polygon in 3D, using x, y and z coordinates

>>> from teradataml import Point, LineString, Polygon
>>> go2 = Polygon([(0, 0, 0), (0, 0, 20), (0, 20, 0), (0, 20, 20), (20, 0, 0), (20, 0, 20), (20, 20, 0), (20, 20, 20), (0, 0, 0)])
>>> # Print the coordinates.
>>> print(go2.coords)
[(0, 0, 0), (0, 0, 20), (0, 20, 0), (0, 20, 20), (20, 0, 0), (20, 0, 20), (20, 20, 0), (20, 20, 20), (0, 0, 0)]

Example 3: Create a Polygon using Point geometry objects

>>> from teradataml import Point, LineString, Polygon
# Create Point objects in 2D, using x and y coordinates.
>>> p1 = Point(0, 20)
>>> p2 = Point(0, 0)
>>> p3 = Point(20, 20)
>>> p4 = Point(20, 0)
>>> go3 = Polygon([p1, p2, p3, p4, p1])
>>> # Print the coordinates.
>>> print(go3.coords)
[(0, 20), (0, 0), (20, 20), (20, 0), (0, 0)]

Example 4: Create a Polygon using LineString geometry objects

>>> from teradataml import Point, LineString, Polygon
# Create LineString objects in 2D, using x and y coordinates.
>>> l1 = LineString([(0, 0), (0, 20), (20, 20)])
>>> l2 = LineString([(20, 0), (0, 0)])
>>> go4 = Polygon([l1, l2])
>>> # Print the coordinates.
>>> print(go4.coords)
[(0, 20), (0, 0), (20, 20), (20, 0), (0, 0)]

Example 5: Create a Polygon using mix of Point, LineString geometry objects and coordinates

>>> from teradataml import Point, LineStromg, Polygon
>>> p1 = Point(0, 0)
>>> l1 = LineString([p1, (0, 20), (20, 20)])
>>> go5 = Polygon([l1, (20, 0), p1])
>>> # Print the coordinates.
>>> print(go5.coords)
[(0, 0), (0, 20), (20, 20), (20, 0)]

Example 5: Create an empty Polygon

>>> from teradataml import Point, LineString, Polygon
>>> goe = Polygon()
>>> # Print the coordinates.
>>> print(poe.coords)
EMPTY