Pt-br:Xapi

From OpenStreetMap Wiki
Jump to: navigation, search
Help
Available languages
English

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.

Pesquisas no Mapa

The Map query is identical to the main API map query and returns:

GET /api/0.6/map?bbox=left,bottom,right,top

where:

Exemplo

http://www.informationfreeway.org/api/0.6/map?bbox=11.54,48.14,11.543,48.145

Notas


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:

The union operator can also be used with the key. For example to select golf courses:

A wildcard can be used for the value (but not for the key), so predicates similar to the following examples are possible:

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:

Notes:

  1. If using wget then parenthesis characters need to be escaped, so for negation predicates, use [not\(way\)] rather than [not(way)].
  2. 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.

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:

Limitações

Veja também

Personal tools
Namespaces
Variants
Actions
site
Toolbox