Skip to content

[BUGFIX] Process US regions without border countries - #297

Merged
treee111 merged 2 commits into
treee111:developfrom
Mirochill:fix-288-us-region-nbc
Aug 20, 2026
Merged

[BUGFIX] Process US regions without border countries#297
treee111 merged 2 commits into
treee111:developfrom
Mirochill:fix-288-us-region-nbc

Conversation

@Mirochill

Copy link
Copy Markdown
Contributor

This PR...

  • Keeps -nbc country runs for Geofabrik IDs like us/texas aligned with the tile names generated by CountryGeofabrik.
  • Adds a regression expectation for us/texas so no-border processing uses us_texas, matching the split tile filenames.

Considerations and implementations

When border-country processing is disabled, CountryOsmData previously kept the raw wanted map id in border_countries. For US regions this meant us/texas, while CountryGeofabrik.find_needed_countries() normalizes tile country names to us_texas. The later split and merge stages compare those names, so no country split files were added to the Osmosis merge command.

This normalizes the no-border country key in the same way as the tile list and downloaded map filenames.

Fixes #288

How to test

  1. Not run locally.
  2. git diff --check

Pull Request Checklist

@cviebrock

Copy link
Copy Markdown

Maybe you can help @Mirochill ... even with your fix, why does this work:

python -m wahoomc cli -nbc -v -co "us/texas"

but this doesn't:

python -m wahoomc cli -nbc -v -co "canada/ontario"

I get the error:

Entered country 'canada/ontario' is not a geofabrik country.
Please check this URL for possible countries: https://download.geofabrik.de/index.html

Is the US the only region that can be filtered by subregion?

@cviebrock

Copy link
Copy Markdown

Nevermind ... -co ontario works.

@treee111

Copy link
Copy Markdown
Owner

Local test result

Tested PR #297 in isolation on branch develop using the gdal-dev Anaconda environment.

Test run: python -m unittest tests.test_osm_maps -v

test_version_and_tags_of_country_config_file ... ok
test_encoding_open_sea_osm ... ok
test_folder_name_many_countries ... ok
test_input_country_malta ... ok
test_calc_border_countries_input_country ... FAIL  ← pre-existing, unrelated to this PR
test_calc_border_countries_input_xy_coordinates_1tile ... ok
test_calc_border_countries_input_xy_coordinates_2tiles ... ok
test_calc_without_border_countries_input_country ... ok
test_calc_without_border_countries_xy_coordinates_1tile ... ok
test_calc_without_border_countries_xy_coordinates_2tiles ... ok

Ran 10 tests in 78.369s

9/10 pass. The one failure (test_calc_border_countries_input_country) is pre-existing and unrelated to this PR — it fails on the unmodified baseline too. Root cause: geofabrik has since split Czech Republic into sub-regions, so the test's expected data is outdated.

The fix itself (.replace('/', '_')) is correct and minimal — test_calc_without_border_countries_input_country which covers the -nbc path passes cleanly.

@treee111

Copy link
Copy Markdown
Owner

Follow-up fix pushed: calc_country_name also needed slash normalization

After reviewing the fix, I noticed calc_country_name (lines 155–164 in osm_data.py) had the same issue as the calc_border_countries -nbc path that this PR already fixes.

calc_country_name builds the output folder name from self.o_geofabrik.wanted_maps, which retains raw user input (e.g. us/texas with a slash). Without normalization, processing a US sub-region would produce a country_name of us/texas, causing folder creation to fail or create an unintended nested directory structure.

I pushed an additional commit to this branch that applies the same .replace('/', '_') pattern:

def calc_country_name(self):
    for country in self.o_geofabrik.wanted_maps:
        normalized = country.replace('/', '_')
        if not self.country_name:
            self.country_name = normalized
        else:
            self.country_name = f'{self.country_name}_{normalized}'

This is consistent with what calc_border_countries already does in this PR and with how geofabrik.py normalizes tile['countries'] (line 190–191). Note: wanted_maps must stay un-normalized at the source because get_geofabrik_geometry() uses it as a lookup key into the geofabrik JSON.

Mirochill and others added 2 commits August 20, 2026 14:45
calc_border_countries already replaced '/' with '_' for the -nbc path,
but calc_country_name still used raw wanted_maps entries, meaning inputs
like 'us/texas' would produce a country_name of 'us/texas' and break
output folder creation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@treee111
treee111 force-pushed the fix-288-us-region-nbc branch from 060c5b2 to f490f60 Compare August 20, 2026 12:45
@treee111
treee111 marked this pull request as ready for review August 20, 2026 12:46
@treee111
treee111 merged commit dd7cb03 into treee111:develop Aug 20, 2026
2 checks passed
@treee111

Copy link
Copy Markdown
Owner

thanks for your PR @Mirochill

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.

Osmosis error when generating individual US states or EU cities without bordering areas

3 participants