Flanders: Fast 2D nearest neighbor search with an angle
`.-:://////:-.`
`-/oyhddddmmddddddNmdmdhs/`
-ohddddddddddddNddddddNddddmmds.
`hmmmmmdddddddddddNddddmmddddmmddm.
`hddddddmmddddddhyyysoossyhdmNmdddNs
sddddddddmmho/:-------------:odmmmmo
:mddddddddd+-------------------:hddd.
dddddddddm+---------------------:ms.
:mddddddddd-----------------------s/`
yddddddddds------------------------:s
`mddddddddm+-----://////+/:---://////y`
-Nddddddddm/----+:` `./+-+-` `.+:
/mddddddddN:---o` -d- -. o-
omddddddddN////y -d/ `m. y+ +:
sdddhhNmmmN+/::o: `-` `+so++//:. `:+`
`---. ydd+::mdddm:----/+-.````-:+:------:+s/-
o/::/+- sN:-oomdddm+------://+///:---------:s
`.-.` s-----+/` oN:---smddds------------:+oyhhysssydhs:.
-o/://+-`.o:----/o` /mh:---hyyy/----------+hdmmmmdddddmmmddho.
/+-----:+/-o:----:+` `.. .mddyyydo-----:///::ohdmmdmmdmddNdmmdmmddd/
:+/-----:+/y-----:+-` .:+///+. dddddddd----:mMMNNddddddmddmdddmmdmddmdddm:
``-/+:----::-------:/+++:----/+ +mdddddN----:MMMMMNmmmmmmmdddddddhhhhhys+/.
.////+//+o:--------------/-----/o` sdddddm/----oNmdmNNNNMMMm//os--...``
y:-----:/+o------------------:o: :ydddm+-----:oyyyysydMMm:::o+.
:o/:----------------+o:-----:s` .::+o--------://++oooo+:--:s
-:/+/:--------------s/----s. -o------------------:/o+.
`-/+o------------/---+d- `+o------------------::h
.s/---------:::ohhhs y.-++:-----------------d:`
dhys+///+oyhhhhyhm/ `s````:/++o+//:::://+++/-.s.
/dddhhhhhhyyhhhddhym` -s`````````..-:::/h/s-````.s`
:dyyhddddddddddhyyyym `ydy-`````````````s:.-o/````sy/-`
yyyyyyyyyyyyyyyyyyyhs `./+ooymhyhy/.`````````:o....++``:dmdhhhso:`
dyyyyyyyyyyyyyyyyyym:`-/oyddhyyyyhddyyhhs+-``````hso++ohd++dyyddyyyyhhyo/`
myyyyyyyyyyyyyyyyyyNhhhyyyyyyyyyyyyddyyyyyhdyso++ddhmhmddhhyyyyddyyyyyyyhdy+.
Installation
$ pip install flanders
Example
In this example we have 6 points (numbered 0 to 5) and two observer points with a certain view vector and view angle (90 degrees). The first observer point finds point 2. The second observer point does not find any neighbor within the view angle and returns -1.
Example code:
import flanders
# as a first step we build the search tree
# we can later reuse the search tree many times
points = [
(60.4, 51.3),
(173.9, 143.8),
(132.9, 124.9),
(19.5, 108.9),
(196.5, 9.9),
(143.3, 53.3),
]
tree = flanders.build_search_tree(points)
# now we will search the indices of nearest neighbor points
# for two observer points
observer_coordinates = [(119.2, 59.7), (155.2, 30.2)]
view_vectors = [(0.0, 1.0), (-1.0, -1.0)]
view_angles_deg = [90.0, 90.0]
indices = flanders.nearest_indices_from_coordinates(
tree, observer_coordinates, view_vectors, view_angles_deg
)
assert indices == [2, -1]
# instead of using observer coordinates, also the original
# points themselves can be observers and we can select them
# by their index
observer_indices = [0, 1, 2, 3, 4, 5]
view_vectors = [(1.0, 1.0) for _ in observer_indices]
view_angles_deg = [90.0 for _ in observer_indices]
indices = flanders.nearest_indices_from_indices(
tree, observer_indices, view_vectors, view_angles_deg
)
assert indices == [5, -1, 1, 2, -1, 1]
Efficiency considerations
The above example is very small and simple but this library starts to shine once you have very many points and/or very many observers where a noddy implementation would take too long to compute.
Example timing for 1 M points and 10 k observers (on i7-10710U):
- constructing the search tree: 3.0 s
- nearest neighbor search: 9.6 s
If you compute nearest neighbors for many observers it is a good idea to send in an entire batch of observers instead of computing one by one. If you send in an entire batch, the code will shared-memory parallelize the loop over the observers.
References used during development
Metadata
Release files for flanders 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 3.6 MB
Release files / flanders-0.3.3-cp314-cp314-win_amd64.whl
| Download URL | flanders-0.3.3-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 177.2 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ed91da30e47f7f515a85dbaeb9ad52ac1647e623787a2af207f63b55127a4433
|
|
BLAKE2b-256 checksum How to use checksums |
cf2f08fb2c1ec284a5324e2a7f3fb690eef760e88e6f82a6ceff9d6100484b99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp314-cp314-manylinux_2_34_x86_64.whl
| Download URL | flanders-0.3.3-cp314-cp314-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 292.7 kB |
| Tags | CPython 3.14 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
f54f7580330be40e3a0b43de41148f5eabc13ca81dd911a0dfeb51425d750bd7
|
|
BLAKE2b-256 checksum How to use checksums |
899ad848bc90651fe9e7aeb5a30a9ba878f28678a4958929119beb779caf50eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | flanders-0.3.3-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 254.6 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
364613633877f9476455e6d807faa1e35ba3534e41c54fa5d72995419f9aea9b
|
|
BLAKE2b-256 checksum How to use checksums |
7caef5210d89e2afb788dd5df9a65ab97368cb2e65aaf21d045a02a7e2b4cd03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp313-cp313-win_amd64.whl
| Download URL | flanders-0.3.3-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 177.3 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b1e6e62fd3aa173aacdb08d0fa6667cf101e578cbff77c69066d79a7c955e0ec
|
|
BLAKE2b-256 checksum How to use checksums |
3e6bf8d7dea31da5975e0ba4ddc005f0e9cb497738647f2eb31500df99eaba60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | flanders-0.3.3-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 294.0 kB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
8b53da14e38fef1c0c294539c5aad9baaa467b06baaa79865d29ace41e6b0d31
|
|
BLAKE2b-256 checksum How to use checksums |
551a88e738a391d830fe24480d0edccf7db05148c7676016e94f8a3521fe63b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | flanders-0.3.3-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 254.2 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3cd7af62bf26d4990c9fe67d2f6d02ca2bbdcbb68f0276db20727ba12e7a5160
|
|
BLAKE2b-256 checksum How to use checksums |
0d6114f5d397b5496e55e94a1d0ffd72b1941450e76a6d8bc1ce7a59dc8a7133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp312-cp312-win_amd64.whl
| Download URL | flanders-0.3.3-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 177.3 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5373152174532bef109c59a050472d5745cfb636a75680fba3a8acc0a343b5ef
|
|
BLAKE2b-256 checksum How to use checksums |
bb29fe8c4ed666e906d8b1406b3dd522653ca86569d6283e0d0f7b29817d865a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | flanders-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 293.9 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
ab8951b95573a8e998d87b4187247028dcbcbdfb4883111be463a8d9c71c6f00
|
|
BLAKE2b-256 checksum How to use checksums |
dbf9a36296bb24b841a4745d30270dceccbd2760439cca1c4a1e8e7f5b1a47c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | flanders-0.3.3-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 254.1 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3138dfc6a1d828f0350f9761abd499979d7d8c3733b2aedac01e7487e9c441a2
|
|
BLAKE2b-256 checksum How to use checksums |
8ac46046d8b3975f4965e3461528388adba9410610e640fd5bb0bf2319c5eb9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp311-cp311-win_amd64.whl
| Download URL | flanders-0.3.3-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 178.7 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f7a22dbd038729a2256d126085d0ffb4e17f0bb0013b8e2f60fb22d9ccaa6f6b
|
|
BLAKE2b-256 checksum How to use checksums |
201be22b2b3b2af048c906426b3a2743ef5f9f104f10989359870a38410d0e5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | flanders-0.3.3-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 295.2 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
0417200a00cf5fcb13a1732766a9582630bd9642922276ddc764c416c3d29853
|
|
BLAKE2b-256 checksum How to use checksums |
1e9155aeb13cb033079436e647b086bffaa1e82f841c03c727ae97741847434e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | flanders-0.3.3-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 255.9 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7043d2fbeb6a174343136d00bb3c153c18e74bcabaf1859df09c6d3319fcb404
|
|
BLAKE2b-256 checksum How to use checksums |
880637fc0d8fac1cb1276442e5ab50e4eb87b2abac33e453de4507dd8eae5bdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp310-cp310-win_amd64.whl
| Download URL | flanders-0.3.3-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 178.0 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5beb7ca8b8d9d0cf50bf49be46818f99b382064d70b23a7d3f3a376ff6eb5728
|
|
BLAKE2b-256 checksum How to use checksums |
bd9bd3a07c89c1c5476050353ed46ab27336d9796202b310195dbd538c63bc31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | flanders-0.3.3-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 295.3 kB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
27189c65445a3e43b8195d3eb1ff75a034af56a804c948d01d328a82772124a7
|
|
BLAKE2b-256 checksum How to use checksums |
62f9a319d6e8ad4bc9767481b72ee6d694b2d945bdc7a6c95dbdac2653fda95a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / flanders-0.3.3-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | flanders-0.3.3-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 256.1 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4a5a56a52e5490ad94b291c62cbd0871ef6b9f315748b2ce4821a3336a4a373f
|
|
BLAKE2b-256 checksum How to use checksums |
beae9f40f3b9e3897c9fae0a789ba36aa46b9b0eeeca5c99017948354b7e964b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Security for flanders 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.