Occupancy Map¶
- class py123d.geometry.OccupancyMap2D[source]¶
Class to represent a 2D occupancy map of shapely geometries using an str-tree for efficient spatial queries.
Public Data Attributes:
idsGetter for geometry IDs in occupancy map
geometriesGetter for geometries in occupancy map.
id_to_idxMapping from geometry IDs to indices in the occupancy map.
Public Methods:
from_dict(geometry_dict[, node_capacity])Constructs a 2D occupancy map from a dictionary of geometries.
intersects(geometry)Searches for intersecting geometries in the occupancy map.
query(geometry[, predicate, distance])Queries the str-tree for geometries that match the given predicate with the input geometry.
query_nearest(geometry[, max_distance, ...])Queries the str-tree for the nearest geometry to the input geometry.
contains_vectorized(points)Determines wether input-points are in geometries (i.e. polygons) of the occupancy map.
- classmethod from_dict(geometry_dict, node_capacity=10)[source]¶
Constructs a 2D occupancy map from a dictionary of geometries.
- property geometries: Sequence[BaseGeometry]¶
Getter for geometries in occupancy map.
- Returns:
list of geometries
- property id_to_idx: Dict[int | str, int]¶
Mapping from geometry IDs to indices in the occupancy map.
- Returns:
dictionary of IDs and indices
- query(geometry, predicate=None, distance=None)[source]¶
Queries the str-tree for geometries that match the given predicate with the input geometry.
- Parameters:
geometry (
Union[BaseGeometry,ndarray]) – Geometry or array_likepredicate (
Optional[Literal['intersects','within','dwithin','contains','overlaps','crosses','touches','covers','covered_by']]) – {None, ‘intersects’, ‘within’, ‘contains’, ‘overlaps’, ‘crosses’, ‘touches’, ‘covers’, ‘covered_by’, ‘contains_properly’, ‘dwithin’}, defaults to Nonedistance (
Optional[float]) – number or array_like, defaults to None.
- Return type:
- Returns:
ndarray with shape (n,) if geometry is a scalar. Contains tree geometry indices.
- Returns:
ndarray with shape (2, n) if geometry is an array_like The first subarray contains input geometry indices. The second subarray contains tree geometry indices.
- query_nearest(geometry, max_distance=None, return_distance=False, exclusive=False, all_matches=True)[source]¶
Queries the str-tree for the nearest geometry to the input geometry.
- Parameters:
geometry (
Union[BaseGeometry,ndarray]) – The input geometry to query.max_distance (
Optional[float]) – The maximum distance to consider, defaults to None.return_distance (
bool) – Whether to return the distance to the nearest geometry, defaults to False.exclusive (
bool) – Whether to exclude the input geometry from the results, defaults to False.all_matches (
bool) – Whether to return all matching geometries, defaults to True.
- Return type:
Union[ndarray[tuple[Any,...],dtype[int64]],Tuple[ndarray[tuple[Any,...],dtype[int64]],ndarray[tuple[Any,...],dtype[float64]]]]- Returns:
The nearest geometry or geometries.