Skip to content

Add local reverse-geocode database for better performance#87

Open
Zoriot wants to merge 1 commit into
mainfrom
offline-reverse-geocode
Open

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

Conversation

@Zoriot
Copy link
Copy Markdown
Collaborator

@Zoriot Zoriot commented May 24, 2026

  • 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
Copy link
Copy Markdown
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 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

@Getter
@Nullable
private RgcHandler rgcHandler = null;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Quite sure that will not cause issues because we always read from main thread. also Rgc handler itself is not thread save


reverse-geocode:
local-database:
# Whether to use the local database for reverse geocoding or not. If false, the online Nominatim API will be used. [true|false]
CompletableFuture<String[]> future = new CompletableFuture<>();
String url = "https://photon.komoot.io/reverse?lat=" + coordinates[0] + "&lon=" + coordinates[1] + "&lang=en";

if (NavigationModule.getInstance().isEnabled() && NavigationModule.getInstance().getRgcHandler() != null) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Quite sure that will not cause issues

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

Qodana for JVM

4 new problems were found

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

💡 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 from 3baac1b to 68868a8 Compare May 24, 2026 15:42
…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 68868a8 to a531451 Compare May 24, 2026 15:51
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.

2 participants