Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Joseph Siddons
GeoSpatialTools
Commits
9496c161
Commit
9496c161
authored
5 months ago
by
Joseph Siddons
Browse files
Options
Download
Email Patches
Plain Diff
fix(kdtree): account for lon wrapping
parent
56498568
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
GeoSpatialTools/kdtree.py
GeoSpatialTools/kdtree.py
+20
-6
No files found.
GeoSpatialTools/kdtree.py
View file @
9496c161
...
...
@@ -82,13 +82,27 @@ class KDTree:
else
:
return
self
.
child_right
.
delete
(
point
)
def
query
(
def
query
(
self
,
point
)
->
tuple
[
Record
|
None
,
float
]:
"""Find the nearest Record within the KDTree to a _query Record"""
if
point
.
lon
<
0
:
point2
=
Record
(
point
.
lon
+
360
,
point
.
lat
)
else
:
point2
=
Record
(
point
.
lon
-
360
,
point
.
lat
)
r1
,
d1
=
self
.
_query
(
point
)
r2
,
d2
=
self
.
_query
(
point2
)
if
d1
<=
d2
:
r
=
r1
else
:
r
=
r2
return
r
,
point
.
distance
(
r
)
def
_query
(
self
,
point
:
Record
,
current_best
:
Record
|
None
=
None
,
best_distance
:
float
=
inf
,
)
->
tuple
[
Record
|
None
,
float
]:
"""Find the nearest Record within the KDTree to a query Record"""
if
not
self
.
split
:
for
p
in
self
.
points
:
dist
=
point
.
distance
(
p
)
...
...
@@ -98,25 +112,25 @@ class KDTree:
return
current_best
,
best_distance
if
getattr
(
point
,
self
.
variable
)
<
self
.
partition_value
:
current_best
,
best_distance
=
self
.
child_left
.
query
(
current_best
,
best_distance
=
self
.
child_left
.
_
query
(
point
,
current_best
,
best_distance
)
if
(
point
.
distance
(
self
.
_get_partition_record
(
point
))
<
best_distance
):
current_best
,
best_distance
=
self
.
child_right
.
query
(
current_best
,
best_distance
=
self
.
child_right
.
_
query
(
point
,
current_best
,
best_distance
)
else
:
current_best
,
best_distance
=
self
.
child_right
.
query
(
current_best
,
best_distance
=
self
.
child_right
.
_
query
(
point
,
current_best
,
best_distance
)
if
(
point
.
distance
(
self
.
_get_partition_record
(
point
))
<
best_distance
):
current_best
,
best_distance
=
self
.
child_left
.
query
(
current_best
,
best_distance
=
self
.
child_left
.
_
query
(
point
,
current_best
,
best_distance
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment