Geometry operations

class Geometry

class gefest.core.geometry.geometry.Geometry[source]

Bases: BaseModel, ABC

Abstract 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 rotate_poly(poly: Polygon, angle: float)[source]

Rotate polygon operation.

abstract get_length(polygon: Polygon)[source]

Perimeter calculation operation.

abstract get_square(polygon: Polygon)[source]

Square calculation operation.

abstract is_contain_point(poly: Polygon, point: Point)[source]

Checks if point in polygon.

abstract get_convex(poly: Polygon)[source]

Returns convex hull.

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: Geometry

Overriding the geometry base class for 2D structures.

The input receives information about the closeness of the polygon.

Parameters:

is_closedTrue if the Polygon must have close borders (first Point is equal to the last one), otherwise False. Default value is True

field is_closed: bool = True
field is_convex: bool = True
get_length(polygon: Polygon)[source]

Returns polygon perimeter.

shapely_to_gefest(geom_in)[source]

Converts any shapely object to GEFEST polygon.

get_coords(poly: Polygon | LineString) list[Point][source]

The function for getting points.

Parameters:

polyPolygon for processing

Returns:

all Point that :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:
  • polyPolygon for processing

  • x_scale – scale value for x axis

  • y_scale – scale value for y axis

Returns:

scaled poly by (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:
  • polyPolygon for processing.

  • angle – value of degree rotation.

Returns:

rotated poly.

get_square(polygon: Polygon) float[source]

Recieving value of the area.

Parameters:

polygonPolygon for processing.

Returns:

value of the polygon area.

is_contain_point(poly: Polygon, point: Point) bool[source]

Checking if a point is inside a polygon.

Parameters:
  • polyPolygon that explore

  • pointPoint for checking presence inside the Polygon.

Returns:

True if point is into poly, otherwise False.

nearest_point(point: Point, poly: Polygon) Point[source]

Calculating closest point between input point and polygon.

Parameters:
  • point – the Point that explore

  • poly – the Polygon that explore

Returns:

nearest_correct_position Point from point among all points in the poly

nearest_points(poly_1: Polygon, poly_2: Polygon) list[Point][source]

Calculating closest point between two polygons.

Parameters:
  • poly_1 – the first Polygon that explore

  • poly_2 – the second Polygon that explore

Returns:

the couple of Point where the first one from poly_1 and the second one from poly_2

get_convex(poly: Polygon) Polygon[source]

Obtaining a convex polygon to avoid intersections.

Parameters:

polyPolygon for 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.

simplify(poly: Polygon, tolerance: float) Polygon[source]

Simplifies polyon.

is_simple(poly: Polygon) bool[source]

Checks if poly is simple.

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 Polygon that explore

Returns:

central Point of poly

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 Structure that explore

Returns:

True if any Polygon in structure intersects with another one,

otherwise - False

contains(poly1: Polygon, poly2: Polygon) bool[source]

Checks if poly2 contains poly1.

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 Polygon that explore

  • poly_2 – the second Polygon that explore

Returns:

True if the poly_1 intersects with poly_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_1 that explore

  • obj_2 – the second obj_2 that explore

Returns:

value of distance between the nearest points of the explored objects

centroid_distance(point: Point, poly: Polygon) Point[source]

Finds distance from point to polygon.

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.