Skip to content

Conversation

@sveinbjornt
Copy link
Owner

@sveinbjornt sveinbjornt commented Nov 21, 2025

  • O(log n) instead of O(n)
  • ~100x faster for typical lookups, ~20x faster even in the worst case scenario

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds R-Tree spatial indexing to the SQLite database to significantly improve the performance of nearest_addr() and nearest_placenames() functions. R-Tree indexes enable efficient bounding box queries, replacing the previous brute-force approach that scanned all records. The implementation creates virtual R-Tree tables (stadfong_rtree and ornefni_rtree) and uses an expanding search radius strategy to find nearby candidates before computing precise distances.

Key Changes:

  • Added R-Tree virtual tables for spatial indexing of addresses and placenames
  • Refactored nearest_* functions to use R-Tree queries with expanding bounding box search
  • Added max_dist parameter to allow filtering results by maximum distance
  • Removed coordinate-based regular indexes that are now superseded by R-Tree

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/test_iceaddr.py Added test coverage for new max_dist parameter and refactored existing test for clarity
src/iceaddr/placenames.py Refactored nearest_placenames() to use R-Tree with expanding bounding box search and added max_dist parameter
src/iceaddr/addresses.py Refactored nearest_addr() to use R-Tree with expanding bounding box search and added max_dist parameter
build_db.py Added R-Tree virtual table creation and population for address data
add_placename_data.py Added R-Tree virtual table creation and population for placename data; commented out interactive file fetch prompt
README.md Updated license link for IS 50V Örnefni data source
Comments suppressed due to low confidence (3)

add_placename_data.py:48

  • This comment appears to contain commented-out code.
        # if input(f"{GPKG_FILE} exists, fetch newer version? (y/n): ").lower().startswith("y"):
        #     Path(GPKG_FILE).unlink()
        # else:

src/iceaddr/addresses.py:15

  • Import of 'math' is not used.
import math

src/iceaddr/placenames.py:13

  • Import of 'math' is not used.
import math

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…th the search box + optimized by removing redundant repeated dist calc when max_dist specified
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sveinbjornt sveinbjornt merged commit f5fdfbd into master Nov 22, 2025
4 checks passed
@sveinbjornt sveinbjornt deleted the rtree branch November 22, 2025 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants