Skip to content

Add local reverse-geocode database for better performance#87

Open
Zoriot wants to merge 2 commits into
mainfrom
offline-reverse-geocode
Open

Add local reverse-geocode database for better performance#87
Zoriot wants to merge 2 commits into
mainfrom
offline-reverse-geocode

Conversation

@Zoriot

@Zoriot Zoriot commented May 24, 2026

Copy link
Copy Markdown
Collaborator
  • Add optional offline country/region lookup using alpslib-geo RgcHandler
  • Automatically download and cache RGC database on first run from configured URL
  • Fall back to online Photon/Komoot API if local database disabled or unavailable
  • Mark rgcHandler field as volatile to guarantee cross-thread visibility
  • Mark Module.enabled as volatile to ensure reliable isEnabled() checks across threads
  • Schedule RgcHandler creation and all method calls on main thread to prevent concurrent access
  • Create parent directories before FileOutputStream to handle first-run download
  • Use try-with-resources for download streams to prevent resource leaks
  • Schedule RGC lookups on main thread when called from worker threads in OpenStreetMapAPI
  • Add getCCA2FromCountryName() fallback helper for country code lookup
  • Add RGC configuration options: enabled, url, path under reverse-geocode.local-database
  • Handle download failures gracefully with logging and fallback to API

Dependencies:

  • Add com.alpsbte.alpslib:alpslib-geo:1.0.0

Files:

  • build.gradle.kts: add alpslib-geo dependency
  • gradle/libs.versions.toml: define alpslib-geo version
  • settings.gradle.kts: enable mavenLocal() (TEMPORARY - disable before merge)
  • NavigationModule.java: add RGC initialization with auto-download
  • Module.java: mark enabled field volatile
  • OpenStreetMapAPI.java: schedule RGC lookups on main thread
  • NavUtils.java: add getCCA2FromCountryName() helper
  • ConfigPaths.java: add RGC_LOCAL_DB_* constants
  • WarpsComponent.java, WarpEditMenu.java: use fallback country code lookup
  • config.yml: document RGC local-database settings

@Zoriot Zoriot requested a review from Copilot May 24, 2026 15:35
@Zoriot Zoriot self-assigned this May 24, 2026
@Zoriot Zoriot added 💄 low priority This currently has low priority. 🦐 small size This is a small issue. labels May 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 optional local reverse-geocoding support for navigation features, using an RGC database to reduce reliance on online Photon/Komoot lookups.

Changes:

  • Adds RGC configuration paths and default navigation config options.
  • Initializes/downloads a local RGC database in NavigationModule.
  • Uses local RGC lookups in OpenStreetMapAPI, with country-code fallback handling for warp creation/editing.
  • Adds the alpslib-geo dependency and repository resolution changes.

Reviewed changes

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

Show a summary per file
File Description
src/main/resources/modules/navigation/config.yml Adds local reverse-geocode database configuration.
src/main/java/net/buildtheearth/buildteamtools/utils/io/ConfigPaths.java Adds config path constants for RGC settings.
src/main/java/net/buildtheearth/buildteamtools/modules/network/api/OpenStreetMapAPI.java Adds local RGC lookup path before online fallback.
src/main/java/net/buildtheearth/buildteamtools/modules/navigation/NavUtils.java Adds helper for resolving CCA2 from region names.
src/main/java/net/buildtheearth/buildteamtools/modules/navigation/NavigationModule.java Adds RGC database file setup, download, and handler initialization.
src/main/java/net/buildtheearth/buildteamtools/modules/navigation/components/warps/WarpsComponent.java Uses fallback CCA2 lookup when reverse geocode returns no code.
src/main/java/net/buildtheearth/buildteamtools/modules/navigation/components/warps/menu/WarpEditMenu.java Uses fallback CCA2 lookup when changing warp location.
settings.gradle.kts Enables mavenLocal() repository resolution.
gradle/libs.versions.toml Adds alpslib-geo version catalog entries.
build.gradle.kts Adds alpslib-geo as an implementation dependency.

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

Comment thread settings.gradle.kts Outdated
Comment thread src/main/resources/modules/navigation/config.yml Outdated
@github-actions

github-actions Bot commented May 24, 2026

Copy link
Copy Markdown

Qodana for JVM

2 new problems were found

Inspection name Severity Problems
Confusing argument to varargs method 🔶 Warning 1
Constant values ◽️ Notice 1

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@Zoriot Zoriot force-pushed the offline-reverse-geocode branch 2 times, most recently from 68868a8 to a531451 Compare May 24, 2026 15:51
Comment thread src/main/java/net/buildtheearth/buildteamtools/modules/navigation/NavUtils.java Outdated
…load and thread-safety fixes

- Add optional offline country/region lookup using alpslib-geo RgcHandler
- Automatically download and cache RGC database on first run from configured URL
- Fall back to online Photon/Komoot API if local database disabled or unavailable
- Mark rgcHandler field as volatile to guarantee cross-thread visibility
- Mark Module.enabled as volatile to ensure reliable isEnabled() checks across threads
- Schedule RgcHandler creation and all method calls on main thread to prevent concurrent access
- Create parent directories before FileOutputStream to handle first-run download
- Use try-with-resources for download streams to prevent resource leaks
- Schedule RGC lookups on main thread when called from worker threads in OpenStreetMapAPI
- Add getCCA2FromCountryName() fallback helper for country code lookup
- Add RGC configuration options: enabled, url, path under reverse-geocode.local-database
- Handle download failures gracefully with logging and fallback to API

Dependencies:
- Add com.alpsbte.alpslib:alpslib-geo:1.0.0

Files:
- build.gradle.kts: add alpslib-geo dependency
- gradle/libs.versions.toml: define alpslib-geo version
- settings.gradle.kts: enable mavenLocal() (TEMPORARY - disable before merge)
- NavigationModule.java: add RGC initialization with auto-download
- Module.java: mark enabled field volatile
- OpenStreetMapAPI.java: schedule RGC lookups on main thread
- NavUtils.java: add getCCA2FromCountryName() helper
- ConfigPaths.java: add RGC_LOCAL_DB_* constants
- WarpsComponent.java, WarpEditMenu.java: use fallback country code lookup
- config.yml: document RGC local-database settings
@Zoriot Zoriot force-pushed the offline-reverse-geocode branch from a531451 to 4ed6464 Compare June 9, 2026 18:25
Address PR review by splitting RGC setup, region lookup, and OpenStreetMap
country resolution into focused methods and switch-based flows.

@Jasupa Jasupa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code is way more clean now; good job. Maybe we can create a second version for things like the disputed areas or multiple languages later, but again, this is out of scope for now and otherwise we would make things unneccesarily complicated for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💄 low priority This currently has low priority. 🦐 small size This is a small issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants