How to effectively find cities and cantons in DE and FR

65 views
Skip to first unread message

Andreas Schempp

unread,
Dec 9, 2024, 11:17:01 AM12/9/24
to GeoAdminCh API
Hi

We are developing a map application similar to https://map.geo.admin.ch, but it should only be possible to search by city and cantons. People can search by postal code or city or canton name. The search results should either list "Kanton XY" or "0000 City" as the result. Here's what I currently do:

1. try SearchServer?type=featuresearch&features=ch.swisstopo-vd.ortschaftenverzeichnis_plz,ch.swisstopo.swissboundaries3d-kanton-flaeche.fill and then SearchServer?type=locations&origins=zipcode,gg25,kantone to see if the term can be found.

2. if result is a canton (by layer=...kanton-flaeche  or origin=kantone), look up the actual canton data through coordinates on MapServer/identify?layers=...kanton-flaeche to get the bbox and canton short code (e.g. ZH for Zurich).

3. if result is from SearchServer?origin=gg25, the name is nut useable. So I have to use MapServer/identify?layers=...gemeinde-flaeche to get the actual town name (attributes.gemname) from coordinates. Then use SearchServer?features=...ortschaftenverzeichnis_plz to get the coordinates for that name before continuing with step 4.

4. if result is a place, look up the name (langtext), postal code (plz) and bbox through MapServer/identify?layers=ortschaftenverzeichnis_plz 

First of all, this is obviously really cumbersome and causes a lot of API hits and traffic. Maybe someone has any ideas if this can be simplified or improved.

Our biggest issue is that some "correct" search terms to not generate any results, especially since the application has to work in german, french and italian. You can reproduce the issue on https://maps.geo.admin.ch as well. The Canton of Valais is only found by "Valais", but not by "Wallis". I'm not sure if that is a bug in the data or intended, and what we can do to get that fixed/solved.

Thanks for any help or ideas.

GeoAdminCh API

unread,
Mar 24, 2025, 8:44:49 AMMar 24
to GeoAdminCh API
Dear Andreas,

Sorry for the late answer.

Concerning the featuresearch - You can search for the following administrative units:
  1. ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill - Administrative boundaries of Switzerland: https://www.geocat.ch/geonetwork/srv/ger/catalog.search#/metadata/9961dc6c-20a9-4b16-8a24-b20c3d8ddb83
    in swisssearch origins=gg25
  2. ch.swisstopo-vd.ortschaftenverzeichnis_plz - The official list of localities: https://www.geocat.ch/geonetwork/srv/ger/catalog.search#/metadata/972cd117-f1ed-4818-be14-233d89ab9fdf
    in swisssearch origins=zipcode
  3. ch.swisstopo.swissboundaries3d-kanton-flaeche.fill - The swissBOUNDARIES3D Cantonal borders: https://www.geocat.ch/geonetwork/srv/ger/catalog.search#/metadata/9eee6d40-f0a6-46c9-94ad-69679b9f3d38
    in swisssearch origins=kantone
Unfortunately, the data source behind these search indexes on the FeatureSearch endpoint (/rest/services/ech/SearchServer?type=featuresearch) is not multilingual.
The name is only stored in the respective official language of the administrative unit in the index.

The names in the data source are partially translated via the Swisssearch endpoint (/rest/services/ech/SearchServer?type=locations). Unfortunately, this is currently only the case for municipal boundaries.
For example:

Simplon / Sempione
swisssearch gg25

https://api3.geo.admin.ch/rest/services/ech/SearchServer?sr=2056&searchText=sempione&lang=de&type=locations&origins=gg25
https://api3.geo.admin.ch/rest/services/ech/SearchServer?sr=2056&searchText=Simplon&lang=de&type=locations&origins=gg25

vs

featureseach ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill

https://api3.geo.admin.ch/rest/services/ech/SearchServer?sr=2056&searchText=sempione&lang=de&type=featuresearch&features=ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill&timeEnabled=false
https://api3.geo.admin.ch/rest/services/ech/SearchServer?sr=2056&searchText=simplon&lang=de&type=featuresearch&features=ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill&timeEnabled=false

To enable a multilingual search, unfortunately the only option at the moment is to construct the search query in multiple languages on the client side and to send it in this form. However, a multilingual query of this kind must be sent to the swisssearch endpoint.
This supports fuzzy search and returns a response if the search text is in multiple languages:

https://api3.geo.admin.ch/rest/services/ech/SearchServer?sr=2056&searchText=Wallis,valais&lang=de&type=locations&origins=kantone
https://api3.geo.admin.ch/rest/services/ech/SearchServer?sr=2056&searchText=Simplon,Sempione&lang=de&type=locations&origins=gg25

We hope we could help you out.

Best regards,
Helpdesk federal geoportal/MCL

Reply all
Reply to author
Forward
0 new messages