Beispiel #1
0
def linesimplify(lines: vp.LineCollection, tolerance):
    """
    Reduce the number of segments in the geometries.

    The resulting geometries' points will be at a maximum distance from the original controlled
    by the `--tolerance` parameter (0.05mm by default).
    """
    if len(lines) < 2:
        return lines

    # Note: preserve_topology must be False, otherwise non-simple (ie intersecting) MLS will
    # not be simplified (see https://github.com/Toblerity/Shapely/issues/911)
    mls = lines.as_mls().simplify(tolerance=tolerance, preserve_topology=False)
    new_lines = vp.LineCollection(mls)

    logging.info(
        f"simplify: reduced segment count from {lines.segment_count()} to "
        f"{new_lines.segment_count()}")

    return new_lines
Beispiel #2
0
def circlecrop(lines: vp.LineCollection, x: float, y: float, r: float, quantization: float):
    """Crop to a circular area."""

    circle = Polygon(vp.as_vector(vp.circle(x, y, r, quantization)))
    mls = lines.as_mls()
    return vp.LineCollection(mls.intersection(circle))