Buffer Module#
- class Circle(position: Tuple[float, float], radius: float, resolution: int | None = 128, index: float | None = None)[source]#
Bases:
Polygon
Represents a circular geometry centered at a specified position with a given radius.
- Parameters:
position (Tuple[float, float]) – The center position of the circle.
radius (float) – The radius of the circle.
resolution (Optional[int], optional) – The resolution of the circle’s edge. Higher values yield smoother circles. Default is 128.
index (Optional[float], optional) – The refractive index of the circle. Default is None.
The Circle class represents circular geometric structures, typically used for modeling fiber cross-sections. It provides methods for defining, scaling, and manipulating circular geometries.
- position: Tuple[float, float]#
- radius: float#
- resolution: int | None = 128#
- index: float | None = None#
- property area: float#
Calculate the area of the shape.
- Returns:
The area of the shape.
- Return type:
float
- property bounds: Tuple[float, float, float, float]#
Get the bounds of the shape.
- Returns:
The (minx, miny, maxx, maxy) bounds of the shape.
- Return type:
tuple of float
- property center: Point#
Get the center (centroid) of the shape.
- Returns:
The centroid of the shape as a Point.
- Return type:
- contains_points(coordinates: ndarray) ndarray #
Checks which of the provided coordinates lie within the polygon or multipolygon, excluding any holes.
- Parameters:
coordinates (np.ndarray) – An array of coordinates to check against the polygon or multipolygon.
- Returns:
A boolean array where True indicates that the coordinate is inside the polygon or multipolygon (excluding any holes) and False indicates that it is outside or within a hole.
- Return type:
np.ndarray
- property convex_hull: Polygon#
Get the convex hull of the shape.
- Returns:
The convex hull as a Polygon.
- Return type:
- copy() Alteration #
Create a deep copy of the object.
- Returns:
A new instance that is a deep copy of the current object.
- Return type:
Alteration
- property exterior#
Get the exterior boundary of the polygon.
- Returns:
The exterior boundary of the polygon.
- Return type:
LinearRing
- get_hole() Polygon #
Retrieves the holes within the polygon as a new Polygon object.
- Returns:
A polygon representing the holes, or an empty polygon if no holes exist.
- Return type:
geo.Polygon
- get_rasterized_mesh(coordinate_system: CoordinateSystem) ndarray #
Rasterize the shape based on the given coordinate system.
- Parameters:
coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.
- Returns:
The rasterized shape as a mesh.
- Return type:
numpy.ndarray
- in_place_copy() Callable #
Decorator to manage in-place operations.
- Parameters:
function (Callable) – The function to wrap.
- Returns:
Wrapped function that optionally modifies the object in-place.
- Return type:
Callable
- property interiors#
Retrieves the interior coordinates of the polygon.
- Returns:
An iterable of coordinates that define the interior boundaries of the polygon.
- Return type:
Iterable
- intersection(*args, in_place=False, **kwargs)#
- property is_empty: bool#
Check if the shapely object is empty.
- Returns:
True if the object is empty, False otherwise.
- Return type:
bool
- property is_iterable: bool#
Check if the shapely object is iterable.
- Returns:
True if the object is iterable, False otherwise.
- Return type:
bool
- property is_multi: bool#
Check if the shapely object is a MultiPolygon.
- Returns:
True if the object is a MultiPolygon, False otherwise.
- Return type:
bool
- property is_pure_polygon: bool#
Check if the shapely object is a pure Polygon.
- Returns:
True if the object is a pure Polygon, False otherwise.
- Return type:
bool
- keep_largest_polygon() Polygon #
Retains only the largest polygon in the geometry.
If the geometry is a MultiPolygon, it keeps the one with the largest area.
- Returns:
The instance of this class with the largest polygon retained.
- Return type:
- plot(ax: Axes = None, show: bool = True, **kwargs)#
- rasterize(coordinate_system: CoordinateSystem) ndarray #
Rasterizes the polygon to a grid based on a coordinate system.
- Parameters:
coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.
- Returns:
A 2D array where 1 indicates the presence of the polygon and 0 indicates its absence.
- Return type:
np.ndarray
- remove_non_polygon_elements() Polygon #
Removes non-polygon elements from the geometry.
Filters out elements that are not Polygon or MultiPolygon from the current geometry.
- Returns:
The instance of this class with only polygon elements retained.
- Return type:
- rotate(*args, in_place=False, **kwargs)#
- scale(*args, in_place=False, **kwargs)#
- scale_position(factor: float) BaseArea #
Scale the position of the shape.
- Parameters:
factor (float) – The scaling factor for the shape’s position.
- Returns:
The scaled shape.
- Return type:
BaseArea
- shift_position(shift: Tuple[float, float], inplace: bool = True) BaseArea #
Shift the position of the shape.
- Parameters:
shift (tuple of float) – The (x, y) shift values.
- Returns:
The shifted shape.
- Return type:
BaseArea
- split_with_line(line, return_largest: bool = True) Polygon #
Split the shape using a line.
- Parameters:
line (LineString) – The line used for splitting the shape.
return_largest (bool, optional) – If True, returns the largest resulting polygon. Otherwise, returns the smallest. Default is True.
- Returns:
The resulting polygon based on the split.
- Return type:
ff.Polygon
- Raises:
ValueError – If the shape is not a pure polygon.
- translate(*args, in_place=False, **kwargs)#
- union(*args, in_place=False, **kwargs)#
- class Square(position: tuple, length: float, index: float | None = None)[source]#
Bases:
Polygon
Represents a square geometry centered at a specified position with a given side length.
- Parameters:
position (tuple) – The center position of the square.
length (float) – The length of the square’s sides.
index (Optional[float], optional) – The refractive index of the square. Default is None.
The Square class defines square-shaped geometric structures. This class is used for specific scenarios where rectangular shapes are necessary, and it includes methods for configuring and transforming these geometries.
- position: tuple#
- length: float#
- index: float | None = None#
- property area: float#
Calculate the area of the shape.
- Returns:
The area of the shape.
- Return type:
float
- property bounds: Tuple[float, float, float, float]#
Get the bounds of the shape.
- Returns:
The (minx, miny, maxx, maxy) bounds of the shape.
- Return type:
tuple of float
- property center: Point#
Get the center (centroid) of the shape.
- Returns:
The centroid of the shape as a Point.
- Return type:
- contains_points(coordinates: ndarray) ndarray #
Checks which of the provided coordinates lie within the polygon or multipolygon, excluding any holes.
- Parameters:
coordinates (np.ndarray) – An array of coordinates to check against the polygon or multipolygon.
- Returns:
A boolean array where True indicates that the coordinate is inside the polygon or multipolygon (excluding any holes) and False indicates that it is outside or within a hole.
- Return type:
np.ndarray
- property convex_hull: Polygon#
Get the convex hull of the shape.
- Returns:
The convex hull as a Polygon.
- Return type:
- copy() Alteration #
Create a deep copy of the object.
- Returns:
A new instance that is a deep copy of the current object.
- Return type:
Alteration
- property exterior#
Get the exterior boundary of the polygon.
- Returns:
The exterior boundary of the polygon.
- Return type:
LinearRing
- get_hole() Polygon #
Retrieves the holes within the polygon as a new Polygon object.
- Returns:
A polygon representing the holes, or an empty polygon if no holes exist.
- Return type:
geo.Polygon
- get_rasterized_mesh(coordinate_system: CoordinateSystem) ndarray #
Rasterize the shape based on the given coordinate system.
- Parameters:
coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.
- Returns:
The rasterized shape as a mesh.
- Return type:
numpy.ndarray
- in_place_copy() Callable #
Decorator to manage in-place operations.
- Parameters:
function (Callable) – The function to wrap.
- Returns:
Wrapped function that optionally modifies the object in-place.
- Return type:
Callable
- property interiors#
Retrieves the interior coordinates of the polygon.
- Returns:
An iterable of coordinates that define the interior boundaries of the polygon.
- Return type:
Iterable
- intersection(*args, in_place=False, **kwargs)#
- property is_empty: bool#
Check if the shapely object is empty.
- Returns:
True if the object is empty, False otherwise.
- Return type:
bool
- property is_iterable: bool#
Check if the shapely object is iterable.
- Returns:
True if the object is iterable, False otherwise.
- Return type:
bool
- property is_multi: bool#
Check if the shapely object is a MultiPolygon.
- Returns:
True if the object is a MultiPolygon, False otherwise.
- Return type:
bool
- property is_pure_polygon: bool#
Check if the shapely object is a pure Polygon.
- Returns:
True if the object is a pure Polygon, False otherwise.
- Return type:
bool
- keep_largest_polygon() Polygon #
Retains only the largest polygon in the geometry.
If the geometry is a MultiPolygon, it keeps the one with the largest area.
- Returns:
The instance of this class with the largest polygon retained.
- Return type:
- plot(ax: Axes = None, show: bool = True, **kwargs)#
- rasterize(coordinate_system: CoordinateSystem) ndarray #
Rasterizes the polygon to a grid based on a coordinate system.
- Parameters:
coordinate_system (CoordinateSystem) – The coordinate system used for rasterization.
- Returns:
A 2D array where 1 indicates the presence of the polygon and 0 indicates its absence.
- Return type:
np.ndarray
- remove_non_polygon_elements() Polygon #
Removes non-polygon elements from the geometry.
Filters out elements that are not Polygon or MultiPolygon from the current geometry.
- Returns:
The instance of this class with only polygon elements retained.
- Return type:
- rotate(*args, in_place=False, **kwargs)#
- scale(*args, in_place=False, **kwargs)#
- scale_position(factor: float) BaseArea #
Scale the position of the shape.
- Parameters:
factor (float) – The scaling factor for the shape’s position.
- Returns:
The scaled shape.
- Return type:
BaseArea
- shift_position(shift: Tuple[float, float], inplace: bool = True) BaseArea #
Shift the position of the shape.
- Parameters:
shift (tuple of float) – The (x, y) shift values.
- Returns:
The shifted shape.
- Return type:
BaseArea
- split_with_line(line, return_largest: bool = True) Polygon #
Split the shape using a line.
- Parameters:
line (LineString) – The line used for splitting the shape.
return_largest (bool, optional) – If True, returns the largest resulting polygon. Otherwise, returns the smallest. Default is True.
- Returns:
The resulting polygon based on the split.
- Return type:
ff.Polygon
- Raises:
ValueError – If the shape is not a pure polygon.
- translate(*args, in_place=False, **kwargs)#
- union(*args, in_place=False, **kwargs)#