Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NSI country filter uniform #2386

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Make NSI country filter uniform #2386

merged 2 commits into from
Nov 18, 2024

Conversation

Famlam
Copy link
Collaborator

@Famlam Famlam commented Nov 10, 2024

  • Let all plugins use the same function, nsi_rule_applies, to evaluate the locationSet of NSI
  • Allow country codes with subcodes (like "NL-GE") instead of only the country ("NL")

This doesn't fix 2358 completely yet, but makes a fix easier.
Also, for cases where the geojson file has the same code as the Osmose extract (such as Iowa, Quebec, ...) this makes it work again.

For canada it also fixes some cases that never worked, e.g. this entry previously wasn't parsed well due to including ca but excluding ca-qc. We previously didn't support such "subregion-exclusions".

- Let all plugins use `nsi_rule_applies` to evaluate the locationSet
- Allow country codes with subcodes (like NL-GE)
In case the geojson file of NSI is named like an Osmose extract (e.g. like US Iowa, or Quebec (CA), it'll support include/exclude statements for those subregions.
@Famlam Famlam marked this pull request as ready for review November 15, 2024 22:30
@frodrigo
Copy link
Member

frodrigo commented Nov 16, 2024

Sub country code was not done before because of not matching Osmose definition and could raise bad Osmose issues.

@Famlam
Copy link
Collaborator Author

Famlam commented Nov 16, 2024

You mean that the same country code (like US-IA for Iowa) has different borders in Osmose or NSI? That would be quite surprising to me. Would you happen to know where (which region) this causes issues?

Currently, by not supporting it we also have false positives, e.g. this detection shouldn't exist because it's rule is excluding CA-QC. However, since we (without this patch) don't check for the ca-qc it's still detected.
(And also false negatives, e.g. this node isn't detected by this rule, without this patch)

Of course this would only affect cases where our division is the same (US-IA) or smaller (CA-QC-*) than theirs, and the naming scheme is similar. For France for instance we use FR-[number] rather than FR-[letters]-[number], so that would really require a map and/or third party library. On the other hand, if they use a smaller subdivision than Osmose, it's unfixable at the moment (unless we start comparing node coordinates rather than extracts). However, those cases wouldn't be affected by this patch, would they?

@frodrigo
Copy link
Member

You mean that the same country code (like US-IA for Iowa) has different borders in Osmose or NSI? That would be quite surprising to me. Would you happen to know where (which region) this causes issues?

Not the boundaries, but the code itself.

The issue is about making the map of the codes.

Maybe we can change some code on Osmose side, to match national or supra national code (if it can help to match NSI code).

@Famlam
Copy link
Collaborator Author

Famlam commented Nov 17, 2024

I don't understand.
If the codes match (e.g. CA-QC, US-IA) this will work to add support.
If the codes do not match (e.g. FR) this PR will not change anything, right?

Making a map for the remaining cases (e.g. FR-ABC = [FR-1, FR-2, FR-3]) could be in a future PR. (I first want to explore if it's possible to use that library before making a hardcoded map).
And even then some cases cannot be fixed (without comparing node/way/relation coordinates) until there's a split of the Osmose extract (e.g. Denmark)

@frodrigo
Copy link
Member

I reread the code. Today the country is always the 2 chars country code, even for sub country area. If I'm not wrong, when a rule exclude a subpart, the 2-chars only country code make the rule excluded, doesn't ?

Concerning France sub areas, It looks like to me subarea codes are not used, but always geojson.

@Famlam
Copy link
Collaborator Author

Famlam commented Nov 18, 2024

I'm not sure if I understand what you mean.

  1. For France, nothing will change by this PR because of the different divisions (FR-[number] in Osmose vs FR-[lettercode] in NSI)
    Maybe in a follow-up PR, either via a hardcoded map (where possible) or via the library (see issue). The library would be favorable for maintenance, but would be a big PR since it would need to download all geojson files etc. Hence I didn't do this yet.
  2. For many other countries with subdivisions (AT, AU, BR, CA, CH, (part of) DE, ES, IT, MX, (part of) PH, (part of) US) it will make the subdivisions work. If I use CA-QC as example:
    a) this rule has {"include":["ca"],"exclude":["ca-qc.geojson"]}
    b) What this PR does is that it strips away the .geojson (and normalizes the case if needed). For many countries (see list above and in the issue) this will work since the file is just called [country-region-code].geojson
    c) Then, since Osmose divides CA-QC in subdivisions, example "CA-QC-CQC", it first checks CA-QC-CQC -> no match. So it checks CA-QC and finds this in de exclude. Hence it detects that this rule is excluded for CA-CQ.

Without this PR, it would only check for CA. It finds CA in the include, hence it (incorrectly) thinks this rule is included.

This PR doesn't do anything if the geojson isn't named the same as the Osmose subdivisions, e.g. France is unaffected, Denmark is unaffected, ... (see issue for full list)

@frodrigo
Copy link
Member

I reread the code. Today the country is always the 2 chars country code, even for sub country area. If I'm not wrong, when a rule exclude a subpart, the 2-chars only country code make the rule excluded, doesn't ?

I was thinking the code was doing a smart thing with exclusion... but it does not.

Sorry, yes this PR will improve the results without introduce more false positive.

@frodrigo frodrigo merged commit be3fbba into dev Nov 18, 2024
4 of 6 checks passed
@Famlam Famlam deleted the famlam-nsi branch November 19, 2024 00:17
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