coordinate --> canton

153 views
Skip to first unread message

ich...@gmail.com

unread,
Nov 24, 2017, 9:02:30 AM11/24/17
to GeoAdmin API
Dear users and developers.

I am searching for some time in the web, where I can get information about the canton of a given coordinate.

I want to post a coordinate (pref: WGS84, not preferred but possible: swiss grid) and then I got back the name of the canton.
I thought using the bbox I can use https://api3.geo.admin.ch/rest/services/api/SearchServer?bbox=685820,246315,685825,246320&type=locations
Based on the example I thought to find the canton in "label" or "detail". However, even for the example, I cannot reproduce the output telling me that this location is in Bern.
Output is:

results

0
id1942136
weight1477
attrs
origin"parcel"
geom_quadindex"0"
@geodist5967.93212890625
zoomlevel10
lon6.8043975830078125
detail"1260 moudon 5678 ch974590888353"
rank10
geom_st_box2d"BOX(551183.797631043 167969.009040845,551736.93207508 168560.527755163)"
lat46.66384506225586
num1260
y551449.6875
x168241.375
label"<b>Moudon</b> 1260 (CH 9745 9088 8353)"


Can you give me any hint for this API or another??
Thank you very much.



































Gilbert Jeiziner

unread,
Nov 24, 2017, 9:14:08 AM11/24/17
to geoadm...@googlegroups.com, ich...@gmail.com
Hi

there is a specific layer for cantons that you could use for this
purpose: ch.swisstopo.swissboundaries3d-kanton-flaeche.fill

If you use it with our identify service [1], you should be able to get
what you want:

https://api3.geo.admin.ch/rest/services/all/MapServer/identify?geometry=2716000.0000000005,1133000&geometryFormat=geojson&geometryType=esriGeometryPoint&imageDisplay=1920,572,96&lang=en&layers=all:ch.swisstopo.swissboundaries3d-kanton-flaeche.fill&mapExtent=2180000,1047000,3140000,1333000&returnGeometry=true&sr=2056&tolerance=10

The service works with both LV03 and LV95 input/output. To transform
WGS84 coordinates to LV95, you can use our reframe web service:
https://www.swisstopo.admin.ch/content/swisstopo-internet/de/online/calculation-services/m2m/_jcr_content/contentPar/tabs/items/dokumente_und_publik/tabPar/downloadlist/downloadItems/54_1489059076274.download/Report16-03.pdf

Note that the complete canton dataset is also available for download:
https://data.geo.admin.ch/ch.swisstopo.swissboundaries3d-kanton-flaeche.fill/

Hope this helps

Gilbert

[1] http://api3.geo.admin.ch/services/sdiservices.html#identify-features
> --
> You received this message because you are subscribed to the Google
> Groups "GeoAdmin API" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to geoadmin-api...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

ich...@gmail.com

unread,
Nov 24, 2017, 6:48:55 PM11/24/17
to GeoAdmin API
Ah, thx. I see that I will find the info in results --> 0 --> properties --> ak.
I recognized two things.
1st: My first try with https://api3.geo.admin.ch/rest/services/api/SearchServer?bbox=685820,246315,685825,246320&type=locations gives back a json of around 1 kB and in the (results --> 0 --> attrs --> details) I find the BFS-Nr., right? Obviously it is easy to assign the canton to a given BFS-Nr, using the info on https://de.wikipedia.org/wiki/Gemeindenummer.
2nd: Your solution gives back a json with 120 kB.
By doing the BFS assignment onboard (instead of asking for the canton), I save 120 times traffic.

I assume to convert WGS84 to LV95 is also faster on board? (I think I wrote one convertion function two years ago). Don't you think so?

Cheers

ich...@gmail.com

unread,
Nov 25, 2017, 3:44:31 AM11/25/17
to GeoAdmin API
I will try to use the BFS-Nr. approach first. I can do a speed comparison with the suggested approach later on.

However, do you know, why https://api3.geo.admin.ch/rest/services/api/SearchServer?bbox=674416,251861,674418,251863&type=locations gives back an empty Json dict?

Thx, bye.

Loïc Gasser

unread,
Nov 25, 2017, 4:12:54 AM11/25/17
to geoadm...@googlegroups.com
Hello,

Yes to perform intersection operations you should use the identify service.


Search server is meant to perform full text search operations.

Kind regards 

Loïc

Swisstopo




--
You received this message because you are subscribed to the Google Groups "GeoAdmin API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api+unsubscribe@googlegroups.com.

ich...@gmail.com

unread,
Nov 25, 2017, 4:32:59 AM11/25/17
to GeoAdmin API

ah, thank you.
I found out that the return data of the geometry is upsizing the returned JSON. The documentation reads: set returnGeometry to false will solve the prob.
Good docu.
Now I will test it with one or two coords that didn't work as i wrote above.

ich...@gmail.com

unread,
Nov 25, 2017, 6:43:51 AM11/25/17
to GeoAdmin API
OT:
Is there no possibility to edit my last post?
btt:
Thank you for all your help. It seems to work fine. Of cause, the tolerance has to be set to 0. Otherwise it gives back 2 cantons sometims, if the coord is close to the border.

Marc Monnerat

unread,
Nov 26, 2017, 11:34:05 AM11/26/17
to geoadmin-api
Hello,

A bit late, but, 

1/ The geodata behind the above mentionned services are open data. Go to https://data.geo.admin.ch/ and search for "boundaries"

2/ You may try OSM Nominatim API, e.g.

   | jq '.address.state' 

"Bern/Berne"

and I am pretty certain that Google, Bing, Yandex provide equivalent services

Regards

Marc



--
You received this message because you are subscribed to the Google Groups "GeoAdmin API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-- ἡ φύσις οὐδὲν ποιεῖ ἅλματα.
Reply all
Reply to author
Forward
0 new messages