gntools.common.geometry module

GEONIS-specific module to handle or parse Esri geometries.

exception gntools.common.geometry.GeometrySerializationError

Bases: exceptions.ValueError

gntools.common.geometry.get_angle(center_point, from_arcpoint, to_arcpoint)

Calculates and returns the angle of a center-point arc in degrees.

Parameters:
  • center_point (tuple, list) – Arc center point ((x, y)).
  • from_arcpoint (tuple, list) – The start point of the arc ((x, y, ...)).
  • to_arcpoint (tuple, list) – The last point of the arc ((x, y, ...)).
Returns:

An angle in degrees.

Return type:

float

gntools.common.geometry.get_arc_center(start_point, mid_point, end_point)

Calculates and returns the center point as a tuple of (x, y) for the defined 3-point arc points.

Parameters:
  • start_point (tuple, list) – First point ((x, y, ...)).
  • mid_point (tuple, list) – Middle or other point on the arc ((x, y, ...)).
  • end_point (tuple, list) – Last point ((x, y, ...)).
Returns:

A tuple of X, Y float values.

Return type:

tuple

gntools.common.geometry.is_clockwise(ring)

Returns True when the given list or tuple of polygon ring coordinates turns clockwise.

This is achieved by calculating an area approximation for the ring using the Shoelace formula. When the area is positive, the ring turns clockwise. When negative, the ring turns counterclockwise.

Parameters:ring (tuple, list) – An EsriJSON ring.
Return type:bool
gntools.common.geometry.is_minor(start_point, mid_point, end_point)

Returns True when the defined 3-point arc is minor (less than 180 degrees).

Parameters:
  • start_point (tuple, list) – First point ((x, y, ...)).
  • mid_point (tuple, list) – Middle or other point on the arc ((x, y, ...)).
  • end_point (tuple, list) – Last point ((x, y, ...)).
Return type:

bool

gntools.common.geometry.serialize(geometry)

Serializes Esri Geometry, an Esri Point, EsriJSON or a coordinate iterable into GEONIS Protocol XML geometry. Regardless of the dimensions of the input geometry, the output geometry will always be 2D.

Parameters:geometry (Geometry, str, unicode, tuple, list) – An Esri Geometry or Point instance, an Esri JSON string or a coordinate iterable.
Returns:An XML ‘Geometry’ element.
Return type:Element