shapelib.tools.lines.dedup package#
Submodules#
shapelib.tools.lines.dedup.core module#
Drop near-coincident (stacked) lines, keeping the longest of each group.
Drone-mapped rows sometimes carry a near-duplicate: two input lines trace the
same physical row a few millimetres apart. That twin poisons downstream tools —
in shapelib.tools.lines.merge it becomes the “rail” of its own sibling and
the merge follows a phantom row. This tool collapses each cluster of stacked
lines into a single representative (the longest one).
A line is dropped when it lies entirely inside the tolerance tube of a longer,
kept line — tested exactly with a buffered covers predicate evaluated inside
the spatial index, so no point sampling is involved.
The public entry point is deduplicate_lines().
- shapelib.tools.lines.dedup.core.deduplicate_lines(lines, tolerance=0.05)[source]#
Drop near-coincident (stacked) lines, keeping the longest of each cluster.
Two input lines that trace the same physical row a few millimetres apart are “stacked” duplicates: the shorter one lies entirely within the
tolerancetube of the longer. This tool collapses every such cluster to its longest line and passes all other lines through unchanged, so the output is the same line set with the phantom twins removed. Filtering by talhão is the caller’s responsibility — pass only the lines of a single talhão.- Parameters:
lines (
GeoDataFrame) – Line geometries. Must be in a projected CRS (metres), sincetoleranceis expressed in CRS units. MultiLineStrings are flattened to single LineStrings before the coverage test.tolerance (
float) – Maximum perpendicular distance (CRS units) between two lines for one to count as a stacked duplicate of the other. A line is dropped only when it lies entirely within this distance of a longer, kept line.
- Returns:
A subset of
lines(original attribute columns and CRS preserved) with the stacked duplicates removed. When two covering lines have exactly equal length, the first in the length ordering is kept.- Return type:
Examples
>>> import shapelib >>> lines = shapelib.read_file("lines.shp") >>> lines.to_utm() >>> cleaned = deduplicate_lines(lines, tolerance=0.05) >>> len(cleaned) <= len(lines) True