Package: inpoly
INPOLY: Fast point(s)-in-polygon queriesA fast 'point(s)-in-polygon' routine forPython.INPOLYreturns the "inside/outside" status for a set of verticesVERTand a general polygon (PSLG) embedded in the two-dimensional plane. General non-convex and multiply-connected polygonal regions can be handled.INPOLYis based on a 'crossing-number' test, counting the number of times a line extending from each point past the right-most region of the polygon intersects with the polygonal boundary. Points with odd counts are 'inside'. A simple implementation requires that each edge intersection be checked for each point, leading to (slow)O(N*M)overall complexity.This implementation seeks to improve these bounds. Query points are sorted byy-valueand candidate intersection sets are determined via binary-search. Given a configuration withNtest points,Medges and an average point-edge 'overlap' ofH, the overall complexity scales likeO(M*H + M*LOG(N) + N*LOG(N)), whereO(N*LOG(N))operations are required for the initial sorting,O(M*LOG(N))operations are required for the set of binary-searches, andO(M*H)operations are required for the actual intersection tests.His typically small on average, such thatH << N. Overall, this leads to fastO((N+M)*LOG(N))complexity for average cases.QuickstartClone/download + unpack this repository.
python3 setup.py install
python3 example.py --IDnumber=1
python3 example.py --IDnumber=2
python3 example.py --IDnumber=3Demo problemsThe following set of example problems are available inexample.py:example: 1 # a simple box-type geometry to get started
example: 2 # random queries using a common geographic dataset
example: 3 # speed test vs existing inpolygon implementationsRunpython3 example.py --IDnumber=Nto call theN-thexample.Fast kernelsINPOLYrelies onCythonto compile the core "inpolygon" tests into a fast kernel.inpoly_.pyxcontains the human-readableCythonimplementation,inpoly_.cis the auto-generated output. For a full build:python3 setup.py build_ext --inplace
python3 setup.py installThese steps should "compile" theCythonkernelinpoly_.pyxinto thePython-compatiblec-codeinpoly_.c, which can then be compiled into the binary libinpoly_.so[pyd|dylib].License TermsThis program may be freely redistributed under the condition that the copyright notices (including this entire header) are not removed, and no compensation is received through use of the software.  Private, research, and institutional use is free.  You may distribute modified versions of this codeUNDER THE CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE TO IT IN THE SAME FILE REMAIN UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH SOURCE AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT CHARGE, AND CLEAR NOTICE IS GIVEN OF THE MODIFICATIONS. Distribution of this code as part of a commercial system is permissibleONLY BY DIRECT ARRANGEMENT WITH THE AUTHOR. (If you are not directly supplying this code to a customer, and you are instead telling them how they can obtain it for free, then you are not required to make any arrangement with me.)DISCLAIMER:  Neither I nor the University of Sydney warrant this code in any way whatsoever. This code is provided "as-is" to be used at your own risk.References[1]- J. Kepner, D. Engwirda, V. Gadepally, C. Hill, T. Kraska, M. Jones, A. Kipf, L. Milechin, N. Vembar:Fast Mapping onto Census Blocks, IEEE HPEC, 2020.