### Install Development Dependencies Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Clone the repository and install the project in development mode with all necessary dependencies for development, linting, and testing. ```bash $ git clone git@github.com:fitodic/centerline.git $ pip install -e .[dev,gdal,lint,test,docs] ``` -------------------------------- ### Show tox Installation Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Verify that tox, a key tool for development tasks, is successfully installed by checking its package information. ```bash $ pip show tox Name: tox Version: 3.12.1 Summary: tox is a generic virtualenv management and test command line tool Home-page: http://tox.readthedocs.org Author: Holger Krekel, Oliver Bestwalter, Bernát Gábor and others Author-email: None License: MIT Location: /home/username/.virtualenvs/centerline/lib/python3.7/site-packages Requires: py, filelock, virtualenv, setuptools, six, pluggy, toml Required-by: ``` -------------------------------- ### Install centerline from PyPI Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/installation.rst.txt Install the centerline package using pip. This is the standard method for installing the library. ```bash $ pip install centerline ``` -------------------------------- ### Install GDAL on Fedora Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/installation.rst.txt Use this command to install GDAL and development tools on Fedora systems. ```bash $ sudo dnf install gdal gdal-devel gcc-c++ redhat-rpm-config ``` -------------------------------- ### Install GDAL and Development Tools on Fedora Source: https://centerline.readthedocs.io/en/latest/chapters/installation.html Use this command to install GDAL, its development headers, and C++ compiler tools on Fedora systems. ```bash $ sudo dnf install gdal gdal-devel gcc-c++ redhat-rpm-config ``` -------------------------------- ### Install python-GDAL in Virtual Environment Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/installation.rst.txt Install a specific version of the python-GDAL package within your activated virtual environment. Ensure the version closely matches your system-wide GDAL installation. ```bash # Activate your virtual environment $ pip install GDAL==2.1.3 ``` -------------------------------- ### Install centerline in Develop Mode Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/installation.rst.txt Install the centerline library in editable/develop mode with all necessary development dependencies. This allows for code changes to be reflected immediately. ```bash $ pip install -e .[dev,gdal,lint,test,docs] ``` -------------------------------- ### Get OGR Driver by File Extension Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/converters.html Determines the appropriate OGR driver based on a file's extension. Raises an UnsupportedVectorType error if the extension is not recognized. ```python def get_ogr_driver(filepath): """Get the OGR driver based on the file's extension. :param filepath: file's path :type filepath: str :raises UnsupportedVectorType: unsupported extension :return: OGR driver :rtype: osgeo.ogr.Driver """ filename, file_extension = os.path.splitext(filepath) extension = file_extension[1:] ogr_driver_count = ogr.GetDriverCount() for idx in range(ogr_driver_count): driver = ogr.GetDriver(idx) driver_extension = driver.GetMetadataItem(str("DMD_EXTENSION")) or "" driver_extensions = driver.GetMetadataItem(str("DMD_EXTENSIONS")) or "" if extension == driver_extension or extension in driver_extensions: return driver raise UnsupportedVectorType ``` -------------------------------- ### Set GDAL Include Paths Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/installation.rst.txt Export the CPLUS_INCLUDE_PATH and C_INCLUDE_PATH environment variables to point to GDAL headers. This is necessary before installing the python-GDAL binding. ```bash $ export CPLUS_INCLUDE_PATH=/usr/include/gdal/ $ export C_INCLUDE_PATH=/usr/include/gdal/ ``` -------------------------------- ### Install centerline with GDAL extra Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/installation.rst.txt Install centerline along with GDAL support by specifying the 'gdal' extra dependency. Be cautious as pip may automatically select a GDAL version that doesn't match your system. ```bash $ pip install centerline[gdal] ``` -------------------------------- ### Unsupported Vector Type Exception Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/exceptions.html Raised when no OGR driver is found for the provided vector file. Verify that the file format is supported and that the necessary OGR drivers are installed. ```python [docs] class UnsupportedVectorType(CenterlineError): default_message = "No OGR driver was found for the provided file." ``` -------------------------------- ### Get Voronoi Vertices and Ridges Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Calculates the Voronoi diagram for the densified borders of the input geometry and returns the vertices and ridges of the diagram. ```python def _get_voronoi_vertices_and_ridges(self): borders = self._get_densified_borders() voronoi_diagram = Voronoi(borders) vertices = voronoi_diagram.vertices ridges = voronoi_diagram.ridge_vertices return vertices, ridges ``` -------------------------------- ### Get Interpolated Boundary Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Creates a LineString from a boundary and interpolates points along it based on the `interpolation_distance`. ```python def _get_interpolated_boundary(self, boundary): line = LineString(boundary) ``` -------------------------------- ### Getting First Point Coordinates Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Retrieves the coordinates of the first point of a linestring. Assumes the linestring object has an 'xy' attribute containing coordinate arrays. ```python def _get_coordinates_of_first_point(self, linestring): return self._create_point_with_reduced_coordinates( x=linestring.xy[0][0], y=linestring.xy[1][0] ) ``` -------------------------------- ### Get Densified Borders Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Extracts polygons, interpolates their boundaries (including interior rings), and returns the points as a NumPy array. This prepares the geometry for Voronoi diagram calculation. ```python def _get_densified_borders(self): polygons = self._extract_polygons_from_input_geometry() points = [] for polygon in polygons: points += self._get_interpolated_boundary(polygon.exterior) if self._polygon_has_interior_rings(polygon): for interior in polygon.interiors: points += self._get_interpolated_boundary(interior) return array(points) ``` -------------------------------- ### Getting Last Point Coordinates Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Retrieves the coordinates of the last point of a linestring. Assumes the linestring object has an 'xy' attribute containing coordinate arrays. ```python def _get_coordinates_of_last_point(self, linestring): return self._create_point_with_reduced_coordinates( x=linestring.xy[0][-1], y=linestring.xy[1][-1] ) ``` -------------------------------- ### Extracting Line Coordinates Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html This method retrieves the first, last, and interpolated points of a line segment. It relies on helper methods to get individual point coordinates and perform interpolation. ```python first_point = self._get_coordinates_of_first_point(line) last_point = self._get_coordinates_of_last_point(line) intermediate_points = self._get_coordinates_of_interpolated_points( line ) return [first_point] + intermediate_points + [last_point] ``` -------------------------------- ### Build Documentation Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Generate the project's documentation using tox. This command is also used by Read the Docs. ```bash $ tox -e docs ``` -------------------------------- ### Run Test Suite Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Execute the project's test suite using tox to ensure code quality and functionality. ```bash $ tox ``` -------------------------------- ### Release New Version Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Initiate the release process for a new version of the project using tox. This includes merging changelogs, bumping the version, committing, tagging, and pushing. ```bash $ tox -e release ``` -------------------------------- ### Run Specific Test Environment Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Run the test suite for a specific Python version and GDAL version combination using tox. ```bash $ tox -e py37-gdal2.3.3 ``` -------------------------------- ### Render Changelog Draft Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Preview the changelog in the terminal without making any modifications, useful for verifying changelog entries before building the final version. ```bash $ tox -e changelog -- --draft ``` -------------------------------- ### Release Patch Version Source: https://centerline.readthedocs.io/en/latest/chapters/contributing.html Create a patch release for the project by specifying 'patch' as an argument to the tox release environment. ```bash $ tox -e release -- patch ``` -------------------------------- ### Instantiate Centerline Class in Python Source: https://centerline.readthedocs.io/en/latest/chapters/usage.html Import and use the `Centerline` class directly in Python. Instantiate it with a shapely Polygon or MultiPolygon and optional attributes. ```python from shapely.geometry import Polygon from centerline.geometry import Centerline polygon = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) attributes = {"id": 1, "name": "polygon", "valid": True} centerline = Centerline(polygon, **attributes) centerline.id == 1 centerline.name centerline.geometry.geoms ``` -------------------------------- ### Create Centerlines using CLI Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/usage.rst.txt Use the `create_centerlines` command-line script to convert input vector files to output vector files. Supports all OGR vector formats. ```bash $ create_centerlines input.shp output.geojson ``` -------------------------------- ### Instantiate Centerline Object in Python Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/usage.rst.txt Import and use the `Centerline` class directly in Python. Instantiate it with `shapely.geometry.Polygon` or `shapely.geometry.MultiPolygon` and optional attributes. ```python from shapely.geometry import Polygon from centerline.geometry import Centerline polygon = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) attributes = {"id": 1, "name": "polygon", "valid": True} centerline = Centerline(polygon, **attributes) centerline.id == 1 centerline.name centerline.geometry.geoms ``` -------------------------------- ### Create Point with Restored Coordinates Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Creates a point using provided x and y coordinates, restoring them by adding the minimum x and y values of the input geometry. ```python def _create_point_with_restored_coordinates(self, x, y): return (x + self._min_x, y + self._min_y) ``` -------------------------------- ### Specify Border Density in Degrees Source: https://centerline.readthedocs.io/en/latest/chapters/faq.html Use this command when your input data is in a geographic coordinate system (like EPSG:4326) and you need to specify the border density in degrees instead of meters. ```bash create_centerlines input.shp output.geojson 0.00001 ``` -------------------------------- ### Centerline Class Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Initializes a Centerline object, processing input geometry to create a centerline. It densifies the input geometry's border and uses Voronoi diagrams to construct the centerline. Attributes from the input geometry can be passed and will be assigned to the Centerline instance. ```APIDOC ## class Centerline ### Description Creates a centerline object from input geometry, densifying its border and constructing the centerline using Voronoi diagrams. Attributes from the input geometry are copied and set as the centerline's attributes. ### Parameters * **input_geometry** (:py:class:`shapely.geometry.Polygon` or :py:class:`shapely.geometry.MultiPolygon`) - The input geometry from which to create the centerline. * **interpolation_distance** (float, optional) - Densifies the input geometry's border by placing additional points at this distance. Defaults to 0.5 meters. * **attributes** (dict) - Additional attributes to assign to the centerline instance. ### Raises * exceptions.InvalidInputTypeError - If the input geometry is not a :py:class:`shapely.geometry.Polygon` or :py:class:`shapely.geometry.MultiPolygon`. ``` -------------------------------- ### Create Centerlines via Command-Line Source: https://centerline.readthedocs.io/en/latest/chapters/usage.html Use the `create_centerlines` script to generate centerlines from a source vector file and save them to a destination vector file. Supports all OGR vector file formats. ```bash $ create_centerlines input.shp output.geojson ``` -------------------------------- ### Clone centerline Repository Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/installation.rst.txt Clone the centerline repository from GitHub to contribute to the library. This is the first step for development. ```bash $ git clone git@github.com:user/centerline.git ``` -------------------------------- ### Initialize Centerline Object Source: https://centerline.readthedocs.io/en/latest/_sources/index.rst.txt Instantiate the Centerline class with a Shapely Polygon and attributes. The attributes are accessible as object properties. ```python from shapely.geometry import Polygon from centerline.geometry import Centerline polygon = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) attributes = {"id": 1, "name": "polygon", "valid": True} centerline = Centerline(polygon, **attributes) centerline.id == 1 centerline.name centerline.geoms ``` -------------------------------- ### Specify Border Density in Degrees Source: https://centerline.readthedocs.io/en/latest/_sources/chapters/faq.rst.txt Use this command when your input data is in degrees (e.g., EPSG:4326) to resolve Qhull input errors caused by unit mismatches. Adjust the border density value as needed. ```bash $ create_centerlines input.shp output.geojson 0.00001 ``` -------------------------------- ### Construct Centerline Geometry Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Constructs the centerline geometry by calculating Voronoi vertices and ridges, filtering finite ridges, creating LineString objects, and selecting those contained within the input geometry. ```python def _construct_centerline(self): vertices, ridges = self._get_voronoi_vertices_and_ridges() linestrings = [] for ridge in ridges: if self._ridge_is_finite(ridge): starting_point = self._create_point_with_restored_coordinates( x=vertices[ridge[0]][0], y=vertices[ridge[0]][1] ) ending_point = self._create_point_with_restored_coordinates( x=vertices[ridge[1]][0], y=vertices[ridge[1]][1] ) linestring = LineString((starting_point, ending_point)) linestrings.append(linestring) str_tree = STRtree(linestrings) linestrings_indexes = str_tree.query( self._input_geometry, predicate="contains" ) contained_linestrings = [linestrings[i] for i in linestrings_indexes] if len(contained_linestrings) < 2: raise exceptions.TooFewRidgesError return unary_union(contained_linestrings) ``` -------------------------------- ### Creating Point with Reduced Coordinates Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Creates a point tuple by subtracting minimum x and y values from the given coordinates. This is used for coordinate reduction or normalization. ```python def _create_point_with_reduced_coordinates(self, x, y): return (x - self._min_x, y - self._min_y) ``` -------------------------------- ### Initialize Centerline Object Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Creates a Centerline object from a shapely Polygon or MultiPolygon. Optionally densifies the geometry's border by specifying an interpolation distance. ```python class centerline.geometry.Centerline(_input_geometry_ , _interpolation_distance =0.5_, _** attributes_) Bases: object Create a centerline object. The `attributes` are copied and set as the centerline’s attributes. Parameters: * **input_geometry** (`shapely.geometry.Polygon` or `shapely.geometry.MultiPolygon`) – input geometry * **interpolation_distance** (_float_ _,__optional_) – densify the input geometry’s border by placing additional points at this distance, defaults to 0.5 [meter] Raises: **exceptions.InvalidInputTypeError** – input geometry is not of type `shapely.geometry.Polygon` or `shapely.geometry.MultiPolygon` ``` -------------------------------- ### Integrate Centerline Class in Python Source: https://centerline.readthedocs.io/en/latest/index.html Instantiate the `Centerline` class with a Shapely Polygon and optional attributes to calculate its centerline. Access calculated attributes and geometries through the instance. ```python from shapely.geometry import Polygon from centerline.geometry import Centerline polygon = Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]) attributes = {"id": 1, "name": "polygon", "valid": True} centerline = Centerline(polygon, **attributes) centerline.id == 1 centerline.name centerline.geoms ``` -------------------------------- ### Initialize Centerline Object Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Initializes a Centerline object with input geometry and an optional interpolation distance. It validates the input geometry and constructs the centerline. ```python class Centerline: """Create a centerline object. The ``attributes`` are copied and set as the centerline's attributes. :param input_geometry: input geometry :type input_geometry: :py:class:`shapely.geometry.Polygon` or :py:class:`shapely.geometry.MultiPolygon` :param interpolation_distance: densify the input geometry's border by placing additional points at this distance, defaults to 0.5 [meter] :type interpolation_distance: float, optional :raises exceptions.InvalidInputTypeError: input geometry is not of type :py:class:`shapely.geometry.Polygon` or :py:class:`shapely.geometry.MultiPolygon` """ def __init__( self, input_geometry, interpolation_distance=0.5, **attributes ): self._input_geometry = input_geometry self._interpolation_distance = abs(interpolation_distance) if not self.input_geometry_is_valid(): raise exceptions.InvalidInputTypeError self._min_x, self._min_y = self._get_reduced_coordinates() self.assign_attributes_to_instance(attributes) self.geometry = MultiLineString(lines=self._construct_centerline()) ``` -------------------------------- ### UnsupportedVectorTypeError Exception Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Raised when no OGR driver can be found for the specified vector file type. ```python exception centerline.exceptions.UnsupportedVectorType(_* args_, _** kwargs_) Bases: CenterlineError default_message = 'No OGR driver was found for the provided file.' ``` -------------------------------- ### Geometry Converters Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Provides utility functions for handling geometry file types. ```APIDOC ## `centerline.converters.get_ogr_driver` ### Description Get the OGR driver based on the file’s extension. ### Parameters #### Path Parameters - **filepath** (str) - The path to the file. ### Raises - **`UnsupportedVectorType`** - If an unsupported file extension is provided. ### Returns - OGR driver object. ``` -------------------------------- ### Create Centerlines from Vector Data Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/converters.html Converts geometries from a source vector file to centerlines in a destination file. Adjusts detail level with interpolation distance and skips non-polygon geometries. Logs warnings for potential issues with polygon geometry and interpolation distance. ```python # -*- coding: utf-8 -*- from __future__ import unicode_literals import logging import os import click import fiona from osgeo import gdal, ogr from shapely.geometry import mapping, shape from .exceptions import ( InvalidInputTypeError, TooFewRidgesError, UnsupportedVectorType, ) from .geometry import Centerline # Enable GDAL/OGR exceptions gdal.UseExceptions() @click.command() @click.argument("src", nargs=1, type=click.Path(exists=True)) @click.argument("dst", nargs=1, type=click.Path(exists=False)) @click.option( "--interpolation-distance", default=0.5, show_default=True, help=( "Densify the input geometry's border by placing additional " "points at this distance" ), ) def create_centerlines(src, dst, interpolation_distance=0.5): """Convert the geometries from the ``src`` file to centerlines in the ``dst`` file. Use the ``interpolation_distance`` parameter to adjust the level of detail you want the centerlines to be produced with. Only polygons and multipolygons are converted to centerlines, whereas the other geometries are skipped. The polygon's attributes are copied to its ``Centerline`` object. If the ``interpolation_distance`` factor does not suit the polygon's geometry, the ``TooFewRidgesError`` error is logged as a warning. You should try readjusting the ``interpolation_distance`` factor and rerun the command. :param src: path to the file containing input geometries :type src: str :param dst: path to the file that will contain the centerlines :type dst: str :param interpolation_distance: densify the input geometry's border by placing additional points at this distance, defaults to 0.5 [meter]. :type interpolation_distance: float, optional :return: ``dst`` file is generated :rtype: None """ with fiona.Env(): with fiona.open(src, mode="r") as source_file: schema = source_file.schema.copy() schema.update({"geometry": "MultiLineString"}) driver = get_ogr_driver(filepath=dst) with fiona.open( dst, mode="w", driver=driver.GetName(), schema=schema, crs=source_file.crs, encoding=source_file.encoding, ) as destination_file: for record in source_file: geom = record.get("geometry") input_geom = shape(geom) attributes = record.get("properties") try: centerline_obj = Centerline( input_geom, interpolation_distance, **attributes ) except (InvalidInputTypeError, TooFewRidgesError) as error: logging.warning(error) continue centerline_dict = { "geometry": mapping(centerline_obj.geometry), "properties": { k: v for k, v in centerline_obj.__dict__.items() if k in attributes.keys() }, } destination_file.write(centerline_dict) return None ``` -------------------------------- ### Too Few Ridges Exception Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/exceptions.html Raised when the number of generated ridges is insufficient. This typically indicates that the interpolation distance needs adjustment. ```python [docs] class TooFewRidgesError(CenterlineError): default_message = ( "Number of produced ridges is too small. Please adjust your " "interpolation distance." ) ``` -------------------------------- ### Centerline Exceptions Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Details custom exceptions used within the Centerline library for error handling. ```APIDOC ## Exceptions ### `CenterlineError` **Description**: Base exception for all errors in the Centerline library. ### `InvalidInputTypeError` **Description**: Raised when the input geometry is not a valid Polygon or MultiPolygon. **Inherits from**: `CenterlineError` ### `TooFewRidgesError` **Description**: Raised when the number of produced ridges is too small, suggesting adjustments to the interpolation distance. **Inherits from**: `CenterlineError` ### `UnsupportedVectorType` **Description**: Raised when no OGR driver is found for the provided file. **Inherits from**: `CenterlineError` ``` -------------------------------- ### Assign Attributes to Instance Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Assigns provided attributes to the Centerline object instance. This allows for custom metadata to be associated with the centerline. ```python def assign_attributes_to_instance(self, attributes): """Assign the ``attributes`` to the :py:class:`Centerline` object. :param attributes: polygon's attributes :type attributes: dict """ for key in attributes: setattr(self, key, attributes.get(key)) ``` -------------------------------- ### Extract Polygons from Input Geometry Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Extracts individual polygons from the input geometry, whether it's a single Polygon or a MultiPolygon. ```python def _extract_polygons_from_input_geometry(self): if isinstance(self._input_geometry, MultiPolygon): return (polygon for polygon in self._input_geometry.geoms) else: return (self._input_geometry,) ``` -------------------------------- ### assign_attributes_to_instance Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Assigns provided attributes to the Centerline object instance. ```APIDOC ## method assign_attributes_to_instance(attributes) ### Description Assigns key-value pairs from the `attributes` dictionary as attributes to the Centerline object. ### Parameters * **attributes** (dict) - A dictionary containing attributes to be assigned to the instance. ``` -------------------------------- ### TooFewRidgesError Exception Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Raised when the centerline calculation produces too few ridges, suggesting the need to adjust the interpolation distance. ```python exception centerline.exceptions.TooFewRidgesError(_* args_, _** kwargs_) Bases: CenterlineError default_message = 'Number of produced ridges is too small. Please adjust your interpolation distance.' ``` -------------------------------- ### Interpolating Intermediate Points Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Generates a list of intermediate points along a linestring at a specified interpolation distance. Points are added until the interpolation distance exceeds the line length. ```python def _get_coordinates_of_interpolated_points(self, linestring): intermediate_points = [] interpolation_distance = self._interpolation_distance line_length = linestring.length while interpolation_distance < line_length: point = linestring.interpolate(interpolation_distance) reduced_point = self._create_point_with_reduced_coordinates( x=point.x, y=point.y ) intermediate_points.append(reduced_point) interpolation_distance += self._interpolation_distance return intermediate_points ``` -------------------------------- ### Base Exception for Centerline Errors Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/exceptions.html The base exception class for all centerline-specific errors. It provides a default error message if none is supplied. ```python # -*- coding: utf-8 -*- from __future__ import unicode_literals [docs] class CenterlineError(Exception): default_message = "An error has occured while constucting the centerline." def __init__(self, *args, **kwargs): # pragma: no cover if not (args or kwargs): args = (self.default_message,) super(CenterlineError, self).__init__(*args, **kwargs) ``` -------------------------------- ### Invalid Input Type Exception Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/exceptions.html Raised when the input geometry is not a valid shapely Polygon or MultiPolygon. Ensure your input conforms to the expected geometry types. ```python [docs] class InvalidInputTypeError(CenterlineError): default_message = ( "Input geometry must be of type shapely.geometry.Polygon " "or shapely.geometry.MultiPolygon!" ) ``` -------------------------------- ### Assign Attributes to Centerline Instance Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Assigns provided attributes to an existing Centerline object. ```python assign_attributes_to_instance(_attributes_) Assign the `attributes` to the `Centerline` object. Parameters: **attributes** (_dict_) – polygon’s attributes ``` -------------------------------- ### Check for Interior Rings Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Determines if a given polygon has any interior rings (holes). ```python def _polygon_has_interior_rings(self, polygon): return len(polygon.interiors) > 0 ``` -------------------------------- ### CenterlineError Exception Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html The base exception class for all errors raised by the centerline module. Use this for general error handling. ```python exception centerline.exceptions.CenterlineError(_* args_, _** kwargs_) Bases: Exception default_message = 'An error has occured while constucting the centerline.' ``` -------------------------------- ### Check if Ridge is Finite Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Determines if a Voronoi ridge is finite by checking if it contains any infinite vertex indices (-1). ```python def _ridge_is_finite(self, ridge): return -1 not in ridge ``` -------------------------------- ### Centerline Class Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Represents and calculates the centerline of a given polygon geometry. ```APIDOC ## `centerline.geometry.Centerline` ### Description Create a centerline object. The `attributes` are copied and set as the centerline’s attributes. ### Parameters #### Path Parameters - **input_geometry** (shapely.geometry.Polygon or shapely.geometry.MultiPolygon) - The input geometry for which to calculate the centerline. - **interpolation_distance** (float, optional) - Densifies the input geometry’s border by placing additional points at this distance. Defaults to 0.5 meters. ### Raises - **`exceptions.InvalidInputTypeError`** - If the input geometry is not of type `shapely.geometry.Polygon` or `shapely.geometry.MultiPolygon`. ### Methods #### `assign_attributes_to_instance(attributes)` Assign the `attributes` to the `Centerline` object. Parameters: - **attributes** (dict) - A dictionary of polygon attributes. #### `input_geometry_is_valid()` Checks if the input geometry is a valid `shapely.geometry.Polygon` or `shapely.geometry.MultiPolygon`. Returns: - bool - True if the geometry is valid, False otherwise. ``` -------------------------------- ### Check if LineString is Within Input Geometry Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Verifies if a given LineString is entirely within the input geometry and has more than one coordinate. ```python def _linestring_is_within_input_geometry(self, linestring): return ( linestring.within(self._input_geometry) and len(linestring.coords[0]) > 1 ) ``` -------------------------------- ### Validate Input Geometry for Centerline Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Checks if the input geometry is a valid shapely Polygon or MultiPolygon, which is required for creating a Centerline object. ```python input_geometry_is_valid() Input geometry is of a `shapely.geometry.Polygon` or a `shapely.geometry.MultiPolygon`. Returns: geometry is valid Return type: bool ``` -------------------------------- ### input_geometry_is_valid Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Checks if the input geometry provided to the Centerline object is of a valid type (Polygon or MultiPolygon). ```APIDOC ## method input_geometry_is_valid() ### Description Validates if the input geometry is either a Shapely Polygon or MultiPolygon. ### Returns * **bool** - True if the geometry is valid, False otherwise. ``` -------------------------------- ### InvalidInputTypeError Exception Source: https://centerline.readthedocs.io/en/latest/modules/centerline.html Raised when the input geometry provided to the Centerline class is not a shapely Polygon or MultiPolygon. ```python exception centerline.exceptions.InvalidInputTypeError(_* args_, _** kwargs_) Bases: CenterlineError default_message = 'Input geometry must be of type shapely.geometry.Polygon or shapely.geometry.MultiPolygon!' ``` -------------------------------- ### Validate Input Geometry Type Source: https://centerline.readthedocs.io/en/latest/_modules/centerline/geometry.html Checks if the input geometry is a Shapely Polygon or MultiPolygon. This method is crucial for ensuring the correct type of geometry is provided before processing. ```python def input_geometry_is_valid(self): """Input geometry is of a :py:class:`shapely.geometry.Polygon` or a :py:class:`shapely.geometry.MultiPolygon`. :return: geometry is valid :rtype: bool """ if isinstance(self._input_geometry, Polygon) or isinstance( self._input_geometry, MultiPolygon ): return True else: return False ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.