Geometry operations
class Geometry
- class gefest.core.geometry.geometry.Geometry[source]
Bases:
BaseModel,ABCAbstract geometry class.
Сlass contains basic transformations of geometries, geometry properties. Each of the methods is overridden for a particular dimension of the geometry.
- abstract resize_poly(poly: Polygon, x_scale: float, y_scale: float)[source]
Resize polygon operation.
- abstract intersects(poly_1: Polygon, poly_2: Polygon) bool[source]
Checks if two polygons intersects.
- abstract min_distance(pt_1: Point, pt_2: Point) float[source]
Returns min distance between two polygons.
- abstract nearest_point(point: Point, poly: Polygon) Point[source]
Finds closest point between input point and polygon.
- abstract nearest_points(poly_1: Polygon, poly_2: Polygon) List[Point][source]
Returns nearest points in the input geometries.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
class Geometry2D
There is an object included set of methods for processing 2D geometrical figures. The most of implemented methods based on the shapely library.
- class gefest.core.geometry.geometry_2d.Geometry2D(*, is_closed: bool = True, is_convex: bool = True)[source]
Bases:
GeometryOverriding the geometry base class for 2D structures.
The input receives information about the closeness of the polygon.
- Parameters:
is_closed –
Trueif thePolygonmust have close borders (first Point is equal to the last one), otherwiseFalse. Default value isTrue
- field is_closed: bool = True
- field is_convex: bool = True
- get_coords(poly: Polygon | LineString) list[Point][source]
The function for getting points.
- Parameters:
poly –
Polygonfor processing- Returns:
all
Pointthat :obj:`poly`contains
- get_prohibited_geom(prohibited_area: Structure, buffer_size: float = 0.001) GeometryCollection[source]
Generates Shapely GeometryCollection from pohibited structure.
- resize_poly(poly: Polygon, x_scale: float, y_scale: float) Polygon[source]
The function for rescaling polygons along each axis.
Scaling occurs relative to the center of mass of the polygon.
- Parameters:
poly –
Polygonfor processingx_scale – scale value for x axis
y_scale – scale value for y axis
- Returns:
scaled
polyby(x,y)axes
- get_angle(vector1: tuple[Point, Point], vector2: tuple[Point, Point]) float[source]
Finds angle betwen two bectors.
- rotate_point(point: Point, origin: Point, angle: float) Polygon[source]
Rotates polygon by given angle.
- rotate_poly(poly: Polygon, angle: float) Polygon[source]
Rotating polygon relative to the center of mass by a given angle.
- Parameters:
poly –
Polygonfor processing.angle – value of degree rotation.
- Returns:
rotated
poly.
- get_square(polygon: Polygon) float[source]
Recieving value of the area.
- Parameters:
polygon –
Polygonfor processing.- Returns:
value of the
polygonarea.
- is_contain_point(poly: Polygon, point: Point) bool[source]
Checking if a point is inside a polygon.
- Parameters:
poly –
Polygonthat explorepoint –
Pointfor checking presence inside thePolygon.
- Returns:
Trueifpointis intopoly, otherwiseFalse.
- nearest_point(point: Point, poly: Polygon) Point[source]
Calculating closest point between input point and polygon.
- Parameters:
point – the
Pointthat explorepoly – the
Polygonthat explore
- Returns:
nearest_correct_position
Pointfrompointamong all points in thepoly
- nearest_points(poly_1: Polygon, poly_2: Polygon) list[Point][source]
Calculating closest point between two polygons.
- Parameters:
poly_1 – the first
Polygonthat explorepoly_2 – the second
Polygonthat explore
- Returns:
the couple of
Pointwhere the first one frompoly_1and the second one frompoly_2
- get_convex(poly: Polygon) Polygon[source]
Obtaining a convex polygon to avoid intersections.
- Parameters:
poly –
Polygonfor processing- Returns:
convex
Polygon
- intersection_line_line(points1, points2, scale1, scale2)[source]
Returns point of two lines intersection.
- intersection_poly_line(figure: Polygon, points: list[Point], scale_factor)[source]
Returns points where line intersects polygon.
- get_random_point_in_shapey_geom(fig)[source]
Returns random point from polygon of arbitrary shape shapely geometry.
- get_random_point_in_poly(poly) Point | None[source]
Returns random point from polygon of arbitrary shape.
- get_centroid(poly: Polygon) Point[source]
Getting a point that is the center of mass of the polygon.
- Parameters:
poly – the
Polygonthat explore- Returns:
central
Pointofpoly
- intersects(structure: Structure) bool[source]
Function to check for any intersection in structure of polygons.
Whole structure appears like shapely MultiLineString for which uses method is simple.
- Parameters:
structure – the
Structurethat explore- Returns:
Trueif anyPolygoninstructureintersects with another one,otherwise -
False
- difference_polys(base_poly: Polygon, diff_polys: list[Polygon])[source]
Returns area of base_poly difference with diff_polys polygons.
- intersection_polys(base_poly: Polygon, diff_polys: list[Polygon])[source]
Returns area of base_poly intersection with diff_polys polygons.
- intersects_poly(poly_1: Polygon, poly_2: Polygon) bool[source]
Intersection between two polygons.
- Parameters:
poly_1 – the first
Polygonthat explorepoly_2 – the second
Polygonthat explore
- Returns:
Trueif thepoly_1intersects withpoly_2, otherwise -False
- _poly_to_shapely_line(poly: Polygon) LineString[source]
Transform GEFEST Polygon to shapely non cycled LineString.
- Parameters:
poly – Polygon
- Returns:
LineString
- _poly_to_shapely_poly(poly: Polygon) Polygon[source]
Transform GEFEST Polygon to shapely Polygon.
- Parameters:
poly – Polygon
- Returns:
ShapelyPolygon
- _pt_to_shapely_pt(pt: Point) Point[source]
Transform GEFEST Polygon to shapely Polygon.
- Parameters:
poly – Point
- Returns:
ShapelyPoint
- split_polygon(poly, line: tuple[Point, Point], scale_factor=1000) list[source]
Splits polygon by line.
- Returns:
Produced parts.
- Return type:
list
- min_distance(obj_1, obj_2) float[source]
Finds smallest distance between two objects.
- Parameters:
obj_1 – the first
obj_1that exploreobj_2 – the second
obj_2that explore
- Returns:
value of distance between the nearest points of the explored objects
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'is_closed': FieldInfo(annotation=bool, required=False, default=True), 'is_convex': FieldInfo(annotation=bool, required=False, default=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.