Table Of Contents

Previous topic

Unit tests

Next topic

Mobile API Examples

This Page

SwissSearch: geocoding

Swisssearch geocoding allows the user to search for swiss locations, like postcode, cantons, cities, toponymic datase (SwissNames) and addresses.

Note: The swiss cantons only allow websites of the federal governement to use the addresses search service.

You may however use this service using the ‘no_geom’ parameter returning no geocoded addresses, to check for the existence of an address.

Input parameters

The following parameters are required:

  • lang: optional lang: de (default) or fr
  • query: the query string to find (mandatory if egid is not transmitted)
  • egid: the egid used to find an address (mandatory if query is not transmitted)
  • DEPRECATED citynr (optional): the city number (BFS id). Use the bfsnr parameter instead.
  • bfsnr (optional): the city number provided by the BFS
  • cb (optional): the name of the callback funtion
  • format (optional): per default, the response is always in JSON format. Per default, a limited set of attributes are returned (notably a label attribute containing a html tag). ‘raw’ returns all the available properties of the selected feature(s) as well as their geometries
  • no_geom (optional): defines if the geometry is returned. ‘true’ means that the geometry is sent back. ‘false’ means that only the bbox is sent back (apply only when raw format is requested)
  • services (optional): Comma sepatared list of services to search in. Current possible values are: ‘cities’, swissnames’, ‘districts’, ‘cantons’, ‘postalcodes’, ‘parcel’ and ‘address’. The later is only for the federal administration, due to restrictions imposed by the cantons. Default is to search in all services except ‘parcel’
  • layers (optional): Comma separated list of layer technical names.

The service returns a maximum of 20 results.

Services in use:

  • cities: communes
  • swissnames: all toponymes as printed on the national maps
  • districts: the swiss districts (not all cantons have districts)
  • postalcodes: ZIP code from swiss Post
  • adress: from the register for buildings and dwellings (BFS)
  • parcel: cadastral information provided by the cantons. A parcel is identified by a city name and a parcel id (or eventually by a BFS city number and a parcel id)
  • attributes: in order to search within attribute information of a layer

Examples:

Note: In French, search for “leopold robert”, not only for “robert”

Result

A JSON content is sent back with the following content:

  • service: the name of the service. It can be postalcodes, cantons, cities, swissnames or address
  • label: html content presented in the Swissearch widget (apply only when html format is requested)
  • egid (optional): EGID number for an address
  • bbox: array with bottom right and top lef coordinate, for example: [509317.96875, 160040.0, 516755.0, 171050.0]
  • id: id of the feature in the database
  • objectorig (optional): defined for swissnames features the origin of the information. Possible values: ‘LK25’, ‘LK50’ or ‘LK100’.
  • layer (optional): indicate in which technical layer the feature has been found
  • all properties (apply only when raw format is requested)

SwissSearch: reversegeocoding

Swisssearch reverse geocoding allows the user to search for swiss locations, like postcode, cantons, cities and swissnames based on a coordinate.

Input parameters

The following parameters are required:

  • lang: optional lang: de (default) or fr
  • easting: the Y position in CH1903 coordinate system
  • northing: the X position in CH1903 coordinate system
  • tolerance: optional spatial tolerance for the search. Default: 10 [m]
  • cb (optional): the name of the callback funtion
  • format(optional): per default, the response is always in JSON format. Per default, a limited set of attributes are returned (notably a label attribute containing a html tag). ‘raw’ returns all the available properties of the selected feature(s) as well as their geometries
  • no_geom (optional): defines if the geometry is returned. ‘true’ means that the geometry is sent back. ‘false’ means that only the bbox is sent back (apply only when raw format is requested)
  • services (optional): Comma sepatared list of services to search in. Current possible values are: ‘cities’, swissnames’, ‘districts’, ‘cantons’, ‘postalcodes’, ‘parcel’ and ‘address’. The later is only for the federal administration, due to restrictions imposed by the cantons. Default is to search in all services

Note: The swiss cantons only allow websites of the federal governement to use the addresses search service.

The service returns a maximum of 50 results.

Examples:

Result

Per default, a JSON content is sent back with the following content:

  • service: the name of the service. It can be postalcodes, cantons, cities, swissnames, districts, address or parcel
  • label: html content
  • bbox: array with bottom right and top lef coordinate, for example: [509317.96875, 160040.0, 516755.0, 171050.0]
  • id: id of the feature in the database
  • bfsnr (optional): the city, district or canton number provided by the BFS (also for parcel)
  • code (optional): for service cantons, the shortname for the cantons
  • nr (optional): for service postalcodes, the postalcode
  • objectorig: defined for swissnames features the origin of the information. Possible values: ‘LK25’, ‘LK50’ or ‘LK100’.

Feature: [id]

This service allows to search for a feature ID stored in the spatial data infrastructure.

Input parameters

The following parameters are required:

  • layer: searchable layer
  • cb (optional): the name of the callback funtion
  • no_geom (optional): defines if the geometry is returned. ‘true’ means that the geometry is sent back. ‘false’ means that only the bbox is sent back. Default: False
  • format (optional): per default, it returns GeoJSON. ‘html’ returns all the properties in HTML format.

Example: https://api.geo.admin.ch/feature/6644?layer=ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill&cb=Ext.ux.JSONP.callback

Result

A GeoJSON representation of the found feature.

Feature: bbox

This service allows to obtain the bbox of the searched features.

Input parameters

The following parameters are required:

  • lang (optional): de (default) or fr (there is no description of layers in other language available in geoadmin for now)
  • layer: searchable layer
  • ids: comma separated list of feature id
  • cb (optional): the name of the callback function

Example: https://api.geo.admin.ch/feature/bbox?layer=ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill&ids=6644&cb=Ext.ux.JSONP.callback

Result

A GeoJSON representation of the found features.

Feature: geometry

This service allows to obtain the geometry of the searched features.

Input parameters

The following parameters are required:

  • lang (optional): de (default) or fr (there is no description of layers in other language available in geoadmin for now)
  • layer: searchable layer
  • ids: comma separated list of feature id
  • cb (optional): the name of the callback funtion

Example: https://api.geo.admin.ch/feature/geometry?layer=ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill&ids=6644&cb=Ext.ux.JSONP.callback

Result

A GeoJSON representation of the found features.

Layers

This service allows to obtain diverse information about the layers in the bod.

URL

https://api.geo.admin.ch/layers https://api.geo.admin.ch/layers/{id} or https://api.geo.admin.ch/layers/{id},{id},{id} (a comma creates a list of layers)

Input parameters

The following parameters are required:

  • lang (optional): de (default) or fr (there is no description of layers in other language available in geoadmin for now)

  • project (optional): (default to all) name of the project in which you desire to look for properties (a comma creates a list of projects)

  • query (optional): a query string for the full text search

  • properties (optional): (default to all) properties you wich to return (a comma creates a list of properties)

  • layer (optional): layer you want to return (a comma creates a list of layers)

  • cb (optional): the name of the callback function

  • mode (optional): (default to no mode) a mode is defined whenever a particular template is required. The following 4 modes are available:

    • bodsearch: this mode requires the definition of query string, all the other parameters can be used

    • legend: returns the legend of a layer, only one layer id must be provided

    • wmts: returns a GetCapabilities document which provides information about the service along with a description of the layers

    • preview: returns per default a preview of all the layers in separated and syncronized frames. In conjunction with this mode, the following optional parameters are available:

      • width (optional): define the width of the map previews
      • lon,lat (optional): define the central point of the map
      • zoom (optional): define the zoom level

Examples:

Profile.json

This service allows to obtain elevation information for a polyline. Note: this service is not freely accessible (fee required).

Input parameters

The following parameters are required:

  • geom: GeoJSON representation of the polyline (type = LineString)
  • elevation_models (optional): comma separated list of elevation models. Three elevation models are available DTM25, DTM2 (swissALTI3D) and COMB (a combination of DTM25 and DTM2). Default: DTM25
  • nb_points (optional): number of points used for the polyline segmentization. Default: 200
  • cb (optional): the name of the callback funtion
  • offset (optional): offset value (int) for using the exponential moving average algorithm (http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average). For a given value, the offset value specify the number of values before and after used to calculate the average.

Example: https://api.geo.admin.ch/profile.json?geom={“type”%3A”LineString”%2C”coordinates”%3A[[550050%2C206550]%2C[556950%2C204150]%2C[561050%2C207950]]}

Result

A JSON, with a “profile” root:

  • alts: an object containing the elevation [m] obtained from the elevation model
  • dist: distance [m] from the first vertex of the polyline
  • easting: the Y position in CH1903 coordinate system
  • northing: the X position in CH1903 coordinate system

Profile.csv

This service allows to obtain elevation information for a polyline in CSV format. Note: this service is not freely accessible (fee required).

Input parameters

The following parameters are required:

  • geom: GeoJSON representation of the polyline (type = LineString)
  • elevation_models (optional): comma separated list of elevation models. Three elevation models are available DTM25, DTM2 (swissALTI3D) and COMB (a combination of DTM25 and DTM2). Default: DTM25
  • nb_points (optional): number of points used for the polyline segmentization. Default: 200
  • offset (optional): offset value (int) for using the exponential moving average algorithm (http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average). For a given value, the offset value specify the number of values before and after used to calculate the average.

Example: https://api.geo.admin.ch/profile.csv?geom={“type”%3A”LineString”%2C”coordinates”%3A[[550050%2C206550]%2C[556950%2C204150]%2C[561050%2C207950]]}

Result

A csv file with the distance, easting and northing information. One column per elevation model is provided.

Height

This service allows to obtain elevation information for a point. Note: this service is not freely accessible (fee required).

Input parameters

The following parameters are required:

  • easting: the Y position in CH1903 coordinate system
  • northing: the X position in CH1903 coordinate system
  • elevation_model (optional): elevation model. Three elevation models are available DTM25, DTM2 (swissALTI3D) and COMB (a combination of DTM25 and DTM2). Default: DTM25
  • cb (optional): the name of the callback funtion

Example: https://api.geo.admin.ch/height?easting=600000&northing=200000

Result

A JSON containing the height information.

Shorten

This service allows to shorten an URL.

Result

The short link (for example: https://s.geo.admin.ch/0baf08b)

Shorten.json

This service allows to shorten an URL.

Input parameters

The following parameter is required:

Note: Only url from domain admin.ch are supported.

Example: https://api.geo.admin.ch/shorten.json?cb=callback&url=http%3A%2F%2Fmap.geo.admin.ch%2F%3FY%3D660000%26X%3D190000%26zoom%3D1%26bgLayer%3Dch.swisstopo.pixelkarte-farbe%26lang%3Den

Result

A JSON with a shorturl

Shorten: decode

This service allows to decode a shortened URL identified by 7 characters.

Input parameters

No input parameters

Example: https://api.geo.admin.ch/shorten/6a9bc34

Result

Redirects to the unshortened URL

WMTS

A RESTFul implementation of the WMTS OGC standard. For detailed information, see See WMTS OGC standard

GetCapabilities

The GetCapabilites document provides informations on the service, along with layer description, both in german and french.

http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml or https://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml

http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml?lang=fr or https://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml?lang=fr

Parameters

Only the RESTFul interface ist implemented. No KVP and SOAP.

A request is in the form:

<protocol>://<ServerName>/<ProtocoleVersion>/<LayerName>/<Stylename>/<Time>/<TileMatrixSet>/<TileSetId>/<TileRow>/<TileCol>.<FormatExtension>

with the following parameters:

Parameter Example Explanation
Protocol http ou https  
ServerName wmts[0-4].geo.admin.ch  
Version 1.0.0 WMTS protocol version
Layername ch.bfs.arealstatistik-1997 See the WMTS GetCapabilities document.
StyleName default mostly constant
Time 2010, 2010-01 Date of tile generation in (ISO-8601). Some dataset will be updated quite often.
TileMatrixSet 21781 (constant) EPSG code for LV03/CH1903
TileSetId 22 Zoom level (see below)
TileRow 236  
TileCol 284  
FormatExtension png Mostly png, except for some raster layer (pixelkarte and swissimage)

The <TileMatrixSet> 21781 is as follow defined:

MinX              420000
MaxX              900000
MinY               30000
MaxY              350000
TileWidth            256

With the <tileOrigin> in the top left corner of the bounding box.

Resolution [m] Zoomlevel Map zoom Tile width m Tiles X Tiles Y Tiles Scale at 96 dpi
4000 0   1024000 1 1 1  
3750 1   960000 1 1 1  
3500 2   896000 1 1 1  
3250 3   832000 1 1 1  
3000 4   768000 1 1 1  
2750 5   704000 1 1 1  
2500 6   640000 1 1 1  
2250 7   576000 1 1 1  
2000 8   512000 1 1 1  
1750 9   448000 2 1 2  
1500 10   384000 2 1 2  
1250 11   320000 2 1 2  
1000 12   256000 2 2 4  
750 13   192000 3 2 6  
650 14 0 166400 3 2 6 1 : 2‘456‘694
500 15 1 128000 4 3 12 1 : 1‘889‘765
250 16 2 64000 8 5 40 1 : 944‘882
100 17 3 25600 19 13 247 1 : 377‘953
50 18 4 12800 38 25 950 1 : 188‘976
20 19 5 5120 94 63 5‘922 1 : 75‘591
10 20 6 2560 188 125 23‘500 1 : 37‘795
5 21 7 1280 375 250 93‘750 1 : 18‘898
2.5 22 8 640 750 500 375‘000 1 : 9‘449
2 23 9 512 938 625 586‘250 1 : 7‘559
1.5 24   384 1250 834 1‘042‘500  
1 25 10 256 1875 1250 2‘343‘750 1 : 3‘780
0.5 26 11 128 3750 2500 9‘375‘000 1 : 1‘890
0.25 27 12 64 7500 5000 37‘500‘000 1 : 945
0.1 28 13 32 15000 10000 150‘000‘000 1 : 378

Notes

  1. The zoom level 24 (resolution 1.5m) has been generated, but is not currently used in the API.
  2. The zoom levels 27 and 28 (resolution 0.25m and 0.1m) are only available for a few layers, e.g. swissimage or cadastral web map. For the others layers it is only a client zoom (tiles are stretched).

Usage Example

Click here to center the map at your current location
Show code

OWSChecker: check conformity with ech-0056

This service check the conformity of various OGC services with the swiss ech-0056 profile. See OWSChecker Documentation for more details.

Input parameters

  • base_url: url of service to test (mandatory)
  • service: type of service to test, one of WMS, WFS, WMTS, WCS or CSW (mandatory)
  • ssurl: server setting url (optional)
  • restful: restful-only service (optional)

Result

A JSON file containing all the tests and their status.

GcSearch: metadata access

GcSearch (Geocat Search) allows the user to access the layers stored in GeoCat.

Input parameters

The following parameters are required:

  • lang: optional lang: de or fr
  • query: the query string to find (mandatory if egid is not transmitted)
  • cb: (optional) the name of the callback function (JSON or JSONP)
  • keyword: the word to look for in the abstract of the layer

Examples: https://api.geo.admin.ch/main/wsgi/gcsearch/search?query=wasser&lang=de&keyword=wasser

Result

A JSON content is sent back with the following content

  • resolution_distance: the resolution of the map
  • extent: the extent of the layer
  • downloads: where to download the layer
  • web_links: the web link where you can find extra inforamtion about the layer
  • alternate_title: the layer can possess an alternative title
  • date: date of the publication in Geocat
  • data_provider: the provider of the layer
  • legal_constraints: define under which legal constraints the layer is accessible
  • id: the geocat identification number of the layer
  • name: the title of the layer in geocat
  • copyright: the name of the copyright
  • thematic_geoportals: define on which geoportal the layer appears
  • equivalent_scales: the scale of the layer
  • data_provider_link: the URL of the dataprovider
  • copyright_link: the URL related to the copyright
  • abstract: a short description of the layer