GET polygon for municipalities

78 views
Skip to first unread message
Assigned to procras...@gmail.com by david...@gmail.com

Kenny Lienhard

unread,
May 28, 2021, 5:20:50 PM5/28/21
to GeoAdminCh API
Dear all, 

I would like to draw polygons (e.g. on Google Maps https://developers.google.com/maps/documentation/javascript/examples/polygon-simple) of Swiss municipalities, regions, and cantons. Is there a way to get 

a) Polygon data in GeoJSON format for specific municipalities (e.g. via "BFS" number)
b) Is it possible to download Polygon data in GeoJSON format for Switzerland

For b), I've found the following link https://opendata.swiss/en/dataset/swissboundaries3d-gemeindegrenzen. GeoJSON seems not available to download. Am I missing something?

Kind regards, Kenny

David Oesch

unread,
May 28, 2021, 5:23:20 PM5/28/21
to geoadm...@googlegroups.com
Try


For json 

--
You received this message because you are subscribed to the Google Groups "GeoAdminCh API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geoadmin-api/cf9edd17-ad84-4006-9366-3935440632aen%40googlegroups.com.

Marc Monnerat

unread,
Jun 3, 2021, 10:54:52 AM6/3/21
to geoadmin-api

Kenny Lienhard

unread,
Jun 3, 2021, 11:53:34 AM6/3/21
to GeoAdminCh API
Dear both, 

Many thanks!

@David: I used this as a starting point and I have working maps in D3.js now. 

@Marc: Nice! This is exactly what I am looking for. I am missing a way to relate data from https://github.com/interactivethings/swiss-maps with my own data. The data from https://github.com/interactivethings/swiss-maps does not contain zip code, BFS number or something similar. I had a look at your API already earlier, but was unable to search for a specific BFS number. 


Shouldn't this provide Aarau (BFS number 4001)? I am getting Versoix instead. Is there a syntax error in my request?

Kind regards, Kenny

Marc Monnerat

unread,
Jun 4, 2021, 7:14:24 AM6/4/21
to geoadmin-api
Hello Kenny,

OK, it's not easy to navigate within the various services, but bear in mind they were developed for a web map application. So you have identify with is basically a click on a map (searching by position), find searching by layer attribute and search, a full-text search, but not returning any geometries.

1/ So, for your need, you may try  the find on the layer ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill :


Unfortunately, the result is a GeoJSON encapsulated in a results field.

{
  "results": [
    {
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
          [
            [
              [
                650938.6,
                250654.6
              ],
      },
      "layerBodId": "ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill",
      "bbox": [
        644378.4,
        246716.8,
        650938.6,
        251485.6
      ],
      "featureId": 4001,
      "layerName": "Gemeindegrenzen",
      "type": "Feature",
      "id": 4001,
      "properties": {
        "perimeter": 23587.84544979814,
        "gemflaeche": 1234,
        "label": "Aarau",
        "objektart": 0,
        "kanton": "AG",
        "gemname": "Aarau"
      }
    }
  ]
}


2/ For any given layer, you may find what attributes are available, their type,and example value with:

curl 'https://api3.geo.admin.ch/rest/services/api/MapServer/ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill' | jq -r '.'
 {
  "fields": [
    {
      "values": [
        "Chéserex",
        "Ferpicloz",
        "Randa",
        "Scuol",
        "Tuggen"
      ],
      "alias": "Name",
      "type": "VARCHAR",
      "name": "gemname"
    },
    {
      "values": [
        1347,
        2194,
        3762,
        5709,
        6287
      ],
      "alias": "BFS-Nummer",
      "type": "INTEGER",
      "name": "id"
    }
  ],
  "id": "ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill",
  "name": "Gemeindegrenzen"
}


Regards,

Marc

Kenny Lienhard

unread,
Jun 4, 2021, 7:36:13 AM6/4/21
to GeoAdminCh API
Hi Marc, 

Many thanks! Your help is highly appreciated. This is very close to what I was looking for. I can definitely start from here. 

Have a nice weekend, Kenny

oberhuelse

unread,
Jul 14, 2021, 5:45:14 AM7/14/21
to GeoAdminCh API
Dear all, 
Sorry for I am a bit late to the party. I have a similar issue with a search service for our WebGIS. The SearchServer returns point features where a polygon (e.g. municipalities) would be prefered. So I tried with a MapServer/find query:


...only to get that encapsulation within the "results" field. Even though I am defining geometryFormat=geojson, the answer is not a proper GeoJSON as our developer keeps telling me (this is "just a JSON"). The answer should be of the type FeatureCollection, as it is via this query for example: 


Is that a bug in the API or is that geometry format parameter not what we are thinking it is?

Thanks again, really enjoying the API and appreciating the support in this forum. 

Best regards, Sebastian

Marc Monnerat

unread,
Jul 14, 2021, 8:26:11 AM7/14/21
to geoadmin-api
Hello Sebastian,

You are correct the find and identify services are returning GeoJSON encapsulated in a result object, which is kind of ugly, but these services were loosely based on the infamous and ill-fated Esri REST JS API.
Now, won't develop the API v3 anymore and we plan to use the OGC feature API (WFS 3.0) for some services.

Regards,

Marc

Reply all
Reply to author
Forward
0 new messages