Zh-hans:OSM XML

From OpenStreetMap Wiki
Jump to navigation Jump to search

基础

XML 是一种所谓的元格式,提供给包括人类可识别的数据交互格式。很多文件格式均采用了类似HTML树型结构的格式,例如: SVG, ODT,...

优点 缺点
  • 人类可读,因为清晰的结构
  • 由与精确的定义,可以做到与机器无关,例如:字符集, XML 结构定义, DTD,...
  • 可以使用通用的XML解析器去定制特定的文件格式
  • 良好的压缩率
  • 非常巨大的文件
  • 需要解压后使用
  • 解析文件需要花费很长时间

OSM XML文件样式注意点

OSM领域的主要工具使用一种首先只被API使用,遵循这个XML样式定义的XML格式。这基本上是一个原始数据(节点路径关系)的实例的列表。

下面是一个缩短的完整的OSM XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
 <bounds minlat="54.0889580" minlon="12.2487570" maxlat="54.0913900" maxlon="12.2524800"/>
 <node id="298884269" lat="54.0901746" lon="12.2482632" user="SvenHRO" uid="46882" visible="true" version="1" changeset="676636" timestamp="2008-09-21T21:37:45Z"/>
 <node id="261728686" lat="54.0906309" lon="12.2441924" user="PikoWinter" uid="36744" visible="true" version="1" changeset="323878" timestamp="2008-05-03T13:39:23Z"/>
 <node id="1831881213" version="1" changeset="12370172" lat="54.0900666" lon="12.2539381" user="lafkor" uid="75625" visible="true" timestamp="2012-07-20T09:43:19Z">
  <tag k="name" v="Neu Broderstorf"/>
  <tag k="traffic_sign" v="city_limit"/>
 </node>
 ...
 <node id="298884272" lat="54.0901447" lon="12.2516513" user="SvenHRO" uid="46882" visible="true" version="1" changeset="676636" timestamp="2008-09-21T21:37:45Z"/>
 <way id="26659127" user="Masch" uid="55988" visible="true" version="5" changeset="4142606" timestamp="2010-03-16T11:47:08Z">
  <nd ref="292403538"/>
  <nd ref="298884289"/>
  ...
  <nd ref="261728686"/>
  <tag k="highway" v="unclassified"/>
  <tag k="name" v="Pastower Straße"/>
 </way>
 <relation id="56688" user="kmvar" uid="56190" visible="true" version="28" changeset="6947637" timestamp="2011-01-12T14:23:49Z">
  <member type="node" ref="294942404" role=""/>
  ...
  <member type="node" ref="364933006" role=""/>
  <member type="way" ref="4579143" role=""/>
  ...
  <member type="node" ref="249673494" role=""/>
  <tag k="name" v="Küstenbus Linie 123"/>
  <tag k="network" v="VVW"/>
  <tag k="operator" v="Regionalverkehr Küste"/>
  <tag k="ref" v="123"/>
  <tag k="route" v="bus"/>
  <tag k="type" v="route"/>
 </relation>
 ...
</osm>

查看Data Primitives了解对象种类的细节。
查看Map features了解真实世界的物体是如何被塑造并分类的。


结构如下:

  • 一个声明了文件使用UTF-8字符编码的XML前缀
  • 一个osm要素,包含API版本(以及因此使用的附件(features))和提取这个文件的转换器(比如一个编辑器
    • 一个节点块,包含在WGS84坐标系统中的位置
      • 每个节点的标签
    • 一个路径
      • 每个路径包含的节点的编号
      • 每个路径的标签
    • 一个关系
      • 每个关系包含的路径的编号
      • 每个关系的标签

查看/XSD/DTD页面for details of attempts to define the format in those languages.

Assumptions

If you develop tools using this format, you can be sure that:

  • blocks come in this order
  • bounds will be on API and JOSM data

You can not be sure that:

  • blocks are there (e.g. only nodes, no ways)
  • blocks are sorted
  • element IDs are non negative (Not in all osm files. Negative ids are used by editors for new elements)
  • elements have to contain tags (Many elements do not. You will even come across Untagged unconnected nodes)
  • visible only if false and not in Planet.osm
  • id or user name present (Not always, due to anonymous edits in a very early stage)
  • Changesets have an attribute num_changes for (This was abandoned from the history export tool because of inconsistencies)
  • version ordering is sequential (doesn't have to be)

JOSM uses an 'action' attribute instead of timestamp, version or changeset for new objects

Some #flavours might have other restrictions.

工具

查看Planet.osm以及ImportExportConvert

Flavours

这里是当前使用的文件格式,都有稍微不同的用途。

JOSM文件样式

主条目:JOSM file format

这个文件格式是由JOSM作者设计的。It basically is a logical extension of the data sent from the server. What it adds is an indication of the origin of the data and the bounding box it comes from (if possible). It is actually more of a storage format of data downloaded along with changes made by the user.

pros cons
  • Supports placeholders
  • Indicates the source of the data
  • not streamable, must read the whole file prior to applying

被以下软件支持:

osmChange

主条目:OsmChange

OsmChange is a file format was created by the author of osmosis and is a more general format for representing changes.

pros cons
  • Streamable

When sorted properly this file is a continuous stream of changes that can be played in order. In osmosis the option --sort-change will put the change into streamable order.

  • Doesn't indicate source of data

Placeholders are proposed as an extension though they are not widely supported.

由以下项目支持:

Technical features of change formats

This a list of things that are desirable in a change file format for exampe change sets

placeholders

Placeholders are a feature where objects that are created in the file can be used in the creation of the objects that depend on them. So a single file can create two nodes and join them with a segment without knowing beforehand the final IDs.

indication of origin

IDs used in OSM files can not be shared between servers. IDs are allocated by the server, not by clients. Thus it is useful if the change file indicates the source of any IDs used in the file.

streamable

Whether the file can normally be processed in a stream, without breaking referential integrity.

查看更多