Pt-br:Xapi
Página ainda em tradução.
A API Extendida OSM, ou em inglês 'OSM Extended API' (ou xapi, pronunciada 'zappy') é uma API somente-leitura, baseada em uma versão modificada da API padrão, que provê melhorias nas capacidades de busca e pesquisa. Ela implementa as requisições-padrão de mapas e um número adicional de maneiras de buscar dados no OSM através dos valores das tags.
A base de dados é um espelho da base principal, e é atualizada através dos dumps da base uma vez por minuto.Os dados normalmente não estão mais do que 10 minutos atrasado se em comparação com a base principal.
Xapi uses a REST style interface with X-path flavouring.
All responses are in the same format as the standard protocol but with the addition of some namespaced extensions. Tag queries use an X-path like syntax to specify search terms.
Contents |
Servidores
There are multiple instances of the xapi service running on several different servers. Each server can be accessed directly or via the informationfreeway redirect which will direct the request to a suitable server of its choosing.
- http://www.informationfreeway.org/api/0.6/... will redirect to a suitable server for the request.
- http://osmxapi.hypercube.telascience.org/api/0.6... is a fast server located in San Diego, but prone to instability (status: online).
- http://xapi.openstreetmap.org/api/0.5... is the standard OSM provided service, but runs on a relatively slow server (status: serving 0.5 cut-off).
- http://osm.bearstech.com/osmxapi/api/0.6/... is a medium capacity virtual machine donated by Bearstech (status: offline).
Pesquisas no Mapa
The Map query is identical to the main API map query and returns:
- All nodes that are inside a given bounding box and any relations that reference them.
- All ways that reference at least one node that is inside a given bounding box, any relations that reference them [the ways], and any nodes outside the bounding box that the ways may reference.
GET /api/0.6/map?bbox=left,bottom,right,top
where:
-
leftis the longitude of the left (westernmost) side of the bounding box. -
bottomis the latitude of the bottom (southernmost) side of the bounding box. -
rightis the longitude of the right (easternmost) side of the bounding box. -
topis the latitude of the top (northernmost) side of the bounding box.
Exemplo
http://www.informationfreeway.org/api/0.6/map?bbox=11.54,48.14,11.543,48.145
Notas
- Unlike the main API which restricts queries to 0.25 square degrees, XAPI allows much larger requests, up to 100 square degrees.
- The map query is functionally identical to the tag query
/api/0.6/*[bbox=left,bottom,right,top]
Pesquisa em Tags
Xapi implements queries for all three kinds of elements; nodes, ways and relations.
Nós
A node request will return an xml document containing nodes and their associated tags. The URL for a node request takes the following form:
http://www.informationfreeway.org/api/0.6/node[...]
This will return a standard OSM API response containing nodes and tags. For example:
<?xml version='1.0' standalone='no'?>
<osm version='0.6' generator='xapi: OSM Extended API'
xmlns:xapi='http://www.informationfreeway.org/xapi/0.6'
xapi:uri='/api/0.6/node[amenity=hospital]'
xapi:planetDate='200803150826'
xapi:copyright='2008 OpenStreetMap contributors'
xapi:instance='zappy2'>
<node id='672180' lat='48.2111685091189' lon='16.3035366605548' timestamp='2006-09-11T16:28:25+01:00' version='1' changeset='10968'>
<tag k='amenity' v='hospital'/>
<tag k='name' v='Wilhelminenspital'/>
</node>
<node id='3596186' lat='53.4633699598014' lon='-2.22667910006381' timestamp='2007-06-21T17:10:58+01:00' version='2' changeset='2213'>
<tag k='amenity' v='hospital'/>
<tag k='name' v='Manchester Royal Infirmary'/>
</node>
...
</osm>
Caminhos
The URL for way requests has the following form:
http://www.informationfreeway.org/api/0.6/way[...]
This returns an xml document containing ways that match the search terms. For each matching way the nodes referenced by that way are also returned. An example of the response from a way query looks like this:
<?xml version='1.0' standalone='no'?> <osm version='0.6' generator='xapi: OSM Extended API' xmlns:xapi='http://www.informationfreeway.org/xapi/0.6' xapi:uri='/api/0.6/way[landuse=residential]' xapi:planetDate='200803150826' xapi:copyright='2008 OpenStreetMap contributors' xapi:instance='zappy2'><node id='218963' lat='52.5611324692581' lon='-1.79024812573334' timestamp='2006-03-22T16:47:48+00:00' version='1' changeset='2211'> </node> <node id='331193' lat='53.7091237972264' lon='-1.50282510180841' timestamp='2007-03-31T00:09:22+01:00' version='1' changeset='2211'> <tag k='highway' v='traffic_signals'/> <tag k='source' v='Yahoo'/> </node> ...<way id='4958218' timestamp='2007-07-25T01:55:35+01:00' version='3' changeset='2211'> <nd ref='218963'/> <nd ref='331193'/> ... <tag k='landuse' v='residential'/> <tag k='source' v='landsat'/> </way> </osm>
Relações
The URL for relation requests has the following form:
http://www.informationfreeway.org/api/0.6/relation[...]
This returns an xml document containing relations that match the search terms. For each matching relation the nodes and ways referenced by that relation are also returned. An example of the response from a relation query looks like this:
<?xml version='1.0' standalone='no'?> <osm version='0.6' generator='xapi: OSM Extended API' xmlns:xapi='http://www.informationfreeway.org/xapi/0.6' xapi:uri='/api/0.6/way[landuse=residential]' xapi:planetDate='200803150826' xapi:copyright='2008 OpenStreetMap contributors' xapi:instance='zappy2'><node ... <way ...<relation id='2670' timestamp='2007-10-25T03:05:34Z' version='32' changeset='2211'> <member type='way' ref='3992472' role=/> <member type='way' ref='3992524' role=/> <member type='way' ref='4253050' role=/> <member type='way' ref='4253053' role=/> <member type='way' ref='4266813' role=/> <member type='way' ref='10285106' role=/> <tag k='name' v='Fonnereau Way'/> <tag k='network' v='Ipswich footpaths'/> <tag k='type' v='route'/> </relation> </osm>
Todos os Elementos
All elements (nodes, ways and relations) that match the given filter predicates can be requested using the following URL:
http://www.informationfreeway.org/api/0.6/*[...]
This returns an xml document containing nodes, ways and relations that match the search terms. For each matching way the nodes and referenced by that way are also returned. Likewise, for each matching relation the ways and nodes referenced by that relation are also returned. An example of the response from this type of query looks like this:
<?xml version='1.0' standalone='no'?>
<osm version='0.6' generator='xapi: OSM Extended API'
xmlns:xapi='http://www.informationfreeway.org/xapi/0.6'
xapi:uri='/api/0.6/*[amenity=hotel]'
xapi:planetDate='200803150826'
xapi:copyright='2008 OpenStreetMap contributors'
xapi:instance='zappy2'>
<node id='218963' lat='52.5611324692581' lon='-1.79024812573334' timestamp='2006-03-22T16:47:48+00:00' version='1' changeset='2211'>
</node>
<node id='331193' lat='53.7091237972264' lon='-1.50282510180841' timestamp='2007-03-31T00:09:22+01:00' version='1' changeset='2211'>
<tag k='amenity' v='hotel'/>
</node>
...
<way id='4958218' timestamp='2007-07-25T01:55:35+01:00' version='1' changeset='2211'>
<nd ref='218963'/>
<nd ref='331193'/>
...
<tag k='amenity' v='hotel'/>
<tag k='building' v='hotel'/>
</way>
<relation id='123456' timestamp='2007-10-25T03:05:34Z' version='32' changeset='2211'>
<member type='node' ref='331193' role=/>
<member type='node' ref='331194' role=/>
...
<tag k='amenity' v='hotel'/>
<tag k='operator' v='Premier Inns'/>
<tag k='type' v='operators'/>
</relation>
</osm>
Predicados
Each API request can be suffixed with selection predicates which determine which elements to select. For example [amenity=hospital] will select all elements that have an amenity tag with a value of hospital. The full url to select all nodes that are tagged as hospitals would be:
http://www.informationfreeway.org/api/0.6/node[amenity=hospital]
A request can be suffixed with multiple predicates, each of which further constrains the results (currently limited to one tag predicate and one bbox predicate). For example:
http://www.informationfreeway.org/api/0.6/node[amenity=hospital][bbox=-6,50,2,61]
this request will select and return all nodes with a tag of amenity=hospital within the bounding box that covers the whole of the England, Wales and Scotland.
Predicados de Tag
A selection predicate must be of the form [key=value]. For example: node[amenity=hospital] will match any node that has an amenity key with a value of hospital, ie <tag k="amenity" v="hospital"/>.
A union operator may be used to select multiple values. For example to select all major roads:
-
way[highway=motorway|motorway_link|trunk|primary]
The union operator can also be used with the key. For example to select golf courses:
-
node[amenity|leisure=golf_course]
A wildcard can be used for the value (but not for the key), so predicates similar to the following examples are possible:
-
way[construction=*] -
way[highway=*]
Key wildcards were supported in the past, but this is no longer maintained.
Note: The URL needs to be UTF-8 url encoded in case of non-ascii characters.
Predicado de BBox
Another form of selection predicate is the bbox pseudo key. A selection predicate of the form [bbox=left,bottom,right,top] defines a bounding box that is used to limit the extent of the result document. Only elements that have some part within the bbox will be included in the result document.
Unlike the standard OSM API, the bbox predicate is not limited in size unless it is used without a tag predicate, in which case it is limited to 100 square degrees.
The default extent, if a bbox predicate is not specified, is the whole planet. This is equivalent to specifying [bbox=-180,-90,180,90].
Predicado de elemento-filho
Items can be selected based on whether or not they have child elements. For example, ways can be selected that do not have any tags or do not have any nodes. This is achieved by using an XPath-like element test. Specifically the following are implemented:
-
/api/0.6/way[nd]- selects ways that have at least one node -
/api/0.6/way[tag]- selects ways that have at least one tag -
/api/0.6/way[not(nd)]- only selects ways that do not have any nodes -
/api/0.6/way[not(tag)]- only selects ways that do not have any tags -
/api/0.6/node[way]- selects nodes that belong to at least one way -
/api/0.6/node[not(way)]- selects nodes that do not belong to any way -
/api/0.6/relation[node]- selects relations that have at least one node member -
/api/0.6/relation[way]- selects relations that have at least one way member -
/api/0.6/relation[relation]- selects relations that have at least one relation member -
/api/0.6/relation[not(node)]- selects relations that do not have any node members -
/api/0.6/relation[not(way)]- selects relations that do not have any way members -
/api/0.6/relation[not(relation)]- selects relations that do not have any relation members
Notes:
- If using wget then parenthesis characters need to be escaped, so for negation predicates, use
[not\(way\)]rather than[not(way)]. - In the OSM xml schema nodes do not really have ways as child elements. However, there is, logically, a many-to-many relationship between nodes and ways, and so xapi implements this relationship and enables nodes to be selected based on whether or not they are members of a way. Of course, the output xml is the same as normal and does not include way elements within a node element.
Tags
The main method of querying Xapi is using a tag/value combination in a predicate. In addition to all the normal tags that you expect to find, Xapi stores a number of pseudo-tags that may be useful. They are all stored in the osm: tag namespace to avoid conflict with other tags.
- osm:user - when an element has a user attribute this is stored as the pseudo tag osm:user.
- osm:users - a list of all users who have made edits to an element (edits predating the 0.5 API are not included)
- osm:timestamp
Modo de usar
Xapi URLs can be used from within any web-browser, however a simple query can return several Mb of data which can overwhelm some browsers. It is recommended that a tool such as wget or curl be used with the output directed to a file. For example, the following command uses wget to select all hospitals and store the result document in a file named data.osm:
$ wget http://www.informationfreeway.org/api/0.6/node[amenity=hospital] -O data.osm
Note: If you use curl, it will handle redirections automatically, so you need to query the host server directly or use the "--location" option. Also you need to use the "--globoff" option, otherwise it will try to interpret the brackets ("[", "]") as part of the command line:
$ curl --location --globoff http://www.informationfreeway.org/api/0.6/node[amenity=hospital] -o data.osm
If you use a script regularly to fetch data from Xapi it would be helpful to set the user agent string to something meaningful. This will help us understand more about how Xapi is being used.
Estatísticas
There are some stats about the contents of the xapi database here: http://osmxapi.hypercube.telascience.org/total.xml. These get updated once a day.
RSS Feed
The Xapi RSS feed provides a list of changes to elements that have been tagged by a user to be watched.
Any element tagged with watch:yourUserId=1 (or yes or true) will be monitored by Xapi and any changes to this element, including deletion, will be shown in the feed. Watched nodes can be grouped into categories by setting the value of the watch tag to the name of a category. For example: watch:80n=churches will add an element to a watchlist category called churches.
To remove an element from your watchlist simply delete the tag from the element.
You can subscribe to your watch list using the following url:
http://www.informationfreeway.org/api/0.6/watch/yourUserId
For example:
http://www.informationfreeway.org/api/0.6/watch/80n
To subscribe to a specific watch category append the URL with the name of the category. For example:
http://www.informationfreeway.org/api/0.6/watch/80n/churches
Notes:
- Anyone can subscribe to your watch list. You can subscribe to anyone's watch list.
- Currently the watch tag is only implemented for nodes.
- This is experimental, there may be significant changes.
- Here's the clever bit: Adding or deleting a watch tag for another user will have no effect. The watch tag for another user can be edited but it will not add or remove that item from that user's watch list. Only edits by the user that owns the watch list will control their watch list.
Limitações
- Created_by tags. These tags are generally un-interesting and have been suppressed to improve performance.
- Predicates. Currently each request is limited to one tag predicate and one bbox predicate. In the future it is hoped that more sophisticated conditions will be implemented. Multiple bboxes would be great for applications like GpsMid - they already implemented data retrieval over xapi in Osm2GpsMid for single regions which is very helpful.
- Request grammar. The request grammar is not formally defined and is not processed using a proper parser, so malformed requests may have unpredictable results. Caveat Emptor.
- user. The planet.osm dump does not contain user information, but the diff files do. Where available the user attribute is returned for each element. A history of user names is also being built so that an attribution list of all users who have edited an element is provided in the
xapi:userstag. This will be complete for all changes since the database was last re-synchronised from a complete planet.osm file. This last happened on March 12, 2008.
Veja também
- OSM Protocol Stack
- API v0.6
- Xapi source code uses GT.M a high-performance schemaless database.
- maintained by User:80n