fractopo.fractopo_utils module

Miscellaneous utilities and scripts of fractopo.

class fractopo.fractopo_utils.LineMerge

Bases: object

Merge lines conditionally.

static conditional_linemerge(first, second, tolerance, buffer_value)

Conditionally merge two LineStrings (first and second).

Merge occurs if 1) their endpoints are within buffer_value of each other and 2) their total orientations are within tolerance (degrees) of each other.

Merges by joining their coordinates. The endpoint (that is within buffer_value of endpoint of first) of the second LineString is trimmed from the resulting coordinates.

E.g. with merging:

>>> first = LineString([(0, 0), (0, 2)])
>>> second = LineString([(0, 2.001), (0, 4)])
>>> tolerance = 5
>>> buffer_value = 0.01
:rtype: :sphinx_autodoc_typehints_type:`\:py\:data\:\`\~typing.Optional\`\\ \\\[\:py\:class\:\`\~shapely.geometry.linestring.LineString\`\]`
>>> LineMerge.conditional_linemerge(first, second, tolerance, buffer_value).wkt
'LINESTRING (0 0, 0 2, 0 4)'

Without merging:

>>> first = LineString([(0, 0), (0, 2)])
>>> second = LineString([(0, 2.1), (0, 4)])
>>> tolerance = 5
>>> buffer_value = 0.01
>>> LineMerge.conditional_linemerge(
...     first, second, tolerance, buffer_value
... ) is None
True
static conditional_linemerge_collection(traces, tolerance, buffer_value)

Conditionally linemerge within a collection of LineStrings.

Returns the linemerged traces and the idxs of traces that were linemerged.

E.g.

>>> first = LineString([(0, 0), (0, 2)])
>>> second = LineString([(0, 2.001), (0, 4)])
>>> traces = gpd.GeoSeries([first, second])
>>> tolerance = 5
>>> buffer_value = 0.01
>>> new_traces, idx = LineMerge.conditional_linemerge_collection(
...     traces, tolerance, buffer_value
... )
:rtype: :sphinx_autodoc_typehints_type:`\:py\:data\:\`\~typing.Tuple\`\\ \\\[\:py\:class\:\`\~typing.List\`\\ \\\[\:py\:class\:\`\~shapely.geometry.linestring.LineString\`\]\, \:py\:class\:\`\~typing.List\`\\ \\\[\:py\:class\:\`int\`\]\]`
>>> [trace.wkt for trace in new_traces], idx
(['LINESTRING (0 0, 0 2, 0 4)'], [0, 1])
static integrate_replacements(traces, new_traces, modified_idx)

Add linemerged and remove the parts that were linemerged.

E.g.

>>> first = LineString([(0, 0), (0, 2)])
>>> second = LineString([(0, 2.001), (0, 4)])
>>> traces = gpd.GeoDataFrame(geometry=[first, second])
>>> new_traces = [LineString([(0, 0), (0, 2), (0, 4)])]
>>> modified_idx = [0, 1]
>>> LineMerge.integrate_replacements(traces, new_traces, modified_idx)
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~geopandas.geodataframe.GeoDataFrame\``

geometry

0 LINESTRING (0 0, 0 2, 0 4)

static run_loop(traces, tolerance, buffer_value)

Run multiple conditional linemerge iterations for GeoDataFrame.

This is the main entrypoint.

GeoDataFrame should contain LineStrings.

E.g.

>>> first = LineString([(0, 0), (0, 2)])
>>> second = LineString([(0, 2.001), (0, 4)])
>>> traces = gpd.GeoDataFrame(geometry=[first, second])
>>> tolerance = 5
>>> buffer_value = 0.01
>>> LineMerge.run_loop(traces, tolerance, buffer_value)
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~geopandas.geodataframe.GeoDataFrame\``

geometry

0 LINESTRING (0 0, 0 2, 0 4)

fractopo.fractopo_utils.remove_identical_sindex(geosrs, snap_threshold)

Remove stacked nodes by using a search buffer the size of snap_threshold.

Return type:

GeoSeries