The Database API

From University Map Wiki
Jump to navigationJump to search

Please read Terms and conditions, Copyright, Fair Use, etc. if you are going to use this API.

Introduction

The same information as provided by the The Map URL API is provided in machine readable form using URLs like this:

 http://map.cam.ac.uk/v5.json?q=search[&partial=yes]
 http://map.cam.ac.uk/v5.json?bb=boundingbox&z=zoom
 http://map.cam.ac.uk/v5.json?ref=ref
 http://map.cam.ac.uk/v5.json?inst=inst

with the same interpretation as in The Map URL API (note that one=list is not relevant in the q= and bb= variants, and the simple name variant is not available to the API - just use http://map.cam.ac.uk/v5.json?q=name).

An additional option ?limit=limit is also available on the ?q and ?bb forms which limits the number of results returned to the number given. For example

 http://map.cam.ac.uk/v5.json?q=saint&limit=15

Values of query parameters, such as ?q= are limited to 2,000 characters. For ?inst= and ?ref= queries, a maximum of 25 may be requested at once (separating the requested codes with '|').

Also, there is another query type available to the database API not available when using a consumer URL. ?alpha=letter will provide an alphabetically ordered listing of the entire index for that letter. This is used as the basis for the directory page and other alphabetic listings. Please cache the results of this search so that it does not place an unwarranted load on the database. You can also filter by type, for example:

 http://map.cam.ac.uk/v5.json?alpha=s&filter=college

The 'v5' is a version number, allowing for potential backward compatibility if we change the spec at some point in the future. Only v5 is recognised for now.

The 'json' part indicates the results are provided in JSON format. We may produce other formats in future, in which case URLs such as http://map.cam.ac.uk/v5.xml?... would be introduced, but for the time being, only JSON is supported.

The result is a JSON array:

[ { "type": type0, ... }, { "type": type1, ... }, ... ]

where each object in the array is an entity matching the request. If there are no results, an empty array is produced. If there is only one result, it is still provided as an array (of one object), not as just the object. Note also that requests by inst and ref may also yield more than one result. For inst, this reflects an institution's multiple locations and for entrances this reflects an alternate entrance (for example, some residence staircases have access on both sides of a building).

The content of the rest of each object depends on:

  • type
  • what information is available for each result
  • whether the request was a search (q=... or name) or direct look up (ref or inst URLs)

type is one of:

error
institution
site
college

building
entrance

nonuniversity
street
more

Error reports

If type is error, then the http request will also return an appropriate status code, typically 400 indicating the request is malformed (wrong combination of query parameters, for example) or 404 (api version or format not implemented for example). The consumer should also be prepared to handle other HTTP errors generated by the server which will not provide JSON data (500 for example). Apart from these, all correctly formed requests will generate status 200. Note that this includes requests with no results (which produce an empty array).

Note also that if you mis-spell 'v5.json' (for example, say you incorrectly use a capital V), then the URL may be interpreted as the end-user form M:/name so you would get a stream of HTML!

Entity structure

Contents of JSON objects representing entities found are as follows, by type.

In general, each request includes information about things linked to each result: the buildings for an institution, the entrances to a site and so on. This referencing only applies one level deep: those parts are excerpted: they do not themselves contain further entities to which they refer. If you need these, you would have to request the content by ref or inst from the parent. The fields omitted in the second level are indicated with an asterisk in the tables that follow.

error

key value   notes
type error    
code the HTTP status code int  
error text describing the error string  

more

key value   notes
type more           When the number of results is limited by ?limit=limit, the last element in the array of results may indicate "more", that there are more results that could be found but the limit was reached. Because certain results are redacted in some circumstances, note that the number of elements in the array may be fewer than limit+1 even if the limit is reached. "more" is not included if all the available results are returned. There isn't any way to page through the results: the search needs to be made more specific.

institution

key value   notes
type institution    
inst the institution code of the entity string  
role kind of institution

string, one of:
college
academic
admin
nonacademic
mrc
library
museum

lecture
 
prefix the name prefix string for example, 'Department of', 'Centre for'
name the substantive part of the institution name string for example, 'Geography'. This is the field to sort on for alphabetically ordered institutions
suffix the name suffix string often an acronym or former name, which would often be presented in parentheses. For example, when name is 'Advanced Photonics and Electronics', prefix is 'Centre for ' and suffix would be 'CAPE'. The whole might be presented as 'Advanced Photonics and Electronics (CAPE), Centre for' or 'Centre for Advanced Photonics and Electronics (CAPE)'
parent* when the entity is subsidiary to another, this is the name of the parent entity entity for example the faculty of a department
locations* information about the geographical buildings or sites associated with the institution array of building/site/college objects

Each location is a further object of the appropriate type, but with a subset of the information (for example, it doesn't contain institutions - see note above).
For example [ { "lat": 52.2103, "lon": 0.1234, "ref": "SEL", "name": "Selwyn College", "primitive": "w", "id": 1234567 } ]

entrances* information about the entrances (to site and buildings) associated with the institution array of entrance objects similar to locations
zoom suggested zoom level at which the entity would be best presented (on its own) int  
options arbitrary space separated tokens indicating arbitrary options string  
sd the subdomain of the entity string e.g. "lucy-cav"
info contact information (etc) array of objects (see below)

for example:

[
  { "type": "address", "address": [
    {"type": "street", "street": "St Andrew's Street"},
    {"type": "place", "place": "Cambridge"},
    {"type": "postcode", "postcode": "CB2 3BU"}],
  { "type": "phone", "phone": "+44 1223 334900" },
  { "type": "fax", "fax": "+44 1223 334901" },
  { "type": "phone", "phone": "+44 1223 334902", "role": "Porter's Lodge"},
  { "type": "email", "email": "admissions@christs.cam.ac.uk" }
  {"type": "url", "url": "http://www.christs.cam.ac.uk/" },
  {"type": "url", "url": "http://www.cam.ac.uk/admissions/undergraduate/colleges/christs/", "role": "Undergraduate Prospectus Entry" },
  {"type": "founded", "founded": "1870" }
]

Note that all this contact information relates to the entity concerned. Subordinate entities will have their own contact information if relevant.

sortasvia when result matched via an AKA field (see below) or from a role, the index of the info element which it matched against integer

Fields common to all geographical objects

The remainder are all geographical objects and share the following common fields:

key value   notes
type      
ref the reference of the entity string e.g. "H/FORVIE"
name the name of the entity (assuming it has one) string e.g. "Forvie Site", "Austin Building"
lat the latitude of a representative position of the entity float  
lon the longitude of a representative position of the entity float  
zoom suggested zoom level at which the entity would be best presented (on its own) int  
primitive whether the building was dericved from an OSM way ("w") or node ("n") string (either "w" or "n") primitive and id can be used together to form a link to the OSM browser, as in http://osm.org/browse/way/1234567
id the OSM id of the node from which the entrance was derived int

sites are always areas (ways) in OSM

 

site

key value   notes
type site    
parent* when the site is a sub-site, this is the main site site object for example object for "Cambridge Biomedical Campus" when name is "Forvie Site"
entrances* to the site array of entrance objects see above

college

key value   notes
type college   This is the geographical entity for a college site or sub-site, not the institutional information which is an inst. This is very similar to site.
parent* when the college item is a subsidiary site, the main site college object e.g. object for "Magdalene College" when site is ref MAGD/CRIPPS
entrances* as for inst array of entrance objects

see above

 
institution* the institution information associated with this college area institution object  

building

key value   notes
type building    
parent* site/college in which the building is situated site/college object  
entrances* entrances of the building array of entrance objects see above
occupants* occupants of the building array of institution objects  

entrance

key value   notes
type entrance   entrances apply to sites and colleges as well as buildings. Note, entrances are always derived from OSM node entities.
parents* buildings and/or sites/colleges to which this entrance gives access array of building/site/college objects note that a few entrances give access to university properties on either side; also occasionally an entrance to a building isn't actually part of the building footprint.
occupants* institution codes of the institutions that gain access by this entrance array of string e.g. ["met", "cs"]. OK, you don't exactly "occupy" an entrance, but consistent with buildings
direction the direction of a normal to the parent building/site/college at an entrance, in degrees between -180 and 180 measured anticlockwise from the east (positive x axis) pointing away from the building float the direction can be used to orient an overlaid arrow pointing to the entrance.
user some or all of the letters "fbvg" string standing for "foot", "bicycle", "vehicle" and "goods" respectively, indicating the class or classes of users which can use the entrance.
door   boolean whether this entrance is the door to a buiulding (true) or a gate to a site (false)

nonuniversity

key value   notes
type nonuniversity    
role what kind of thing this is string e.g. "hotel"

street

key value   notes
type street   no additional fields other than the common ones

Contact information

Contact information for institutions and colleges is grouped into an array of items each of which may be repeated and qualified as necessary. For example, multiple phone numbers with descriptions of what each is for. Note that these all relate to the entity concerned. Subordinate entities will have their own contact information if relevant, so addresses, phone numbers etc. for child institutions should not be given as alternate addresses within the same info array.

key value  
person string primary contact named individual, for example "Prof. John Doe".
description string A brief description of the function of the institution
title string primary contact title, for example "The Bursar", where useful for more personal addressing.
address array of objects (see below)

what the address is for, assumed to be the primary address if not described.

phone string in the international form +44 1223 33nnnn
fax string ditto
email string  
url string complete, including the http://
founded int (colleges only) year of foundation
logo string url of image which is used to brand the institution
twitter string  
facebook string  
AKA string

another name or search term by which the institution is known. Unlike other info fields, the value of this info item is (usually) added to the search index.

This may be used in different ways according to the accompanying options. An "xm" option excludes the entry from the paper map (this might be a very old name, for example, which you want search results to hit, but not include in an up-to-date static map). "xw" excludes it from the web site searches and presentation, but includes it in the paper map and other alphabetic listings. "xd" excludes it from presentation (the user doesn't see it), but includes it in the index.

Additionally when a ?q returns a result via a match on an AKA, the top level structure contains 'viaaka', the index of the info element which it matched against. This is so that you can tell the user if you want to why their search matched when it doesn't appear to match the main entry name.

Contact information qualifiers

Each of these objects contains a type to identify the key, and may also contain other qualifying information, as follows:

key value  
type one of the keys listed in the previous table
role string description of what the contact information will be used for. If omitted, assumed to be the primary contact information of this type. For URLs this would typically be used for the link text rather than displaying the URL itself. For others it would serve as a caption. 
options string arbitrary space separated string of options (meanings client dependent)

Addresses

Addresses are further subdivided so that they can be presented linearly, in "label" form or as a VCARD etc, by combining the elements with suitable punctuation and markup, and also cross-linked where appropriate - for example the street element could be linked with the URL http://www.cam.ac.uk/streetname to jump to the map for the street name. These should be used in order when presenting an address.

Each element contains a type field whose value is one of the keys in the following table, and then a key/value pair according to the type, as follows:

key value  
location int a number indicating that this address refers to the corresponding location in the list of locations. Not all addresses need refer to a location (e.g. a PO Box), and not all locations need have a corresponding address. But when they do, the correspondence may be used to disambiguate locations occupied by the institution. Numbering starts at 1, not zero!
maildrop string for parts of an address such as a room number or a PO Box number
building string name of building
number string location on a street, e.g. "42a"
site string e.g. "Lords Bridge", "New Museums Site"
street string e.g. "Downing Place"
street2 string occasionally a second street is part of the address
smallplace string where place is a local village
place string usually "Cambridge"
county string rarely needed
postcode string  
address string the complete address laid out linearly, only provided in the absence of all of the other fields to allow for addresses which have not been structured yet 

Some examples:

  • Hamilton Kerr Institute:
    [ {"type": "street", "street": "Mill Lane"},
     {"type": "smallplace", "smallplace": "Whittlesford"},
     {"type": "place", "place": "Cambridge"},
     {"type": "postcode", "postcode": "CB22 4NE"} ]
  • Division of Anaesthesia
    [ {"type": "maildrop", "maildrop": "Box 93"},
     {"type": "maildrop", "maildrop": "Level 4"},
     {"type": "site", "site": "Addenbrooke's Hospital"},
     {"type: "street, "street: "Hills Road"},
     {"type": "place", "place": "Cambridge"},
     {"type": "postcode", "postcode": "CB2 2QQ"} ]
  • Department of Anglo-Saxon, Norse and Celtic
    [ {"type": "number", "number": "9"},
     {"type: "street, "street: "West Road"},
     {"type": "place", "place": "Cambridge"},
     {"type": "postcode", "postcode": "CB3 9DP"} ]
  • Cambridge Centre for Brain Repair
    [ {"type": "building", "building": "E. D. Adrian Building"},
     {"type": "site", "site": "Forvie Site"},
     {"type": "street", "street": "Robinson Way"},
     {"type": "place", "place": "Cambridge"},
     {"type": "postcode", "postcode": "CB2 0PY"} ]

Coordinates

There are very few real-world coordinates in the database (it doesn't, for example, include building outlines). But this information is available from the OSM API by reference to the OSM id in the 'id' field of all geographic entities.

For building outlines, the OSM API supports:

 http://osm.org/api/0.6/way/<ID>
 http://osm.org/api/0.6/way/<ID>/full
 http://osm.org/api/0.6/way/<ID>/relations

Note however that a building doesn't have to be just a single closed way, since it can have have holes in the area. These are handled as OSM "multipolygons". In essence, there is an outer way plus a number of inner ways

For example, Churchill West Court (ref CHU016, http://preview.map.cam.ac.uk/v5.json?ref=CHU016&debug=1). The Map API tells you it is a way with id 148247888 and you can plug it into the OSM API thus

 http://www.openstreetmap.org/api/0.6/way/148247888/full

returning

<osm version="0.6" generator="OpenStreetMap server">
<node id="1613469175" lat="52.2128314" lon="0.1013427" version="1" changeset="10553242" user="davidearl" uid="3582" visible="true" timestamp="2012-01-31T20:37:02Z"/>
<node id="1613469065" lat="52.2127198" lon="0.101803" version="1" changeset="10553242" user="davidearl" uid="3582" visible="true" timestamp="2012-01-31T20:36:58Z"/>
...
<nd ref="1613469175"/>
<nd ref="1613469065"/>
...
<tag k="amenity" v="university"/>
<tag k="building" v="yes"/>
<tag k="name" v="West Court"/>
<tag k="operator" v="Churchill College (University of Cambridge)"/>
<tag k="ref" v="CHU016"/>
</way>
</osm>

and http://www.openstreetmap.org/api/0.6/way/148247888/relations gets

<osm version="0.6" generator="OpenStreetMap server">
<relation id="1999559" visible="true" timestamp="2012-01-31T20:40:32Z" version="1" changeset="10553242" user="davidearl" uid="3582">
<member type="way" ref="148247888" role="outer"/>
<member type="way" ref="148248147" role="inner"/>
<tag k="type" v="multipolygon"/>
</relation>
</osm>

telling you it is a multipolygon outer, and giving the info to traverse to the inner as above.