A Python library for efficient ray tracing operations on COPC (Cloud Optimized Point Cloud) files.
pymeepcl manages multiple COPC files for efficient spatial queries using ray tracing. It also maintains a cache of loaded point data to speed up subsequent queries. This module makes use of the python bindings of the copc-lib library.
Manages multiple COPC files for efficient ray tracing operations. Provides a unified interface to work with one or more COPC files, enabling efficient spatial queries using ray tracing.
Key Attributes:
cache: Cache for storing loaded node point data to reduce disk readsfiles: List of MeeFile objects representing the loaded COPC filesbounds_copc: Combined global COPC bounding box of all files (tuple of minimums, maximums)bounds_las: Combined global LAS bounding box of all files (tuple of minimums, maximums)
Key Methods:
trace_ray(ray, radius, return_sorted, timer, recursive): Traces a ray through all loaded files and returns points within a cylindrical radiusadd_file(filepath): Adds a new COPC file to the structuredel_file(filepath): Removes a file from the structure and clears associated cache entriesupdate_bounds(): Recalculates the combined global bounds of all loaded files
Represents a single COPC file. Handles reading, indexing, and bounding box logic.
Key Attributes:
filepath: The path to the COPC filereader: The reader object for the COPC fileconfig: The configuration object for the COPC filelas_header: The header object for the LAS filenode_entries: List of all nodes in the fileis_indexed: True if the file has been indexed for vectorized intersection testsis_octree_indexed: True if the file has been indexed with octree structurebounds_copc_min,bounds_copc_max: Global COPC bounds of the filebounds_las_min,bounds_las_max: Global LAS bounds of the file
Key Methods:
intersect_global(ray, radius): Checks if ray hits the root boxintersect_nodes(ray, radius): Returns nodes intersected by ray, vectorized intersection testintersect_nodes_octree(ray, radius): Returns nodes intersected by ray, recursively traverses the file, if a parent node isn't hit the children will not be checkedbuild_index(): Constructs numpy arrays for vectorized intersection testsbuild_index_octree(): Constructs octree structure for recursive traversal
Describes a ray using origin and direction. The direction vector is automatically normalized.
Key Attributes:
origin: Origin point as list or numpy array of shape (3,)direction: Direction vector as list numpy array of shape (3,)
LRU cache for storing loaded node point data to reduce disk reads. Keys are tuples of (filepath, node_key_string), values are copclib.PointData objects.
Key Attributes:
cache: OrderedDict storing the cached node datamax_size: Maximum number of nodes to cache (default: 100)
Container for a clustered point segment and its geometric features, including PCA/eigen features and shape descriptors (linearity, planarity, sphericity, omnivariance).
Key Attributes:
id: Segment identifierpoints: Array of shape (N, 3) containing the point coordinatescentroid: Center of mass (x, y, z)eigenvalues: Array [lambda1, lambda2, lambda3] in descending ordernormal_vector: Eigenvector of smallest eigenvaluelinearity: Shape descriptor (lam1 - lam2) / lam1planarity: Shape descriptor (lam2 - lam3) / lam1sphericity: Shape descriptor lam3 / lam1omnivariance: Shape descriptor (lam1 * lam2 * lam3)^(1/3)equation: Plane equation coefficients inequationattribute (a, b, c, d for ax + by + cz + d = 0)
Clusters points based on 1D distance along the ray and calculates geometric features for each cluster. This method is being replaced by cluster_and_analyze_ransac which provides more robust plane fitting.
Iteratively fits planes to point clouds using RANSAC (Random Sample Consensus) and returns segments with geometric features. For the RANSAC algorythm the PyRANSAC3d library is used.
Function Signature:
cluster_and_analyze_ransac(points, threshold=0.1, min_points=10, max_iterations=1000)
Parameters:
points: (N, 3) array of pointsthreshold: Maximum distance for a point to be considered an inlier (default: 0.1)min_points: Minimum points required to continue fitting planes (default: 10)max_iterations: Maximum RANSAC iterations per plane fit (default: 1000)
Returns:
- List of
Segmentobjects, each containing:- Plane equation coefficients in
equationattribute (a, b, c, d for ax + by + cz + d = 0) - Geometric features (linearity, planarity, sphericity, omnivariance)
- Points belonging to that plane
- Leftover points are returned as a segment with id=-1
- Plane equation coefficients in
from pymeepcl import MeeStruct, Ray
import numpy as np
# Initialize with a file or directory
struct = MeeStruct("path/to/file.copc.laz")
# or
struct = MeeStruct("path/to/directory/")
# Create a ray
ray = Ray(origin=[0, 0, 0], direction=[0, 0, -1])
# Trace the ray and get points within radius
points = struct.trace_ray(ray, radius=1.0, return_sorted=True)
# Cluster and analyze points
from pymeepcl import cluster_and_analyze_ransac
segments = cluster_and_analyze_ransac(points, threshold=0.1, min_points=10, max_iterations=1000)The library can also be used from the command line to trace a single ray and return the points in a specified outputfile:
python pymeepcl.py -i input.copc.laz -p 0 0 0 -d 0 0 -1 -r 1 -o output.xyzOptions:
-i, --input: Path to COPC file or directory-p, --projektionszentrum: Origin point (x, y, z)-d, --direction: Direction vector (dx, dy, dz)-r, --radius: Cylinder radius (default: 10m)-o, --output: Output file path (default: punkte.xyz)-R, --recursive: Use recursive octree traversal--no-sorted: Do not sort points by distance along the ray
- Ray tracing with cylindrical radius filtering
- Support for multiple COPC files (tiles)
- Caching mechanism for performance optimization
- Optional recursive octree traversal
- Point clustering and geometric analysis (PCA, shape descriptors)
- Vectorized intersection tests for efficient node checking
A script that generates statistics about the nodes of a COPC file or multiple files.
Usage:
python copc_stats.py -i <input_file_or_directory> [options]Options:
-i, --input: Path to one or more COPC files or a directory-o, --output: Path to the output CSV file (default: ./statistics_summary.csv)-wh, --write_histogram: Directory to save histogram images (optional)-sh, --show_histogram: Display histogram on screen (optional)