Skip to main content

Fast points-in-polygon test and distances to polygons.

Project description

image image image image image

Polygons: Fast points-in-polygon test and distances to polygons

Computes distances to polygon edges and vertices and can check whether points are inside/outside.

Installation using pip

$ pip install polygons

Supported versions

  • Python: 3.6, 3.7, 3.8, 3.9
  • Operating systems: Linux, macOS, and Windows

Capabilities

  • Check whether points are inside or outside polygons
  • Nearest distances to edges
  • Nearest distances to vertices

Recommended citation

If you use this tool in a program or publication, please acknowledge its author(s):

@misc{polygons,
  author    = {Bast, Radovan},
  title     = {Polygons: Fast points-in-polygon test and distances to polygons},
  month     = {2},
  year      = {2021},
  publisher = {Zenodo},
  version   = {v0.2.0},
  doi       = {10.5281/zenodo.3825616},
  url       = {https://doi.org/10.5281/zenodo.3825616}
}

Python example

import polygons

# polygon_points is a list of lists
# the library has been developed to perform
# with very many polygons - this is just to have a simple example
polygon_points = [
    [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)],
    [(0.0, 2.0), (1.0, 2.0), (1.0, 3.0), (0.0, 3.0), (0.0, 2.0)],
]

# the more points you compute in one go, the better
# here using two points to make a simple example but if you have many points
# then compute a thousand or a million in one go
# so that the library can parallelize over the points
points = [(0.5, 0.5), (0.5, -0.5)]

# parameters for the tree construction:
#  - each tree node has 4 children nodes
#  - each leaf collects 4 edges
# you can try different parameters and check the timing
# they (should) have no effect on the results apart from timing
num_edges_children = 4
num_nodes_children = 4
tree = polygons.build_search_tree(
    polygon_points, num_edges_children, num_nodes_children
)

inside = polygons.points_are_inside(tree, points)
print(inside)  # [True, False]

# indices are the indices of the nearest polygon vertices (counted
# consecutively)
indices, distances = polygons.distances_nearest_vertices(tree, points)
print(indices)  # [0, 0]
print(distances)  # [0.7071067811865476, 0.7071067811865476]

distances = polygons.distances_nearest_edges(tree, points)
print(distances)  # [0.5, 0.5]

indices, distances = polygons.distances_nearest_vertices(
    tree, [(0.6, 0.6), (0.5, -0.5)]
)
print(indices)  # [2, 0]
print(distances)  # [0.5656854249492381, 0.7071067811865476]

References which were used during coding

Development notes

Running the benchmark:

$ cargo test --release -- --ignored --nocapture

Python interface inspired by https://github.com/dev-cafe/rustafarian.

Building and testing the Python interface:

$ cargo build --release --features pyo3
$ maturin develop --release --cargo-extra-args="--features pyo3"

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

polygons-0.2.1-cp39-none-win_amd64.whl (173.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

polygons-0.2.1-cp39-cp39-manylinux2010_x86_64.whl (238.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

polygons-0.2.1-cp39-cp39-macosx_10_7_x86_64.whl (219.2 kB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

polygons-0.2.1-cp38-none-win_amd64.whl (173.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

polygons-0.2.1-cp38-cp38-manylinux2010_x86_64.whl (238.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

polygons-0.2.1-cp38-cp38-macosx_10_7_x86_64.whl (219.2 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

polygons-0.2.1-cp37-none-win_amd64.whl (174.0 kB view details)

Uploaded CPython 3.7 Windows x86-64

polygons-0.2.1-cp37-cp37m-manylinux2010_x86_64.whl (238.8 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

polygons-0.2.1-cp37-cp37m-macosx_10_7_x86_64.whl (219.3 kB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

polygons-0.2.1-cp36-none-win_amd64.whl (174.1 kB view details)

Uploaded CPython 3.6 Windows x86-64

polygons-0.2.1-cp36-cp36m-manylinux2010_x86_64.whl (238.9 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

polygons-0.2.1-cp36-cp36m-macosx_10_7_x86_64.whl (219.4 kB view details)

Uploaded CPython 3.6m macOS 10.7+ x86-64

File details

Details for the file polygons-0.2.1-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 9f5df82030e5f3d6f3e6569afcdb216445a4d82886881789f2a57857288bcc9a
MD5 871d5bf0bbe26d6532e1eccba2044bb2
BLAKE2b-256 2a4d774afe9e0d896ed3fa817323feb4d5bdecad541fa2c2e58cc3dccb82acee

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 99c91e3616bca300d1c7ae81f10be5570bedd612b6b58ba310575388e573f68d
MD5 7ea282a62d7a404126ced8d92a7c1fdc
BLAKE2b-256 15e94a508f1e55d47a4db1e9252fadff47682b943e431d614352a048978637c3

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 ba32201a10b0b082b6c5bf88a2879c8d02c2b561d6475a2686261a8c8355fbe1
MD5 72b17f9d9898567dba2c690c215e9e63
BLAKE2b-256 a4728d51cba5a3d2eeaf4ddc6b6214d0d75d5a643b3da644d0af554c81d5c178

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 fcf80c7fddc50121b4e6b202cdacaf3e199ca12c0dc0da60c851de8cc1b46243
MD5 d148e5f3e92b63d582bb2ad70d308255
BLAKE2b-256 333d40a89de7269eb1b199a904a702b0e29ab200912b305ea30476e6cb62e13a

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1548d67fdb4220a79d2e6f62f158c1c324172add6793aaea76404c8d78cd0c98
MD5 198498d039696573fa52461938476df3
BLAKE2b-256 7b2cbb075ef3ea8af93128c81bbae428dab75df4fdff41e9ca90829ff6eac847

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 5bfafcaf74257300ec5076158496b81f3b06faccc052abd348a80ef40ba47721
MD5 10dc552b5441b904e5432bf0665e9fea
BLAKE2b-256 7e7e99e6ad427e3fec409ac337aa9487ba3b2b14afaba2485c71210adaddd863

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp37-none-win_amd64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 d250305396593c43571f5a4415f13f6df41bbb86635bcb6d5c6f9dcea4e0bded
MD5 da9c2f9a54fc84f8343232ebb0b714ea
BLAKE2b-256 093c965d8dfeee7b2295449704ce9719d6fe11d03151a47ad3998356c5d4d555

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 fbac4120d86ecdbb254b4733edd45c64f94a70b8797a89908cbe6cefbb844282
MD5 caa97aac5a4045cda1cd0df40fa0ff12
BLAKE2b-256 f0d6b165039d8c42e9b7f73a67542a26045938053866c495a2e45c17ff06843a

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 701002132a8444e9ccaae9953cb9c9e49dc27deec8ce8fd8f2c5ff9d7c6115f0
MD5 7b8bcf01559708132e4c7558cbbc60d7
BLAKE2b-256 fc018161a0a724916d052da7623fefb2bc9a85dccbbd1ef8ad34d6e62974d12f

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp36-none-win_amd64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 c1bcaa67da30076e8edbe6510d3706f7af754860f100e8304666fb3927891b1e
MD5 111b8ce20cbbca9ddc14fe88282b6bc1
BLAKE2b-256 d621ffbad410b267aa3b4948cc91ac2c7b0a283b3b3497de7e1eb7ed76beebef

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6d0caf543866c2750b609ddadec515c776e4951fe86d426ed5999aadabe0ff98
MD5 99bc3cb40220a2adda1dbf7bf844ba7d
BLAKE2b-256 83597e8dcd014a5104fc86225b571331063bc827e103b94667e0668271847aee

See more details on using hashes here.

File details

Details for the file polygons-0.2.1-cp36-cp36m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for polygons-0.2.1-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 ce52c5425e23208367240d73d9fe2ec0640c90c071634e101b71b03fceb384b7
MD5 37447ee1603b821fb8b634ab48e5dfa0
BLAKE2b-256 e195d3cd2bc1f6e579a0006affb4f9f17da96e118907ecfbcbb186492f3c5dae

See more details on using hashes here.

Supported by

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