RSGISLib Vector Geometry Module
Convert Geometries
- rsgislib.vectorgeoms.convert_polygon_to_polyline(vec_poly_file: str, vec_poly_lyr: str, vec_line_file: str, vec_line_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function to convert a polygon vector file to a polyline file.
- Parameters:
vec_poly_file – Input polygon vector file
vec_poly_lyr – The name of the vector layer
vec_line_file – The output vector file
vec_line_lyr – The output vector layer name
out_format – The output vector file format (default: GPKG).
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.convert_polys_to_lines_gp(vec_poly_file: str, vec_poly_lyr: str, vec_line_file: str, vec_line_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False, exterior_lines: bool = False)
A function to convert a polygon vector file to a polyline file using geopandas.
- Parameters:
vec_poly_file – Input polygon vector file
vec_poly_lyr – The name of the vector layer
vec_line_file – The output vector file
vec_line_lyr – The output vector layer name
out_format – The output vector file format (default: GPKG).
del_exist_vec – remove output file if it exists.
exterior_lines – If True then only the outer exterior lines are outputted.
- rsgislib.vectorgeoms.convert_multi_geoms_to_single(vec_file: str, vec_lyr: str, out_format: str, out_vec_file: str, out_vec_lyr: str, del_exist_vec: bool = False)
A convert any multiple geometries into single geometries.
- Parameters:
vec_file – input vector file
vec_lyr – input vector layer within the input file.
out_format – the format driver for the output vector file (e.g., GPKG, ESRI Shapefile).
out_vec_file – output file path for the vector.
out_vec_lyr – output vector layer name.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.explode_vec_lyr(vec_file: str, vec_lyr: str, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG')
A function to explode a vector layer separating any multiple geometries (e.g., multipolygons) to single geometries.
Note. this function uses geopandas and therefore the vector layer is loaded into memory.
- Parameters:
vec_file – vector layer file
vec_lyr – vector layer name
out_vec_file – output vector layer file
out_vec_lyr – output vector layer name (Can be None if output format is not GPKG).
out_format – The output format for the vector file.
- rsgislib.vectorgeoms.explode_vec_files(in_vec_files: List[str], output_dir: str, out_format: str = 'GPKG', out_vec_ext: str = 'gpkg')
A function which explodes the multiple geometries within a list of input layers. The output directory must be different to the directory the input files as the output file name will be the same as the input name.
Note. this function uses the explode_vec_lyr function which uses geopandas and therefore the vector layer is loaded into memory.
- Parameters:
in_vec_files – A list of input files.
output_dir – The directory where the output files will be placed.
out_format – The vector format for the outputs.
out_vec_ext – the file extension for the output files. There should not be a dot within the extension. e.g., gpkg, shp, geojson.
- rsgislib.vectorgeoms.get_vec_lyr_as_pts(vec_file: str, vec_lyr: str) List
Get a list of points from the vectors within an input file.
- Parameters:
vec_file – Input vector file
vec_lyr – Input vector layer name
- Returns:
returns a list of points.
- rsgislib.vectorgeoms.get_geom_pts(geom: Geometry, pts_lst: List = None) List
Recursive function which extracts all the points within the an OGR geometry.
- Parameters:
geom – The geometry from with the points are extracted.
pts_lst – The list for the points, if None a list will be created.
- Returns:
a list of points.
- rsgislib.vectorgeoms.get_geoms_as_bboxs(vec_file: str, vec_lyr: str) List[Tuple[float, float, float, float]]
A function which returns a list of bounding boxes for each feature within the vector layer.
- Parameters:
vec_file – vector file.
vec_lyr – layer within the vector file.
- Returns:
list of BBOXs
Calculate New Geometries
- rsgislib.vectorgeoms.clip_vec_lyr(vec_file: str, vec_lyr: str, vec_roi_file: str, vec_roi_lyr: str, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG')
A function which clips a vector layer using an input region of interest (ROI) polygon layer.
- Parameters:
vec_file – Input vector file.
vec_lyr – Input vector layer within the input file.
vec_roi_file – Input vector file defining the ROI polygon(s)
vec_roi_lyr – Input vector layer within the roi input file.
out_vec_file – Output vector file
out_vec_lyr – Output vector layer name.
out_format – Output file format (default GPKG).
- rsgislib.vectorgeoms.clip_and_merge_with_roi(vec_file: str, vec_lyr: str, vec_roi_file: str, vec_roi_lyr: str, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG', dissolve_lyr: bool = False, explode_rslt_lyr: bool = False, ref_col_name: str = 'ref_bkgrd', roi_rgn_val: int = 0, data_rgn_val: int = 1)
This function clips the input vector layer (vec_file) using the region of interest (ROI; vec_roi_file) and merges the clipped vector with the ROI. The input layers should both be polygon layers.
- Parameters:
vec_file – Input vector file.
vec_lyr – Input vector layer within the input file.
vec_roi_file – Input vector file defining the ROI polygon(s)
vec_roi_lyr – Input vector layer within the roi input file.
out_vec_file – Output vector file
out_vec_lyr – Output vector layer name.
out_format – Output file format (Default: GPKG).
dissolve_lyr – After clipping the input vec_lyr the layer can optionally be dissolved - which would merge all neighbouring polygons.
ref_col_name – The name of a column which is added to the output vector layer to indicate which features are from the background ROI and those from the input vector layer (Default: ref_bkgrd)
roi_rgn_val – The value to indicate polygons which relate to the background region of interest (Default: 0).
data_rgn_val – The value to indicate polygons which relate to the input data (Default: 1).
- rsgislib.vectorgeoms.create_alpha_shape(vec_file: str, vec_lyr: str, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG', alpha_val: float = None, alpha_vals: List = None, max_iter: int = 10000, del_exist_vec: bool = False)
Function which calculate an alpha shape for a set of vector features (which are converted to points).
For this function to work you need the alphashapes module installed: https://alphashape.readthedocs.io https://github.com/bellockk/alphashape
- Parameters:
vec_file – the input vector file.
vec_lyr – the input vector layer name
out_vec_file – the output vector file.
out_vec_lyr – the name of the output vector layer (if None then the same as the input).
out_format – the output vector file format (e.g., GPKG)
alpha_val – The alpha value to create the the alpha shape polygon. If None then a value will be automatically calculate but warning this can a significant amount of time (i.e., hours!!)
alpha_vals – Alternatively, a list of alpha values can be provided (e.g., [75, 50, 25, 5, 2]) where first to produce a valid result will be outputted. i.e., the order you provide the alpha values will be the order they are tested. If None then the alpha_val parameter will be used.
max_iter – The maximum number of iterations for automatically selecting the alpha value. Note if the number iteration is not sufficient to find an optimum value then no value is returned.
del_exist_vec – remove output file if it exists.
- Returns:
(vec_output, alpha_val); vec_output is a boolean True an output produced; False no output, alpha_val - the alpha value used for the analysis. If a single value was inputted then the same value will be outputted.
- rsgislib.vectorgeoms.calc_poly_centroids(vec_file: str, vec_lyr: str, out_format: str, out_vec_file: str, out_vec_lyr: str)
Create a vector layer of the polygon centroids.
- Parameters:
vec_file – input vector file
vec_lyr – input vector layer within the input file.
out_format – the format driver for the output vector file (e.g., GPKG).
out_vec_file – output file path for the vector.
out_vec_lyr – output vector layer name.
- rsgislib.vectorgeoms.vec_lyr_intersection_gp(vec_file: str, vec_lyr: str, vec_over_file: str, vec_over_lyr: str, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which performs an intersection between the vector layer and the overlain vector using Geopandas.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
vec_over_file – The vector file overlained on the input vector file.
vec_over_lyr – The vector layer overlained on the input vector file.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.vec_lyr_difference_gp(vec_file: str, vec_lyr: str, vec_over_file: str, vec_over_lyr: str, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which performs a difference between the vector layer and the overlain vector using Geopandas.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
vec_over_file – The vector file overlained on the input vector file.
vec_over_lyr – The vector layer overlained on the input vector file.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.vec_lyr_sym_difference_gp(vec_file: str, vec_lyr: str, vec_over_file: str, vec_over_lyr: str, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which performs a symmetric difference between the vector layer and the overlain vector using Geopandas.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
vec_over_file – The vector file overlained on the input vector file.
vec_over_lyr – The vector layer overlained on the input vector file.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.vec_lyr_identity_gp(vec_file: str, vec_lyr: str, vec_over_file: str, vec_over_lyr: str, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which performs a identity between the vector layer and the overlain vector using Geopandas.
The result consists of the surface of vec_file, but with the geometries obtained from overlaying vec_file with vec_over_file.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
vec_over_file – The vector file overlained on the input vector file.
vec_over_lyr – The vector layer overlained on the input vector file.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.vec_lyr_union_gp(vec_file: str, vec_lyr: str, vec_over_file: str, vec_over_lyr: str, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which performs a union between the vector layer and the overlain vector using Geopandas.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
vec_over_file – The vector file overlained on the input vector file.
vec_over_lyr – The vector layer overlained on the input vector file.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.vec_lyr_intersection(vec_file: str, vec_lyr: str, vec_over_file: str, vec_over_lyr: str, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which performs an intersection between the vector layer and the overlain vector.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
vec_over_file – The vector file overlained on the input vector file.
vec_over_lyr – The vector layer overlained on the input vector file.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.vec_lyr_difference(vec_file: str, vec_lyr: str, vec_over_file: str, vec_over_lyr: str, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', symmetric: bool = False, del_exist_vec: bool = False)
A function which performs an difference between the vector layer and the overlain vector.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
vec_over_file – The vector file overlained on the input vector file.
vec_over_lyr – The vector layer overlained on the input vector file.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
symmetric – If True then the symmetric difference will be taken.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.vec_lyr_dissolve(vec_file: str, vec_lyr: str, vec_col: str, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG')
A function which dissolves a vector layer using a variable within the attribute table.
- Parameters:
vec_file – Input vector file.
vec_lyr – Input vector layer within the input file.
vec_col – The column within the attribute table with the variable to dissolve on. The variable must be categorical.
out_vec_file – Output vector file
out_vec_lyr – Output vector layer name.
out_format – Output file format (Default: GPKG).
- rsgislib.vectorgeoms.buffer_vec_layer_gp(vec_file: str, vec_lyr: str, buf_dist: float, out_vec_file: str, out_vec_lyr: str = None, out_format: str = 'GPKG', del_exist_vec: bool = False, buf_res: int = 16, buf_sgl_sided: bool = False, cap_style: int = 1, join_style: int = 1)
A function which performs a buffer on the inputted vector layer using geopandas.
- Parameters:
vec_file – Input vector file path.
vec_lyr – Input vector layer name.
buf_dist – radius of the buffer in the units of the projection.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
buf_res – resolution of the buffer around each vertex.
buf_sgl_sided – Option to just buffer a single side of the vector. If buf_dist is positive it indicates the left-hand side while is buf_dist is negative it indicates the right-hand side.
cap_style – round = 1, flat = 2, square = 3 (Default: 1; i.e., round)
join_style – mitre = 1, flat = 2, bevel = 3 (Default: 1; i.e., round)
- rsgislib.vectorgeoms.split_vec_by_grid(vec_file: str, vec_lyr: str, x_grid_size: float, y_grid_size: float, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG')
A function which splits an inputted vector using a regular grid across the whole area - note this function internally generates a geopandas dataframe with a grid covering the whole area so for a set of sparse features covering a large area with a small grid size this function will be pretty inefficient.
- Parameters:
vec_file – Input vector file
vec_lyr – Input vector layer
x_grid_size – grid size in x-axis. Unit is dependent on projection.
y_grid_size – grid size in x-axis. Unit is dependent on projection.
out_vec_file – Output vector file
out_vec_lyr – Output vector layer
out_format – Output vector format.
- rsgislib.vectorgeoms.split_lines_to_reg_pts(vec_in_file: str, vec_in_lyr: str, out_vec_file: str, out_vec_lyr: str = None, pt_step: float = 1000, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which splits a line vector layer into a set of points at a regular intervals (defined by pt_step). The outputted points are attributed with a unique ID, line ID, X and Y coordinate and distance from the start of the line.
- Parameters:
vec_in_file – The inputted vector file path - this should be a polyline vector file
vec_in_lyr – The name of the vector layer
out_vec_file – The output vector file path - this will be a points vector file
out_vec_lyr – The name of the output vector layer (if None then created as the same as the file name)
pt_step – The steps (in the unit of the coordinate system) along lines in the layer at which points are created.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.create_angle_lines_from_points(vec_file: str, vec_lyr: str, angle: float, line_len: float, out_vec_file: str, out_vec_lyr: str, out_format: str)
A function which calculates a set of points for each point within the input vector layer (which needs to be a points geometry layer) creating a set of lines with the angle specified between them and the length specified.
- Parameters:
vec_file – Input points vector file.
vec_lyr – input points vector layer
angle – the angle (in degrees) between the points
line_len – the length of the lines.
out_vec_file – the output vector file
out_vec_lyr – the output vector layer
out_format – the output vector format (e.g., GPKG, GeoJSON).
- rsgislib.vectorgeoms.create_bbox_vec_lyr(vec_file: str, vec_lyr: str, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG', whole_num_grid: bool = False, whole_num_base_grid: float = 10.0, whole_num_round: int = None)
A function which creates a new vector layer with a single polygon representing the bounding box (BBOX) / Envelope of the input vector layer.
- Parameters:
vec_file – Input vector file.
vec_lyr – Input vector layer within the input file.
out_vec_file – Output vector file
out_vec_lyr – Output vector layer name.
out_format – Output file format (Default: GPKG).
whole_num_grid – Specify whether the bbox coordinates are to be rounded on to a whole number grid. (Default: False)
whole_num_base_grid – the size of the (square) grid on which output will be defined. (Default: 10)
whole_num_round – specify whether outputted values should be rounded. None for no rounding (default; None) or integer for number of significant figures to round to.
Edit Geometries
- rsgislib.vectorgeoms.simplify_geometries(vec_file: str, vec_lyr: str, tolerance: float, out_format: str, out_vec_file: str, out_vec_lyr: str, del_exist_vec: bool = False)
Create a simplified version of the input
- Parameters:
vec_file – input vector file
vec_lyr – input vector layer within the input file.
tolerance – simplification tolerance
out_format – the format driver for the output vector file (e.g., GPKG, ESRI Shapefile).
out_vec_file – output file path for the vector.
out_vec_lyr – output vector layer name.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.delete_polygon_holes(vec_file: str, vec_lyr: str, out_format: str, out_vec_file: str, out_vec_lyr: str, area_thres: float = None, del_exist_vec: bool = False)
Delete holes from the input polygons in below the area threshold.
- Parameters:
vec_file – input vector file
vec_lyr – input vector layer within the input file.
out_format – the format driver for the output vector file (e.g., GPKG, ESRI Shapefile).
out_vec_file – output file path for the vector.
out_vec_lyr – output vector layer name.
area_thres – threshold below which holes are removed. If threshold is None then all holes are removed.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.shiftxy_vec_lyr(vec_file: str, vec_lyr: str, x_shift: float, y_shift: float, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG')
A function which shifts (translates) a vector layer in the x and y axis’.
- Parameters:
vec_file – Input vector file.
vec_lyr – Input vector layer within the input file.
x_shift – The shift in the x axis. In the units of the coordinate system the file is projected in.
y_shift – The shift in the y axis. In the units of the coordinate system the file is projected in.
out_vec_file – Output vector file
out_vec_lyr – Output vector layer name.
out_format – Output file format (default GPKG).
Remove Geometries
- rsgislib.vectorgeoms.rm_polys_area(vec_file: str, vec_lyr: str, area_thres: float, out_vec_file: str, out_vec_lyr: str, out_format: str = 'GPKG', less_than: bool = True)
A function which removes polygons with a size less than or greater than a defined threshold.
- Parameters:
vec_file – Input vector file
vec_lyr – Input vector layer
area_thres – the area threshold used to remove features
out_vec_file – the output vector file
out_vec_lyr – the output vector layer
out_format – the output vector format
less_than – boolean specifying whether threshold is less than or greater than. Default: True (i.e., less than).
- rsgislib.vectorgeoms.thin_vector_geoms(vec_file: str, vec_lyr: str, grid_vec_file: str, grid_vec_lyr: str, out_vec_file: str, out_vec_lyr: str, out_format: str)
A function which thins the geometries (points are the most likely) using an input set of polygons (most likely a grid). Just a single geometry (point) intersecting with a polygon (grid cell) within the grid input vector will be outputted. This function is expected to be used to thin a set of points, for example, such that only 1 point is within each 1 km grid cell.
Note. the input vector files must be the same projection.
- Parameters:
vec_file – The input vector file which is to be thinned (i.e., points vector)
vec_lyr – The input vector layer which is to be thinned (i.e., points vector)
grid_vec_file – The input vector file for the polygons (grid) used to thin the vec_file geometries (points)
grid_vec_lyr – The input vector layer for the polygons (grid) used to thin the vec_file geometries (points)
out_vec_file – the output vector file.
out_vec_lyr – the layer name for the output vector.
out_format – The output vector file format (Default GPKG)
Geometry Tests
- rsgislib.vectorgeoms.vec_intersects_vec(vec_base_file: str, vec_base_lyr: str, vec_comp_file: str, vec_comp_lyr: str) bool
Function to test whether the comparison vector layer intersects with the base vector layer.
Note. This function iterates through the geometries of both files performing a comparison and therefore can be very slow to execute for large vector files.
- Parameters:
vec_base_file – vector layer file used as the base layer
vec_base_lyr – vector layer used as the base layer
vec_comp_file – vector layer file used as the comparison layer
vec_comp_lyr – vector layer used as the comparison layer
- Returns:
boolean
- rsgislib.vectorgeoms.vec_overlaps_vec(vec_base_file: str, vec_base_lyr: str, vec_comp_file: str, vec_comp_lyr: str) bool
Function to test whether the comparison vector layer overlaps with the base vector layer.
Note. This function iterates through the geometries of both files performing a comparison and therefore can be very slow to execute for large vector files.
- Parameters:
vec_base_file – vector layer file used as the base layer
vec_base_lyr – vector layer used as the base layer
vec_comp_file – vector layer file used as the comparison layer
vec_comp_lyr – vector layer used as the comparison layer
- Returns:
boolean
- rsgislib.vectorgeoms.vec_within_vec(vec_base_file: str, vec_base_lyr: str, vec_comp_file: str, vec_comp_lyr: str) bool
Function to test whether the comparison vector layer within with the base vector layer.
Note. This function iterates through the geometries of both files performing a comparison and therefore can be very slow to execute for large vector files.
- Parameters:
vec_base_file – vector layer file used as the base layer
vec_base_lyr – vector layer used as the base layer
vec_comp_file – vector layer file used as the comparison layer
vec_comp_lyr – vector layer used as the comparison layer
- Returns:
boolean
- rsgislib.vectorgeoms.vec_contains_vec(vec_base_file: str, vec_base_lyr: str, vec_comp_file: str, vec_comp_lyr: str) bool
Function to test whether the base vector layer contains with the comparison vector layer.
Note. This function iterates through the geometries of both files performing a comparison and therefore can be very slow to execute for large vector files.
- Parameters:
vec_base_file – vector layer file used as the base layer
vec_base_lyr – vector layer used as the base layer
vec_comp_file – vector layer file used as the comparison layer
vec_comp_lyr – vector layer used as the comparison layer
- Returns:
boolean
- rsgislib.vectorgeoms.vec_touches_vec(vec_base_file: str, vec_base_lyr: str, vec_comp_file: str, vec_comp_lyr: str) bool
Function to test whether the comparison vector layer touches the base vector layer.
Note. This function iterates through the geometries of both files performing a comparison and therefore can be very slow to execute for large vector files.
- Parameters:
vec_base_file – vector layer file used as the base layer
vec_base_lyr – vector layer used as the base layer
vec_comp_file – vector layer file used as the comparison layer
vec_comp_lyr – vector layer used as the comparison layer
- Returns:
boolean
- rsgislib.vectorgeoms.vec_crosses_vec(vec_base_file: str, vec_base_lyr: str, vec_comp_file: str, vec_comp_lyr: str) bool
Function to test whether the comparison vector layer touches the base vector layer.
Note. This function iterates through the geometries of both files performing a comparison and therefore can be very slow to execute for large vector files.
- Parameters:
vec_base_file – vector layer file used as the base layer
vec_base_lyr – vector layer used as the base layer
vec_comp_file – vector layer file used as the comparison layer
vec_comp_lyr – vector layer used as the comparison layer
- Returns:
boolean
Spatial Index
- rsgislib.vectorgeoms.create_rtree_index(vec_file: str, vec_lyr: str)
A function which creates a spatial index using the rtree package for the inputted vector file/layer.
- Parameters:
vec_file – Input vector file to be processed.
vec_lyr – The layer within the vector file for which the index is to be built.
- rsgislib.vectorgeoms.bbox_intersects_index(rt_idx, geom_lst: List, bbox: Tuple[float, float, float, float] | List[float]) bool
A function which tests for intersection between the geometries and the bounding box using a spatial index.
- Parameters:
rt_idx – the rtree spatial index object (created using the create_rtree_index function)
geom_lst – the list of geometries as referenced in the index (created using the create_rtree_index function)
bbox – the bounding box (xMin, xMax, yMin, yMax). Same projection as geometries in the index.
- Returns:
True there is an intersection. False there is not an intersection.
Internal Utilities
- rsgislib.vectorgeoms.get_pt_on_line(pt1: ~osgeo.ogr.Geometry, pt2: ~osgeo.ogr.Geometry, dist: float) -> (<class 'float'>, <class 'float'>)
A function that calculates a point on the vector defined by pt1 and pt2.
- Parameters:
pt1 – An ogr point geometry which has functions GetX() and GetY().
pt2 – An ogr point geometry which has functions GetX() and GetY().
dist – The distance from pt1 the new point is to be created.
- Returns:
The created point; returned as a set of floats: (x, y)
- rsgislib.vectorgeoms.find_pt_to_side(pt_start: ~osgeo.ogr.Geometry, pt: ~osgeo.ogr.Geometry, pt_end: ~osgeo.ogr.Geometry, line_len: float, left_hand: bool = False) -> (<class 'float'>, <class 'float'>)
A function to calculate a point location at a right-angle to the vector defined by the points pt_start and pt_end at the location pt.
- Parameters:
pt_start – An ogr point geometry which has functions GetX(), GetY() and Distance().
pt – An ogr point geometry which has functions GetX(), GetY() and Distance().
pt_end – An ogr point geometry which has functions GetX(), GetY() and Distance().
line_len – The distance from the pt_start and pt_end vector to the new point.
left_hand – Specify which side the point is projected from the pt_start and pt_end vector. Default: False - project right-hand side of vector, True - project left-hand side of vector
- Returns:
The created point; returned as a set of floats: (x, y)
- rsgislib.vectorgeoms.create_orthg_lines(vec_in_file: str, vec_in_lyr: str, out_vec_file: str, out_vec_lyr: str = None, pt_step: float = 1000, line_len: float = 10000, left_hand: bool = False, out_format: str = 'GPKG', del_exist_vec: bool = False)
A function to create a set of lines which are orthogonal to the lines of the input vector file.
- Parameters:
vec_in_file – The inputted vector file path - this should be a polyline vector file
vec_in_lyr – The name of the vector layer
out_vec_file – The output vector file path - this will be a polyline vector file
out_vec_lyr – The name of the output vector layer (if None then created as the same as the file name)
pt_step – The steps (in the unit of the coordinate system) along lines in the layer at which lines are created.
line_len – The length of the lines created.
left_hand – Specify which side the point is projected from the line (i.e., left or right side) Default: False - project right-hand side of vector, True - project left-hand side of vector
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.closest_line_intersection(vec_line_file: str, vec_line_lyr: str, vec_objs_file: str, vec_objs_lyr: str, out_vec_file: str, out_vec_lyr: str = None, start_x_field: str = 'start_x', start_y_field: str = 'start_y', uid_field: str = 'uid', out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which intersects each line within the input vector layer (vec_objs_file, vec_objs_lyr) creating a new line between the start point of the input layer (defined in the vector attribute table: start_x_field, start_y_field) and the intersection point which is closest to the start point.
- Parameters:
vec_line_file – Input lines vector file path.
vec_line_lyr – Input lines vector layer name.
vec_objs_file – The vector file for the objects (expecting polygons) to be intersected with.
vec_objs_lyr – The vector layer for the objects (expecting polygons) to be intersected with.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name
start_x_field – The field name for the start point X coordinate for the input lines.
start_y_field – The field name for the start point Y coordinate for the input lines.
uid_field – The field name for the Unique ID (UID) of the input lines.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.line_intersection_range(vec_line_file: str, vec_line_lyr: str, vec_objs_file: str, vec_objs_lyr: str, out_vec_file: str, out_vec_lyr: str = None, start_x_field: str = 'start_x', start_y_field: str = 'start_y', uid_field: str = 'uid', out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which intersects each line within the input vector layer (vec_objs_file, vec_objs_lyr) creating a new line between the closest intersection to the start point of the input layer (defined in the vector attribute table: start_x_field, start_y_field) and the intersection point which is furthest to the start point.
- Parameters:
vec_line_file – Input lines vector file path.
vec_line_lyr – Input lines vector layer name.
vec_objs_file – The vector file for the objects (expecting polygons) to be intersected with.
vec_objs_lyr – The vector layer for the objects (expecting polygons) to be intersected with.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name
start_x_field – The field name for the start point X coordinate for the input lines.
start_y_field – The field name for the start point Y coordinate for the input lines.
uid_field – The field name for the Unique ID (UID) of the input lines.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
- rsgislib.vectorgeoms.scnd_line_intersection_range(vec_line_file: str, vec_line_lyr: str, vec_objs_file: str, vec_objs_lyr: str, out_vec_file: str, out_vec_lyr: str = None, start_x_field: str = 'start_x', start_y_field: str = 'start_y', uid_field: str = 'uid', out_format: str = 'GPKG', del_exist_vec: bool = False)
A function which intersects a line with a set of polygons outputting the lines cut to their second point of intersection. Assume, first point of intersection would be entering the polygon and the second point of intersection would be leaving the polygon.
- Parameters:
vec_line_file – Input lines vector file path.
vec_line_lyr – Input lines vector layer name.
vec_objs_file – The vector file for the objects (expecting polygons) to be intersected with.
vec_objs_lyr – The vector layer for the objects (expecting polygons) to be intersected with.
out_vec_file – The output vector file path.
out_vec_lyr – The output vector layer name
start_x_field – The field name for the start point X coordinate for the input lines.
start_y_field – The field name for the start point Y coordinate for the input lines.
uid_field – The field name for the Unique ID (UID) of the input lines.
out_format – The output file format of the vector file.
del_exist_vec – remove output file if it exists.
Calculate Geometry Info
- rsgislib.vectorgeoms.get_poly_hole_area(vec_file: str, vec_lyr: str)
Get an array of the areas of the polygon holes.
- Parameters:
vec_file – input vector file
vec_lyr – input vector layer within the input file.
- Returns:
A list of areas.