Zh-hans:Osmosis

From OpenStreetMap Wiki
Jump to navigation Jump to search
Sub pages
Installation
Detailed Usage
Examples
Benchmarking / Tuning
Development
Writing Plugins

Osmosis 是用于处理OSM数据的Java命令行应用程序,包括许多插件式的组件。比如读写数据库和文件的组件、继承和修改数据源的组件、对数据排序管理的组件等,避免了实现常用功能而重复性编写代码。

目前主要功能有:

  • 从数据库中生成指定区域的osm数据
  • 导入区域的osm数据到数据库
  • 生成变化数据集数据库更新记录表
  • 应用变化数据集到本地数据库
  • 比较区域osm数据生成变化数据集
  • 区域osm数据重排序
  • 抽取指定矩形或多边形范围内数据

Osmosis也可以库的形式集成到其他Java应用(包括Android应用)中[1]

当前状态

Osmos 目前大部分的代码库不太可能会被彻底改变。 新功能以新任务的形式,在不同时期会被进行说明 plugins, 但是已存在的功能不太会被移除掉. 欢迎提交任何 BUG

当前的版本只支持API 0.6 OSM data model

下载

最新稳定版本

请保证在任何时候都使用以下的稳定版本

开发编译版本

在使用前,你应该去查看它最新的功能或修正的错误。“不能保证其稳定性”。

定期编译包是创建在持续整合的服务器上,上面包括了很容易被识别的SVN版本号。

老风格的nightly builds 还依然有效,但是只能在持续集合包无效的情况下使用。

http://dev.openstreetmap.org/~bretth/osmosis-build/


Java 1.5

对于那些不能安装Java 1.6 运行时的情况,可以查考以下的兼容 1.5 的版本。目前已经确认一些问题存在于部分老款的Mac 系统。

支持 API 0.5

0.35版本是最后一个支持 API 0.5。

DB Schema

(see Osmosis/PostGIS_Setup)

Database schema在 script/contrib 目录下可以找到与API相匹配的创建脚本。

在Osmosis 发行包中的script 目录里,可以找到用来创建simple模式和snapshot模式的数据库模式创建脚本(osmosis 0.39 ff)。

Subversion

subversion 库 地址: http://svn.openstreetmap.org/applications/utils/osmosis/

(更多的内容参见Osmosis 安装指南分页 Osmosis/Installation 。)


使用

详细使用说明

以下链接包含了所有完整的任务明细和使用说明:

以下链接包含了一些老版本的使用说明:

追求最大的性能,可以参考 Tuning and Benchmarking.

OSMembrane 也包含了在前端使用Osmosis 的说明。

使用案例

(更多内容参见 Osmosis/Examples.)

导入一个planet 文件到本地的PostgreSQL 数据库。

osmosis --read-xml file="planet.osm" --write-apidb host="x" database="x" user="x" password="x"


从本地的PostgreSQL 数据库导出一个planet 文件。

osmosis --read-apidb host="x" database="x" user="x" password="x" --write-xml file="planet.osm"

从两个planet 文件得出差异集。第一个文件是变化后数据,第二个文件是变化前数据。

osmosis --read-xml file="planet1.osm" --read-xml file="planet2.osm" --derive-change --write-xml-change file="planetdiff-1-2.osc"

从一个planet 文件和本地PostgreSQL 数据库中得出差异集。

osmosis --read-xml file="planet1.osm" --read-apidb host="x" database="x" user="x" password="x" --derive-change --write-xml-change file="planetdiff-1-2.osc"

应用一个差异集到planet 文件上。

osmosis  --read-xml-change file="planetdiff-1-2.osc" --read-xml file="planet1.osm" --apply-change --write-xml file="planet2.osm" or
osmosis  --read-xml file="planet1.osm" --read-xml-change file="planetdiff-1-2.osc" --apply-change --write-xml file="planet2.osm" for the older version

整理出指定内容的planet 文件。

osmosis --read-xml file="data.osm" --sort type="TypeThenId" --write-xml file="data-sorted.osm"

以上的例子都使用了 默认管道连接特性,然而读写planet文件的命令行可以写成两种方式。第一种就是使用默认管道连接,第二种准确的来说就是通过被命名的"mypipe"的管道来连接两个部件。默认管道连接将以指定顺序来跑完每个任务。而每个任务需要把它的输出流放到一个堆栈上,而且每个任务需要从堆栈上把数据放到它的输入流。正是因为基于堆栈的方式,所以需要使用"--apply-change" 参数的例子会首先去读取差异文件,而后--apply-change 任务会先从堆栈取得数据文件,再然后去改变文件。

osmosis --read-xml file="planetin.osm" --write-xml file="planetout.osm"
osmosis --read-xml file="planetin.osm" outPipe.0="mypipe" --write-xml file="planetout.osm" inPipe.0="mypipe"


通过Osmosis/Polygon Filter File Format 文件来导出一个地区 :

osmosis --read-xml file="planet-latest.osm" --bounding-polygon file="country2pts.txt" --write-xml file="germany.osm"


导出指定标签的ways。通过指定 --used-node 将只导出那些被过滤出来的ways所需要使用的nodes。Relations 则不受影响。

osmosis --read-xml city.osm --way-key-value keyValueList="railway.tram,railway.tram_stop" --used-node --write-xml city_tram.osm


对于一些大数据(就像 planet 文件),通常会因为内存的限制造成一个分段错误。在--used-node后加上idTrackerType=BitSet这个参数,可能可以帮助解决这个现象:

osmosis --read-xml city.osm --way-key-value keyValueList="railway.tram,railway.tram_stop" --used-node idTrackerType=BitSet --write-xml city_tram.osm

记住,--way-key-value--node-key-value 不能被同时使用。可以去多跑几次去创建两个(或以上)的文件,然后再合并(merge)在一起(对于n个文件,你需要n-1个merge命令):

osmosis --rx 1.osm --rx 2.osm --rx 3.osm --merge --merge --wx merged.osm

只有从0.22版本开始 的 0.5 任务 才有效。


导出指定区域

这是一个从巨大的下载文件来提取OSM XML 子集的基本用例。你可以去下载整个地球的OSM (planet.osm) ,只是想提取某些区域,或是从下载的国家分量包里只获取某个城市。最简单的就是导出一个矩形大小的范围。

这是一个从Germany或者是world osm上导出Nürnberg 以及 周边地区的例子:

 bzcat downloaded.osm.bz2 | osmosis\
  --read-xml enableDateParsing=no file=-\
  --bounding-box top=49.5138 left=10.9351 bottom=49.3866 right=11.201 --write-xml file=-\
  | bzip2 > extracted.osm.bz2

在这里需要使用 bzip2直接来进行压缩和解压缩,这比内置的解压程序更高效。

最简单的就是双击你想获取的莫个坐标范围的地方,再点击"Permalink" 从URL上来抓取数据。

Windows 注意事项

如果你想要好的表现,可以尝试bzcat 这个For Windows的工具。然而 /dev/stdin在Windows上不是一个有效的路径. 尝试使用CONIN$ 来代替它.

在Android中使用

在根目录级的build.gradle文件中添加以下Maven存储库:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

在模块级的build.gradle文件中添加依赖项(根据您的需要选择所需的子项目):

dependencies { 
    implementation 'com.github.openstreetmap.osmosis:osmosis-apidb:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-areafilter:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-core:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-dataset:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-extract:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-hstore-jdbc:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-osm-binary:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-pbf:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-pbf2:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-pgsimple:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-pgsnapshot:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-replication:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-replication-http:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-set:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-tagfilter:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-tagtransform:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-testutil:0.48.0'
    implementation 'com.github.openstreetmap.osmosis:osmosis-xml:0.48.0'
}

获取帮助 报告BUG

想要获取在使用osmosis 过程中遇到的问题答案,osmosis 开发邮件列表是最好的地方。

http://lists.openstreetmap.org/listinfo/osmosis-dev

在开票前,请在开发邮件列表讨论下可能潜在的bugs。如果你不确定是否已经发现了一个bug,尝试去登陆到OSM trac的"osmosis"部分。

http://trac.openstreetmap.org/query?component=osmosis

另请参阅

  • 想了解用osmosis 所描述的差异方面的详细内容,参见OsmChange
  • 想了解更多复杂的例子,参见 Osmosis/Examples.
  • 想要尝试去写自己的任务,参见Osmosis/WritingPlugins
  • 想了解完整的命令和参数集,参见 Osmosis/Detailed Usage.
  • Osm2pgsql 同样能够对postgis数据库进行导出工作
  • 感谢 Osmosis, Osm2postgresql 能够仅仅通过一句命令,就可以安装 postgresql & postgis 和你自己的OSM数据。