Skip to main content

A universal tool for preparing polyline data for algorithms like RDP, by solving the arbitrary start-point problem.

Project description

py-canonicalizer: A Universal Tool for Polyline Canonicalization

- This Python package is designed to solve a common problem in computational geometry and CAD workflows: the arbitrary start-point and direction of polylines. It provides a robust, universal algorithm to standardize 3D point lists, making them predictable and ready for further processing by algorithms like the Ramer-Douglas-Peucker (RDP) algorithm.
- This ensures that your algorithmic results are consistent every time, regardless of the original data's orientation.
  • Features

    • Application-Agnostic: Works with any Python environment, with no dependencies on specific CAD or GIS software.
    • Rule-Based Standardization: Uses a clear, hierarchical set of rules (based on centroid proximity and coordinate values) to define a canonical starting point and direction.
    • Data Cleaning: Automatically handles duplicate points in closed polylines to prevent calculation errors.
  • Installation

    • You can install the package directly from PyPI using pip:
    • pip install py-canonicalizer
      
  • Usage

    • The core function canonicalize_points takes a NumPy array and returns a new, ordered array.
    • import numpy as np
      from py_canonicalizer import canonicalize_points
      
      # Example: a simple closed polyline with an arbitrary start point
      original_points = np.array([[1, 1, 0], [2, 3, 0], [5, 4, 0], [4, 1, 0], [1, 1, 0]])
      
      # Get the canonicalized version
      canonical_points = canonicalize_points(original_points)
      
      print(canonical_points)
      # Output will always be consistently ordered regardless of the input's original orientation.
      
  • How It Works

    • The algorithm is based on a set of rules and a hierarchical tie-breaker system to ensure a single, repeatable result for any given point cloud.
    • Data Cleaning: The algorithm first removes duplicate points, which often appear at the end of closed polylines.
    • Canonical Start Point: It finds the point closest to the geometric center (centroid) of the polyline.
    • Hierarchical Tie-breaker: If multiple points are equally close, it uses a predictable rule (max X, then max Y, then max Z) to select the starting point.
    • Direction: It then compares the neighbors of the start point using the same tie-breaker rule to determine the polyline's final, standardized direction (e.g., clockwise vs. counter-clockwise).
  • License

    • This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_canonicalizer-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_canonicalizer-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file py_canonicalizer-0.1.0.tar.gz.

File metadata

  • Download URL: py_canonicalizer-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for py_canonicalizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 803ada8a3a5b589775d82c3b6fcbaf7a4ecfb95bba70a39ce170d9d5f11371b4
MD5 6ab06d70c81a240b970a83678c06e058
BLAKE2b-256 8d88818ac34a2da053b458b113c93a96b7d7f56f39d2ef2e1fda9eb278c9c08f

See more details on using hashes here.

File details

Details for the file py_canonicalizer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_canonicalizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c897074dfa322e44e07b603573b689a0a6c569fff51ac6397240d37d162e18ff
MD5 172b85165ac97f02ffc61eb1760120ea
BLAKE2b-256 ec7d216d5af7800068fcda24b4795250f64e650cb48d0d8c456ee2a03d3eeab2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page