Fetching structured street, postal code, location and canton information from API

38 views
Skip to first unread message

Yanick Witschi

unread,
Nov 17, 2021, 3:42:38 AM11/17/21
to GeoAdminCh API
Hello everyone!

I'm trying to find a way to get structured location data from arbitrary user input.
E.g. the user should be able to type "Dorfstrasse Wabern" and I should be able to extract "Dorfstrasse" as the street, "Wabern" as the location, 3084 as the postal code, "BE" as the canton etc. 

The only thing I found is https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText=dorfstrasse%20wabern&type=locations which seems to find the data but it does not come in structured fashion. The data is combined in a "detail" string of arbitrary format.

Is this even possible with the API?

Thanks!
Yanick

Eugène Skopa

unread,
Nov 17, 2021, 5:08:46 AM11/17/21
to GeoAdminCh API
Hello,

First of all sorry to interject, I am in no way affiliated with the GeoAdmin/Swisstopo but having recently implemented a similar feature perhaps I might be able to help.

First of all, are you interested in all types of data or only one in particular?
Because by default, SearchService returns feature results of several types (parameter: origins, see [1], particularly see the paragraph right above examples). I am not aware of a way to retrieve all the elements you need in a single request, but it can be obtained if several are combined.

If you are interested in all of the possible results of the locations SearchService, then you could search for them with it as you showed and then, depending on the origin, either directly query feature resource (see [2], using the returned featureId and the layer  based on the origins documentation) or do a features search first (as far as I know it is required for the origin: gazetteer, because results returned with that origin seem to come from two layers: ch.swisstopo.swissnames3d and ch.bav.haltestellen-oev) before querying the feature resource.

But if you are only interested in addresses then in my opinion a features search on ch.bfs.gebaeude_wohnungs_register layer (or ch.swisstopo.amtliches-gebaeudeadressverzeichnis or both) with a subsequent request to the feature resource might be a cleaner approach.

Hope it helps!
Regards,
Eugène

Yanick Witschi

unread,
Nov 18, 2021, 3:31:39 PM11/18/21
to GeoAdminCh API
Thanks Eugène! It did help a lot - sometimes all one needs is a gentle push into the right direction.
The feature API and the right layer names were what I was missing :-)

Thank you so much!
Yanick
Reply all
Reply to author
Forward
0 new messages