9. tools

Module for defining the repetitive functions to manipulate the shapely objects that are used in the classes for performing the slope stabity analysis.

tools.getIntersect(x, y1, y2)[source]

Intersects two lines that have the same abscise points

Parameters:
  • x (list or tuple) – abscises of both lines
  • y1 (list or tuple) – ordinates of first line
  • y2 (list or tuple) – ordinates of second line
Returns:

Coordinates of the interesection point

Return type:

(tuple)

Examples

>>> from pybimstab.tools import getIntersect
>>> getIntersect(x=[0, 1], y1=[0, 0], y2=[1, -1])
(0.5, 0.0)
tools.cutLine(line, distance)[source]

Cuts a line in two parts at a distance measured from its starting point.

Parameters:
  • line (LineString) – Any line or polyline from the shapely module.
  • distance (int or float) – The absolute distance measured from the starting point of the line.
Returns:

Two lines that merged at the common point conform the original input line.

Return type:

(tuple)

Examples

>>> from shapely.geometry import LineString
>>> from pybimstab.tools import cutLine
>>> line = LineString([(0, 0), (5, 0)])
>>> line1, line2 = cutLine(line, 2.5)
>>> list(line1.coords)
[(0.0, 0.0), (2.5, 0.0)]
>>> list(line2.coords)
[(2.5, 0.0), (5.0, 0.0)]
tools.upperLowerSegm(line1, line2)[source]

Splits two polylines ath their intersection points and join the upper segments in a new polyline and the lower segments in other

Parameters:
  • line1 (LineString) – Any line or polyline from the shapely module.
  • line2 (LineString) – Any line or polyline from the shapely module.
Returns:

Two lines where each one is given in a (n, 2) array with the coordinates. The first one is the outcome of joinning the upper segments and the second is the outcome of joinning the lower segments.

Return type:

(tuple)

Examples

>>> from shapely.geometry import LineString
>>> from pybimstab.tools import upperLowerSegm
>>> line1 = LineString([(0, 0), (5, 0)])
>>> line2 = LineString([(0, 5), (5, -5)])
>>> upperLine, lowerLine = upperLowerSegm(line1, line2)
>>> upperLine, lowerLine
(array([[ 0. ,  0. ],
        [ 2.5,  0. ],
        [ 2.5,  0. ],
        [ 5. , -5. ]]),
 array([[0. , 5. ],
        [2.5, 0. ],
        [2.5, 0. ],
        [5. , 0. ]]))
tools.getPointAtX(line, x)[source]

Interesects a vertical line at the abscice x with the input line and retuns the intersection point.

The input line must not have more than one intersection with the vertical line.

If the abscise is out of the horizontal range of the line, then the nearest end is returned.

Parameters:
  • line (LineString) – Any line or polyline from the shapely module.
  • x (int or float) – The abscise where the vertical line is wanted.
Returns:

Two lines where each one is given in a (n, 2) array with the coordinates. The first one is the outcome of joinning the upper segments and the second is the outcome of joinning the lower segments.

Return type:

(tuple)

Examples

>>> from shapely.geometry import LineString
>>> from pybimstab.tools import upperLowerSegm, getPointAtX
>>> line = LineString([(0, 0), (5, 0)])
>>> x = 2.5
>>> point = getPointAtX(line, x)
>>> point.x, point.y
(2.5, 0.0)
tools.extractSegment(line, distance1, distance2)[source]

Extracts a segment from a polyline (shapely LineString) given two distances measured from its starting point.

The following rule must be satisfied: distance1 > distance2

Parameters:
  • line (LineString) – Any line or polyline from the shapely module.
  • distance1 (int or float) – The first distance measured from the starting pint of the line.
  • distance2 (int or float) – The second distance measured from the starting pint of the line.
Returns:

Two lines where each one is given in a (n, 2) array with the coordinates. The first one is the outcome of joinning the upper segments and the second is the outcome of joinning the lower segments.

Return type:

(tuple)

Examples

>>> from shapely.geometry import LineString
>>> from pybimstab.tools import upperLowerSegm, extractSegment
>>> line = LineString([(0, 0), (5, 0)])
>>> distance1, distance2 = 1, 3
>>> segment = extractSegment(line, distance1, distance2)
>>> list(segment.coords)
[(1.0, 0.0), (3.0, 0.0)]