gtkit package
Submodules
gtkit.gops module
- gtkit.gops.centroid_with_z(geom: Polygon) Point[source]
Calculate the centroid of a 3D polygon.
- Parameters:
geom (Polygon) – The input 3D polygon geometry.
- Returns:
The 3D centroid point.
- Return type:
Point
- gtkit.gops.convert_3d_2d(geometry)[source]
Convert a 3D geometry to a 2D geometry.
- Parameters:
geometry – The input geometry.
- Returns:
The converted 2D geometry.
- Return type:
Geometry
- gtkit.gops.cut(line: LineString, dist: float) Tuple[LineString, LineString][source]
Split a LineString at a specified distance.
- Parameters:
line (LineString) – The LineString to be split.
dist (float) – The distance at which to split the LineString.
- Returns:
Two LineString segments resulting from the split.
- Return type:
Tuple[LineString, LineString]
- gtkit.gops.extrapolate(p1: Point, p2: Point, ratio: int = 15) LineString[source]
Extrapolate a LineString between two points based on a given ratio.
- Parameters:
p1 (Point) – The first Point.
p2 (Point) – The second Point.
ratio (int, optional) – The extrapolation ratio. Defaults to 15.
- Returns:
The extrapolated LineString.
- Return type:
LineString
- gtkit.gops.geo_transform_to_26190(width: int, height: int, bounds: Tuple[float, float, float, float], crs: Dict) Affine[source]
Transform geographic coordinates to EPSG:26910 (NAD83 UTM Zone 10N) coordinates.
- Parameters:
width (int) – Width of the array.
height (int) – Height of the array.
bounds (tuple) – A tuple representing the bounds (xmin, ymin, xmax, ymax).
crs (dict) – Coordinate Reference System of the input coordinates.
- Returns:
The affine transformation matrix for the EPSG:26910 coordinates.
- Return type:
Affine
- gtkit.gops.get_pts_on_orthogonal_line_and_orthogonal_line(pt1: Point, pt2: Point, width: float) LineString[source]
Get a LineString representing points on an orthogonal line offset by a given road width.
- Parameters:
pt1 (Point) – The first Point to define the orthogonal line.
pt2 (Point) – The second Point to define the orthogonal line.
width (float) – The road width for offset.
- Returns:
A LineString representing points on an orthogonal line offset by the road width.
- Return type:
LineString
- gtkit.gops.get_reference_shift(center_line_points: List[Point], translated_line: LineString) List[Point][source]
Get the projected points on a translated LineString from a list of center LineString points.
- Parameters:
center_line_points (List[Point]) – List of center LineString points.
translated_line (LineString) – The translated LineString.
- Returns:
List of projected points on the translated LineString.
- Return type:
List[Point]
- gtkit.gops.interpolate_with_delta(line: LineString, delta: float, distances: List[float] | None = None) List[Point][source]
Interpolate points along a LineString at specified intervals or distances.
- Parameters:
line (LineString) – The LineString to interpolate points along.
delta (float) – The interval or distance between interpolated points.
distances (List[float], optional) – List of specific distances for interpolation. Defaults to None.
- Returns:
List of interpolated points along the LineString.
- Return type:
List[Point]
- gtkit.gops.is_orientation_clockwise(co_ords: ndarray) bool[source]
Check if the orientation of coordinates is clockwise.
- Parameters:
co_ords (np.ndarray) – Array of coordinates.
- Returns:
True if the orientation is clockwise, False otherwise.
- Return type:
bool
- gtkit.gops.line_referencing(line: LineString | MultiLineString, point: Point) Tuple[int | float, Point][source]
Calculate the fraction of the given Point’s position along the LineString and the projected Point on the LineString.
- Parameters:
line (Union[LineString, MultiLineString]) – The LineString or MultiLineString geometry.
point (Point) – The Point to be projected onto the LineString.
- Returns:
The fraction of the Point’s position and the projected Point on the LineString.
- Return type:
Tuple[Union[int, float], Point]
- gtkit.gops.midpoint(line: LineString) Point[source]
Calculate the midpoint of a LineString.
- Parameters:
line (LineString) – The input LineString geometry.
- Returns:
The midpoint point of the LineString.
- Return type:
Point
- gtkit.gops.re_project_crs_to_26190(bounds: Tuple[float, float, float, float], from_crs: Dict) Tuple[float, float, float, float][source]
Reproject bounds from a given CRS to EPSG:26910 (NAD83 UTM Zone 10N).
- Parameters:
bounds (tuple) – A tuple representing the bounds (xmin, ymin, xmax, ymax).
from_crs (dict) – Source Coordinate Reference System.
- Returns:
Reprojected bounds in EPSG:26910 coordinates as (west, south, east, north).
- Return type:
tuple
- gtkit.gops.re_project_from_26190(bounds: Tuple[float, float, float, float], to_crs: Dict) Tuple[float, float, float, float][source]
Reproject bounds from EPSG:26910 (NAD83 UTM Zone 10N) to a target CRS.
- Parameters:
bounds (tuple) – A tuple representing the bounds (xmin, ymin, xmax, ymax).
to_crs (dict) – Target Coordinate Reference System.
- Returns:
Reprojected bounds in the target CRS as (west, south, east, north).
- Return type:
tuple
gtkit.gpdops module
- gtkit.gpdops.bbox_df(inp_df: GeoDataFrame) GeoDataFrame[source]
Create bounding boxes around geometries in a GeoDataFrame.
- Parameters:
inp_df (gpd.GeoDataFrame) – The GeoDataFrame containing geometries.
- Returns:
The GeoDataFrame with bounding boxes.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.cluster_shapes_by_distance(df: GeoDataFrame, distance: float, check_crs: bool = False) GeoDataFrame[source]
https://gis.stackexchange.com/a/437352
Make groups for all shapes within a defined distance. For a shape to be excluded from a group, it must be greater than the defined distance from all shapes in the group. Distances are calculated using shape centroids.
Cluster shapes within a defined distance based on centroids.
- Parameters:
df (gpd.GeoDataFrame) – The GeoDataFrame containing shapes.
distance (float) – The distance threshold for clustering.
check_crs (bool, optional) – Check if the GeoDataFrame has a projected CRS. Defaults to False.
- Returns:
The GeoDataFrame with cluster labels.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.create_temp_df(from_df: GeoDataFrame) GeoDataFrame[source]
Create an empty GeoDataFrame with the same columns and CRS as the input GeoDataFrame.
- Parameters:
from_df (gpd.GeoDataFrame) – The input GeoDataFrame.
- Returns:
An empty GeoDataFrame with matching columns and CRS.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.get_centroid(geom_df: GeoDataFrame) GeoDataFrame[source]
Calculate the centroid for each geometry in the GeoDataFrame.
- Parameters:
geom_df (gpd.GeoDataFrame) – The GeoDataFrame containing geometries.
- Returns:
The GeoDataFrame with centroid points added.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.get_centroid3d(geom_df: GeoDataFrame) GeoDataFrame[source]
Calculate the 3D centroid for each geometry in the GeoDataFrame.
- Parameters:
geom_df (gpd.GeoDataFrame) – The GeoDataFrame containing geometries.
- Returns:
The GeoDataFrame with 3D centroids added.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.get_common_columns(df_a: GeoDataFrame, df_b: GeoDataFrame) Tuple[GeoDataFrame, GeoDataFrame][source]
Get GeoDataFrames with common columns between two GeoDataFrames.
- Parameters:
df_a (gpd.GeoDataFrame) – The first GeoDataFrame.
df_b (gpd.GeoDataFrame) – The second GeoDataFrame.
- Returns:
GeoDataFrames with common columns.
- Return type:
Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]
- gtkit.gpdops.get_points_within_bbox(bbox: GeoDataFrame, points: GeoDataFrame) GeoDataFrame[source]
Get points within a bounding box.
- Parameters:
bbox (gpd.GeoDataFrame) – The GeoDataFrame representing the bounding box.
points (gpd.GeoDataFrame) – The GeoDataFrame containing points.
- Returns:
The GeoDataFrame with points within the bounding box.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.gpdread(inp_file: str) GeoDataFrame[source]
Read a GeoDataFrame from a file.
- Parameters:
inp_file (str) – The path to the input file.
- Returns:
The GeoDataFrame read from the file.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.line_midpoint_df(geom_df: GeoDataFrame) GeoDataFrame[source]
Calculate midpoints for line geometries in a GeoDataFrame.
- Parameters:
geom_df (gpd.GeoDataFrame) – The GeoDataFrame containing line geometries.
- Returns:
The GeoDataFrame with midpoint geometries added.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.merge_geometries(in_df: GeoDataFrame) GeoDataFrame[source]
Merge geometries within a GeoDataFrame into a single geometry.
- Parameters:
in_df (gpd.GeoDataFrame) – The GeoDataFrame containing geometries to merge.
- Returns:
The GeoDataFrame with merged geometries.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.merge_geoms_df_from_file(inp_file: str) GeoDataFrame[source]
Read a GeoDataFrame from a file and merge its geometries.
- Parameters:
inp_file (str) – The path to the input file.
- Returns:
The GeoDataFrame with merged geometries.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.nearest_linestring_to_a_point_df(pts: GeoDataFrame, lines: GeoDataFrame) GeoDataFrame[source]
Find the nearest linestring to each point in a GeoDataFrame.
- Parameters:
pts (gpd.GeoDataFrame) – The GeoDataFrame containing points.
lines (gpd.GeoDataFrame) – The GeoDataFrame containing linestrings.
- Returns:
The resulting GeoDataFrame with nearest line information.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.non_overlapping_columns(a: GeoDataFrame, b: GeoDataFrame) list[source]
Get a list of columns that are in GeoDataFrame a but not in GeoDataFrame b.
- Parameters:
a (gpd.GeoDataFrame) – The first GeoDataFrame.
b (gpd.GeoDataFrame) – The second GeoDataFrame.
- Returns:
A list of non-overlapping column names.
- Return type:
list
- gtkit.gpdops.points_in_a_radius_around_centroid(centroid: GeoDataFrame, lines: GeoDataFrame, raduis: int = 5) GeoDataFrame[source]
Find points within a specified radius around centroids.
- Parameters:
centroid (gpd.GeoDataFrame) – The GeoDataFrame containing centroid geometries.
lines (gpd.GeoDataFrame) – The GeoDataFrame containing linestrings.
raduis (int, optional) – The radius within which to search for points. Defaults to 5.
- Returns:
The resulting GeoDataFrame with points within the radius.
- Return type:
gpd.GeoDataFrame
- gtkit.gpdops.project_points_to_line(points: GeoDataFrame, lines: GeoDataFrame) GeoDataFrame[source]
Project points onto the nearest positions on lines.
- Parameters:
points (gpd.GeoDataFrame) – The GeoDataFrame containing points to project.
lines (gpd.GeoDataFrame) – The GeoDataFrame containing lines to project onto.
- Returns:
The GeoDataFrame with projected points.
- Return type:
gpd.GeoDataFrame
gtkit.imgops module
gtkit.imutils module
- gtkit.imutils.compute_bounds(width: int, height: int, transform: Affine) Tuple[float, float, float, float][source]
Compute the bounds of an array using its dimensions and affine transformation.
- Parameters:
width (int) – Width of the array.
height (int) – Height of the array.
transform (Affine) – An affine transformation matrix.
- Returns:
A tuple containing the computed bounds (xmin, ymin, xmax, ymax).
- Return type:
tuple
- gtkit.imutils.get_affine_transform(min_x: float, max_y: float, pixel_width: float, pixel_height: float) Affine[source]
Generate an affine transformation matrix based on translation and scaling.
- Parameters:
min_x (float) – Minimum x-coordinate value.
max_y (float) – Maximum y-coordinate value.
pixel_width (float) – Pixel width.
pixel_height (float) – Pixel height.
- Returns:
The generated affine transformation matrix.
- Return type:
Affine
- gtkit.imutils.get_pixel_resolution(transform: Affine) Tuple[float, float][source]
Get the pixel resolution from an affine transformation matrix.
- Parameters:
transform (Affine) – An affine transformation matrix.
- Returns:
The pixel resolution as (pixel_width, pixel_height).
- Return type:
tuple
- gtkit.imutils.get_window(extent: Tuple[float, float, float, float], transform: Affine) Tuple[Tuple[int, int], Tuple[int, int]][source]
Calculate the row and column window indices for the given extent and affine transform.
- Parameters:
extent (tuple) – A tuple representing the extent (xmin, ymin, xmax, ymax) of the window.
transform (Affine) – An affine transformation matrix.
- Returns:
A tuple containing the row and column window indices as (row_indices, col_indices).
- Return type:
tuple
gtkit.mesh module
- class gtkit.mesh.ImageMesh[source]
Bases:
MeshClass for generating image-based mesh data.
- None
- _step_in_x(bound
Tuple[float, float, float, float], normalizer: int = 1) -> int: Compute step size in X.
- _step_in_y(bound
Tuple[float, float, float, float], normalizer: int = 1) -> int: Compute step size in Y.
- collate_data(extent
Tuple[float, float, float, float]) -> dict: Collate data for a mesh element.
Methods
collate_data(extent)Collate data for a mesh element.
mesh()Compute mesh elements.
- class gtkit.mesh.ImageNonOverLapMesh(grid_size: tuple, mesh_size: tuple, sections: tuple, mesh_transform: Affine, mesh_bound: tuple)[source]
Bases:
ImageMeshThe Class will compute Grid bounded within complete_size to provide non overlapping grid, The class will adjust the grid to evenly fit the number of tiles
Working of this class depends on the geo reference information of the image which acts as the starting point
The geo reference information to be present in the image is source_min_x, source_max_y and pixel resolution
Based on the geo reference information present in the image, compute grid of size complete_size // int(np.ceil(dst_img_size / src_img_size) over complete_size
Given an starting image size, final size and its transform this will find all the grid of size complete_size // int(np.ceil(dst_img_size / src_img_size) between the given complete size
The start position of grid and the step size of grid is computed from the transform info provided, usually present in geo referenced image
NOTE - The COORDINATES MUST BE IN EPSG:26910
- grid_size
Size of the grid in rows and columns.
- Type:
tuple
- mesh_size
Size of the mesh.
- Type:
tuple
- sections
Number of sections in rows and columns.
- Type:
tuple
- mesh_transform
Mesh transformation.
- Type:
affine.Affine
- mesh_bound
Mesh boundary coordinates.
- Type:
tuple
- collate_data(extent
Tuple[float, float, float, float]) -> dict: Collate data for a mesh element.
Methods
collate_data(extent)Collate data for a mesh element.
mesh()Generate non-overlapping grid bounded within specified bounds.
- collate_data(extent: Tuple[float, float, float, float]) dict[source]
Collate data for a mesh element.
- Parameters:
extent (Tuple[float, float, float, float]) – Extent coordinates.
- Returns:
Collated data.
- Return type:
dict
- grid_size: tuple
- mesh() Generator[dict, None, None][source]
Generate non-overlapping grid bounded within specified bounds.
- Yields:
dict – Data describing each mesh element.
- mesh_bound: tuple
- mesh_size: tuple
- mesh_transform: Affine
- sections: tuple
- class gtkit.mesh.ImageOverLapMesh(grid_size: tuple, mesh_size: tuple, sections: tuple, mesh_transform: Affine, mesh_bound: tuple, overlap_mesh_bound: Tuple[float, float, float, float], buffer_mesh_bound: tuple)[source]
Bases:
ImageMeshThe Class will compute Grid bounded within complete_size and if the provided grid size overlaps, the the class will tune accordingly to provide overlapping grid, The class wont hamper the grid size in any manner, it will find all the possible grid of size provided that could fit in complete_size
Working of this class depends on the geo reference information of the image which acts as the starting point
The geo reference information to be present in the image is source_min_x, source_max_y and pixel resolution
Based on the geo reference information present in the image, compute grid of size grid_size over complete_size
Given an starting image size, final size and its transform this will find all the grid of size image size between the given complete size
The start position of grid and the step size of grid is computed from the transform info provided, usually present in geo referenced image
NOTE - The COORDINATES MUST BE IN EPSG:26910
- grid_size
Size of the grid in rows and columns.
- Type:
tuple
- mesh_size
Size of the mesh.
- Type:
tuple
- sections
Number of sections in rows and columns.
- Type:
tuple
- mesh_transform
Mesh transformation.
- Type:
affine.Affine
- mesh_bound
Mesh boundary coordinates.
- Type:
tuple
- overlap_mesh_bound
Overlap mesh boundary coordinates.
- Type:
Tuple[float, float, float, float]
- buffer_mesh_bound
Buffer mesh boundary coordinates.
- Type:
tuple
- collate_data(extent
Tuple[float, float, float, float]) -> dict: Collate data for a mesh element.
Methods
collate_data(extent)Collate data for a mesh element.
mesh()Generate overlapping grid within specified bounds.
- buffer_mesh_bound: tuple
- collate_data(extent: Tuple[float, float, float, float]) dict[source]
Collate data for a mesh element.
- Parameters:
extent (Tuple[float, float, float, float]) – Extent coordinates.
- Returns:
Collated data.
- Return type:
dict
- grid_size: tuple
- mesh() Generator[dict, None, None][source]
Generate overlapping grid within specified bounds.
- Yields:
dict – Data describing each mesh element.
- mesh_bound: tuple
- mesh_size: tuple
- mesh_transform: Affine
- overlap_mesh_bound: Tuple[float, float, float, float]
- sections: tuple
- class gtkit.mesh.Mesh[source]
Bases:
objectBase class for generating mesh data.
- None
Methods
collate_data(**kwargs)Abstract method to collate data.
mesh()Abstract method to compute mesh.
- class gtkit.mesh.ShpMesh(geom: LineString, grid_width: float, mesh_width: float)[source]
Bases:
MeshClass for generating mesh data based on a LineString geometry.
- geom
LineString geometry.
- Type:
LineString
- grid_width
Width of the grid cells.
- Type:
float
- mesh_width
Width of the mesh.
- Type:
float
- _get_horizontal_lines(grid_lines
np.ndarray) -> List[LineString]: Get horizontal lines from grid lines.
- _get_vertical_lines(grid_lines
np.ndarray) -> List[LineString]: Get vertical lines from grid lines.
- _generate_grid_line(pts, distance
float, side: str) -> np.ndarray: Generate a grid line.
- collate_data(geom
Polygon) -> dict: Collate data for a mesh element.
- Attributes:
- total_grid
Methods
collate_data(geom, **kwargs)Collate data for a mesh element.
mesh()Generate mesh based on the LineString geometry.
- collate_data(geom: Polygon, **kwargs) dict[source]
Collate data for a mesh element.
- Parameters:
geom (Polygon) – Polygon geometry.
- Returns:
Collated data.
- Return type:
dict
- geom: LineString
- grid_width: float
- mesh()[source]
Generate mesh based on the LineString geometry.
- Yields:
dict – Data describing each mesh element.
- mesh_width: float
- property total_grid
- gtkit.mesh.compute_dimension(bounds: Tuple[float, float, float, float], pixel_resolution: Tuple[float, float]) Tuple[int, int][source]
Compute the output dimensions based on bounds and pixel resolution.
- Parameters:
bounds (tuple) – A tuple representing the bounds (xmin, ymin, xmax, ymax).
pixel_resolution (tuple) – Pixel resolution as (pixel_width, pixel_height).
- Returns:
The output dimensions as (output_width, output_height).
- Return type:
tuple
- gtkit.mesh.compute_num_of_col_and_rows(grid_size: Tuple[int, int], mesh_size: Tuple[int, int]) Tuple[int, int][source]
Compute the number of columns and rows in a mesh grid based on grid size and mesh size.
- Parameters:
grid_size (tuple) – A tuple representing the grid size (grid_width, grid_height).
mesh_size (tuple) – A tuple representing the mesh size (mesh_width, mesh_height).
- Returns:
The number of columns and rows in the mesh grid as (num_col, num_row).
- Return type:
tuple
- gtkit.mesh.create_mesh_using_img_param(mesh_bounds: Tuple[float, float, float, float], grid_size: Tuple[int, int], pixel_resolution: Tuple[float, float], is_overlap: bool = False) ImageNonOverLapMesh | ImageOverLapMesh[source]
Create a mesh using image parameters.
- Parameters:
mesh_bounds (Tuple[float, float, float, float]) – Tuple of minimum and maximum X and Y coordinates of the mesh.
grid_size (Tuple[int, int]) – Tuple representing the grid size in rows and columns.
pixel_resolution (Tuple[float, float]) – Tuple representing the pixel resolution in X and Y directions.
is_overlap (bool, optional) – Boolean indicating whether to use overlapping mesh. Defaults to False.
- Returns:
Either ImageNonOverLapMesh or ImageOverLapMesh instance.
- Return type:
Union[ImageNonOverLapMesh, ImageOverLapMesh]
- gtkit.mesh.get_mesh_transform(width: int, height: int, transform: Affine) Affine[source]
Generate an affine transformation matrix for a mesh grid within a given extent.
- Parameters:
width (int) – Width of the mesh grid.
height (int) – Height of the mesh grid.
transform (Affine) – An affine transformation matrix representing the extent.
- Returns:
The affine transformation matrix for the mesh grid.
- Return type:
Affine
- gtkit.mesh.mesh_from_img_param(grid_size: Tuple[int, int] | None = None, mesh_size: Tuple[int, int] | None = None, transform: Affine | None = None, mesh_bounds: Tuple[float, float, float, float] | None = None, overlap: bool = True) ImageNonOverLapMesh | ImageOverLapMesh[source]
Create a mesh from image parameters.
- Parameters:
grid_size (Tuple[int, int], optional) – Size of the grid in rows and columns. Defaults to None.
mesh_size (Tuple[int, int], optional) – Size of the mesh. Defaults to None.
transform (affine.Affine, optional) – Affine transformation. Defaults to None.
mesh_bounds (Tuple[float, float, float, float], optional) – Bounds of the mesh. Defaults to None.
overlap (bool, optional) – Whether to use overlapping mesh. Defaults to True.
- Returns:
Either ImageNonOverLapMesh or ImageOverLapMesh instance.
- Return type:
Union[ImageNonOverLapMesh, ImageOverLapMesh]
- gtkit.mesh.mesh_from_line(line: LineString, grid_width: float, mesh_width: float) ShpMesh[source]
Create a mesh from a LineString.
- Parameters:
line (LineString) – LineString geometry representing the line.
grid_width (float) – Width of the grid cells.
mesh_width (float) – Width of the mesh.
- Returns:
ShpMesh instance.
- Return type:
gtkit.mops module
- gtkit.mops.angle_between_vector(v1: tuple, v2: tuple)[source]
Calculate the angle in radians between two vectors.
- Parameters:
v1 (np.ndarray) – The first vector.
v2 (np.ndarray) – The second vector.
- Returns:
The angle in radians between the two vectors.
- Return type:
float
two vectors have either the same direction - https://stackoverflow.com/a/13849249/71522
- gtkit.mops.euclidean(coordinates_a: ndarray) ndarray[source]
This function will return set of distances from coordinates_a to coordinates_a ex -
coordinates_a = [[0, 0], [1, 1]]
- return
sets of distances from [0, 0] to all the coordinates present in coordinates_a sets of distances from [1, 1] to all the coordinates present in coordinates_a
- visually -
- distance from [0, 0] to [0, 0] | distance from [1, 1] to [0, 0] |distance from [0, 0] to [1, 1] | distance from [1, 1] to [1, 1] |
resulting in shape of [n_coordinates_a, n_coordinates_a]
Calculate the Euclidean distances between points in a set of coordinates.
- Parameters:
coordinates_a (np.ndarray) – The set of coordinates.
- Returns:
The distances between points in the same set of coordinates.
- Return type:
np.ndarray
- gtkit.mops.euclidean_between_two_sets(coordinates_a: ndarray, coordinates_b: ndarray) ndarray[source]
This function will return set of distances from coordinates_b to coordinates_a ex -
coordinates_b = [[0, 0], [1, 1]] coordinates_a = [[2, 1], [3, 1], [2, 4], [5, 2]]
- return
sets of distances from [0, 0] to all the coordinates present in coordinates_a sets of distances from [1, 1] to all the coordinates present in coordinates_a
- visually -
- distance from [0, 0] to [2, 1] | distance from [1, 1] to [2, 1] |distance from [0, 0] to [3, 1] | distance from [1, 1] to [3, 1] |distance from [0, 0] to [2, 4] | distance from [1, 1] to [2, 4] |distance from [0, 0] to [5, 2] | distance from [1, 1] to [5, 2] |
resulting in shape of [n_coordinates_a, n_coordinates_b]
Calculate the Euclidean distances between two sets of coordinates.
- Parameters:
coordinates_a (np.ndarray) – The first set of coordinates.
coordinates_b (np.ndarray) – The second set of coordinates.
- Returns:
The distances between coordinates_b and each coordinate in coordinates_a.
- Return type:
np.ndarray
- gtkit.mops.magnitude(vec: ndarray, axis=-1) ndarray[source]
Calculate the magnitude of a vector.
- Parameters:
vec (np.ndarray) – The vector.
axis (int, optional) – The axis along which to calculate the magnitude. Defaults to -1.
- Returns:
The magnitude of the vector.
- Return type:
np.ndarray
- gtkit.mops.new_coordinate_based_on_angle_and_distance(points: ndarray, angle: ndarray, distance: ndarray) ndarray[source]
Given a Point find a new point at an given ‘angle’ with given ‘distance’
/ B [New Point]
/
/ angle CAB and distance AB [GIVEN]
A ———— C
Calculate new coordinates based on an angle and a distance from the input points.
- Parameters:
points (np.ndarray) –
array of shape [number_of_line_segments, 1, 2] If the line segment to which perpendicular distances are to be computed then pass it as follows :
- – the dimension [number_of_points, 1, 2] are [
[ [point_1_x, point_1_y], ], [ [point_2_x, point_2_y], ], …. … [ [point_n_x, point_n_y], ],
]
angle (np.ndarray) – array of shape [number_of_points, 1, 1]
distance (np.ndarray) – array of shape [number_of_points, 1, 1]
- Returns:
New coordinates calculated from the given points, angles, and distances.
- Return type:
np.ndarray
- gtkit.mops.new_perpendicular_point_to_line_segment(line_segment: ndarray, distance_from_the_line: ndarray)[source]
Get perpendicular point with reference to start and end point of the segment
Calculate new perpendicular points on line segments at a certain distance from the line.
- Parameters:
line_segment (np.ndarray) –
array of shape [number_of_line_segments, 2, 2]
If the line segment to which perpendicular distances are to be computed then pass it as follows :
- – the dimension [number_of_line_segments, 2, 2] are [
[ [start_line_segment_1_x, start_line_segment_1_y], [end_line_segment_1_x, end_line_segment_1_y] ], [ [start_line_segment_2_x, start_line_segment_2_y], [end_line_segment_2_x, end_line_segment_2_y] ], …. … [ [start_line_segment_n_x, start_line_segment_n_y], [end_line_segment_n_x, end_line_segment_n_y] ],
]
distance_from_the_line (np.ndarray) – Distances from the line.
- Returns:
New perpendicular points calculated at the specified distances from the line, (perpendicular points with reference to start, perpendicular points with reference to end)
return is of shape [number_of_segments, 2, 2]
[A_n] [C_n] | line_segment_with | |-----------------------------| | index value ‘n’ | [B_n] [D_n]
to get points -
A_n - perpendicular_with_start[segment_index_value_n, 0, :] B_n - perpendicular_with_start[segment_index_value_n, 1, :] C_n - perpendicular_with_end[segment_index_value_n, 0, :] D_n - perpendicular_with_end[segment_index_value_n, 1, :].
- Return type:
np.ndarray
- gtkit.mops.new_point_after_certain_distance(line_segments: ndarray, distance_from_start: ndarray) ndarray[source]
https://math.stackexchange.com/questions/175896/finding-a-point-along-a-line-a-certain-distance-away-from-another-point https://math.stackexchange.com/a/426810
Calculate new points along line segments at a certain distance from the start points.
- Parameters:
line_segments (np.ndarray) –
array of shape [number_of_line_segments, 2, 2]
If the line segment to which perpendicular distances are to be computed then pass it as follows :
- – the dimension [number_of_line_segments, 2, 2] are [
[ [start_line_segment_1_x, start_line_segment_1_y], [end_line_segment_1_x, end_line_segment_1_y] ], [ [start_line_segment_2_x, start_line_segment_2_y], [end_line_segment_2_x, end_line_segment_2_y] ], …. … [ [start_line_segment_n_x, start_line_segment_n_y], [end_line_segment_n_x, end_line_segment_n_y] ],
]
distance_from_start (np.ndarray) – array specifying the distance to compute the point shape [number_of_line_segments, 1, 1] or [1, 1]
- Returns:
New points calculated at the specified distances from the start points of the line segments.
- Return type:
np.ndarray
- gtkit.mops.perpendicular_distance_from_point_to_line_segment_in_2d(line_segment: ndarray, coordinates: ndarray) ndarray[source]
The function will compute perpendicular distance for the coordinates value present in coordinates to the given input line segment
- if single line segment is passed for computation, i.e. input with dim [1, 2, 2] then expect the output in
- format:
- distance from line_Segment_1 to coordinate[0] …. | …. distance from line_Segment_1 to coordinate[n] |
- if multiple line segments are passed for computation, i.e. input with dim [n_segments, 2, 2] then expect
- the output in format:
- distance from line_Segment_1 to coordinate[0] …. | … distance from line_Segment_1 to coordinate[n] |distance from line_Segment_2 to coordinate[0] …. | … distance from line_Segment_2 to coordinate[n] |
… | distance from line_Segment_n to coordinate[0] …. | …distance from line_Segment_n to coordinate[n] |
Calculate the perpendicular distances from points to line segments in 2D.
- Parameters:
line_segment (np.ndarray) –
array of shape [number_of_line_segments, 2, 2]
If the line segment to which perpendicular distances are to be computed then pass it as follows :
- – the dimension [number_of_line_segments, 2, 2] are [
[ [start_line_segment_1_x, start_line_segment_1_y], [end_line_segment_1_x, end_line_segment_1_y] ], [ [start_line_segment_2_x, start_line_segment_2_y], [end_line_segment_2_x, end_line_segment_2_y] ], …. … [ [start_line_segment_n_x, start_line_segment_n_y], [end_line_segment_n_x, end_line_segment_n_y] ],
]
coordinates (np.ndarray) – array of shape [number of points, 2]
- Returns:
Perpendicular distances from each point to each line segment, array of shape [number of segments, number of points].
- Return type:
np.ndarray
- gtkit.mops.unit_vector(vec: ndarray, axis=-1) ndarray[source]
Calculate the unit vector of a vector.
- Parameters:
vec (np.ndarray) – The vector.
axis (int, optional) – The axis along which to calculate the unit vector. Defaults to -1.
- Returns:
The unit vector of the input vector.
- Return type:
np.ndarray