stefanzweifel/php-swiss-cantons

Zipcode and Canton is not a One-to-One relationship

Closed this issue · 4 comments

Hi,

I'm using this library since a few months, thank you for your work !

But unfortunately, some cases don't work when guessing the canton from the zipcode.
In fact, in Switzerland, a zipcode (NPA) does not contain the information of a specific canton. It's based on geographical and physical information, like train endpoint. For some zipcode, you can have different cities, which are in different cantons.

Example: 1290 is assigned to Chavanne-les-bois in the canton of Vaud, and Versoix in the canton of Geneva.

It's the same issue with zipcode and cities: a city can have several zipcode...
Example: Kefikon has a zipcode for its part in Thurgovie canton et a zipcode for its part in Zurich canton..

Conclusion
Is it possible to have a system covering all cases ? If not, it would be necessary to add this information as a warning in the library documentation.

Yeah, this library is not perfect. :)
And as you mention, the whole system is not perfect. I myself live in a city which has 3 different names and the zipcode – depending on the government data source – belongs to up to 4 different cities.

Is it possible to have a system covering all cases?

Zipcode search was an aftertought for this package and has been added in #6 many years ago. As you mention, the code currently assumes that a zipcode has a one-to-one relationship with a canton.

What we could do, is rewrite the package so that certain methods return an array/collection of Cantons/Zipcodes.
I currently work on other projects, but could implement this in the near future.

The consumer of the package then still have to figure out, which canton to choose.
I don't know how you use the package, but in your example with 1290, you would somehow have to decide which canton to use: Vaud or Geneva.

That's not something the package can solve based on a single data point (zipcode).

That's not something the package can solve based on a single data point (zipcode).

I totally agree. To determine the canton, we'd need at least the zipcode and the city name. But is there any city identifier other than the name ? Or at least a reference liste ?
Otherwise, it will be hard to search with an not-standardized name..

As you mentioned in #33, the link in the README/issue points to a 404 now. I haven't figured out yet, where the Swiss Post now publishes these values.

I found this asset on opendata.swiss, but didn't have the time yet to review the data.
https://opendata.swiss/de/dataset/amtliches-ortschaftenverzeichnis-mit-postleitzahl-und-perimeter