-
-
Notifications
You must be signed in to change notification settings - Fork 67
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Used to live in https://github.com/abey79/vpype-explorations, should be integrated to vpype using this corrected version:
import click
import vpype as vp
import vpype_cli
from shapely.geometry import Polygon, LineString, MultiLineString, GeometryCollection, MultiPoint
@click.command()
@click.argument("X", type=vpype_cli.LengthType())
@click.argument("Y", type=vpype_cli.LengthType())
@click.argument("R", type=vpype_cli.LengthType())
@click.option(
"-q",
"--quantization",
type=vpype_cli.LengthType(),
default="0.1mm",
help="Quantization used for the circular area",
)
@vpype_cli.layer_processor
def circlecrop(lines: vp.LineCollection, x: float, y: float, r: float, quantization: float):
"""Crop to a circular area."""
# Create a circular polygon
circle = Polygon(vp.as_vector(vp.circle(x, y, r, quantization)))
# Convert LineCollection to MultiLineString
mls = lines.as_mls()
# Perform the intersection
intersection = mls.intersection(circle)
# Handle GeometryCollection and MultiPoint specifically
if isinstance(intersection, (GeometryCollection, MultiPoint)):
# Extract only LineString geometries
line_strings = [geom for geom in intersection.geoms if isinstance(geom, LineString)]
return vp.LineCollection(line_strings)
# For all other types, pass directly to LineCollection
return vp.LineCollection(intersection)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request