JA:Osmosis

From OpenStreetMap Wiki
Jump to navigation Jump to search
サブページ
Installation
Beginners Guide
Detailed Usage
Examples
Benchmarking / Tuning
Development
Writing Plugins

Osmosis は、OSM データを処理するコマンドライン Java アプリケーションです。このツールは、より大規模な処理を実行するために互いにつなぐことができる一連の接続可能なコンポーネントから成ります。例えば、データベースから読み込むコンポーネント、ファイルまたはデータベースに書き込むコンポーネント、変更セットをデータベースに作ったり適応したりするコンポーネント、データをソートするコンポーネントなどを持っています。これは、ファイルやデータベースを扱う共通の仕事を書き換えることなく、簡単に新しい機能を追加できるように設計されています。

これが現在できる事のいくつかの例です:

  • planet ダンプをデータベースから生成する。
  • planet ダンプをデータベースに載せる。
  • 変更セットをデータベースの履歴テーブルから生成する。
  • 変更セットをローカルデータベースに適応する。
  • 2つの planet ダンプを比べて、変更セットを生成する。
  • planet ダンプ内のデータを整理しなおす。
  • 矩形境界や多角形境界内にあるデータを取り出す。

OsmosisはJavaアプリケーションのライブラリとして利用することも可能です。[1]


現状

Osmosisは大きな変更が行われる可能性はあまりない状態になっています。新しい機能が追加される場合は、新しいタスクか、あるいはプラグインという形で導入されるものと思われますが、すでに実装されている機能が削除されることはないでしょう。バグレポートは全て歓迎します。

現行リリースバージョンでは、バージョン0.6のOSMデータモデルのみをサポートしています。

ダウンロード

最新安定版

可能な限り以下に示す安定版を使用してください。

注意: バージョン 0.38は、Windows環境において致命的な問題が存在します。
2GB以上のPBF形式ファイルを読み込む際、エラーメッセージ表示無く、データが破棄されます。
バージョン0.39以降へのアップグレードをお願いします。

開発ビルド

こちらのバージョンは最新の機能やバグフィックスが必要な場合に限り使用してください。これらのバージョンは安定した動作は保障されません。

正規ビルドは継続的インテグレーションサーバにて作成されています。これらはビルドバージョンを容易に識別できるよう、gitのリビジョンナンバーが含まれています。

Java 1.5

Java v1.6を利用できない場合は、以下にあるv1.5互換バージョンを利用してください。いくつかの古いMacシステムではこの問題があることが知られています。

Java 5 互換バージョン:

API 0.5 サポート

API 0.5のサポートは、バージョン0.35が最終版となります。

DB スキーマ

Database schema creation scripts matching the production API are bundled with the Osmosis distribution within the script/contrib directory.

Database schema creation scripts for the Osmosis PostGIS "simple" schema are bundled with the Osmosis distribution within the script directory.

ソースコード

Git レポジトリはGitHubに格納されています: https://github.com/openstreetmap/osmosis

(詳細は Osmosis/Installation インストール用サブページにて確認してください。)

使い方

詳細な使い方

全てのタスクと、その使い方に関する完全な詳細は Osmosis/Detailed Usage にあります。

Full details of all tasks and their usage are available at the following links:

Usage details for older versions are available below:

To maximize performance, refer to Tuning and Benchmarking.

There is also a frontend for the use of Osmosis named OSMembrane.

使用例

(Osmosis/Examples にもっと多くの例があります。)

planet ファイルをローカルの PostgreSQL rails port データベースにインポートします。

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

ローカルの PostgreSQL rails port データベースから 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 rails port データベースから変更セットを作成します。

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"

The above examples make use of the default pipe connection feature, however a simple read and write planet file command line could be written in two ways. The first example uses default pipe connection, the second explicitly connects the two components using a pipe named "mypipe". The default pipe connection will always work so long as each task is specified in the correct order. Each task pushes its output stream(s) onto a stack, and each task that requires input stream(s) takes them from the stack. This stack-based approach is the reason why the above "--apply-change" example first reads the change file, then the data file - the --apply-change task will then first retrieve the data file from the stack and then the change file.

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"

Extract an area based on a Osmosis/Polygon Filter File Format file:

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

Extract only those ways that have certain tags. Specifying --used-node only extracts those nodes that are used in the filtered ways. Relations stay untouched.

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

On larger files (e.g. a planet file), this may result in a segfault due to memory limitations. In this case, passing idTrackerType=BitSet as a parameter to --used-node may help:

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

Note that --way-key-value and --node-key-value cannot be used in one run. Instead, create two (or more) files in several runs and merge them together afterwards (yes, for n files you need n-1 merge commands):

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

Only 0.5 tasks are available from version 0.22 onwards.

矩形境界から抽出

Osmosisの基本的な利用法のひとつとして、OSM XMLを切り出して小さなサブセットを作成することがあります。全世界のOSMファイル(planet.osm)をダウンロードしたあとに特定の地域を抽出することもできますし、あるいはある国のなから市町村のみを抽出することも可能です。 最も簡単な方法は、矩形で抽出することです。

例えばドイツ地域、あるいは全世界のOSMファイルから ヌーレンベルグ市のみを抽出する際は、以下の記法を使用します。:


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

この手法は展開と圧縮に bzip2 を直接使っているので、内蔵アーカイバよりも効率がよいです。

緯度経度を得るための最も簡単な方法は、知りたい位置をダブルクリックして、それから「パーマリンク」をクリックして、URL フィールドからデータを取り出すことです。

Windows notes

十分なパフォーマンスがあれば、bzcat はWindowsでも利用可能です。ただ、Windowsには/dev/stdinが存在しません。代替としてCONIN$を使用してください。

ヘルプの入手法やバグの報告

osmosis の使い方に関する疑問への回答を得るための最良の場所は、osmosis dev メーリングリストです。

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

影響の大きなバグをチケット登録する際には、先にdev メーリングリストで議論するようにしてください。バグの存在が確定的である場合は、OSMのTracの"osmosis"コンポーネントにてチケットを登録してください。

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


参考

開発

osmosis の開発に関する詳細は Osmosis/Development にあります。 Visit there for documentation on the internal structure of osmosis, design decisions, steps to configuring development environments, etc.

ノート

Osmosisを利用するには、Javaのバージョン1.6を使用してください。Osmosisではjava.awt.geomクラスを必要としますが、このクラスはバージョン1.6でのみ利用可能です。もしバージョン1.5用に書きなおされたクラスができれば、バージョン1.5でも利用することが可能になります。Osmosis utilises generics and java.util.concurrent features requiring Java 1.5 as a minimum.

A number of tasks produce temporary files that contain serialised java classes to avoid using too much RAM. These files are gzipped to reduce disk space and in many cases improve performance through reduced IO. This will fail on some Java installations where the uncompressed data exceeds 2GB. This is caused by [Bug 5092263]. Upgrading to a later JDK will fix this problem. The only other option is to modify the source code to use uncompressed temporary files, contact me if this is required. This affects the IBM JDK1.5.0 included with IBM Rational tools such as Rational Software Architect. This was fixed in Sun JDK 5.0u8(b01) and Sun JDK 6.0.

内蔵の bzip (.bz2) の性能は、Java 内蔵の gzip (.gz) よりもとても低速です (Java の gzip は性能を向上させるために ネイティブコードを利用しています)。 また、最近の planet ダウンロードでは、内蔵 bzip ライブラリが対応していない bzip の機能(ストリーム)を使っています。 これらを使うために、そしてより大きいファイルでより速く処理するために、プラットホームのネイティブな bzip 実装を使って、 入出力に標準入出力を使うことが提案されています。 ( pbzip2 -d -c planet.osm.bz2 | bin/osmosis --rx /dev/stdin --wx /dev/stdout | gzip -c > planet-same.osm.gz ) Osmosis/Examples#Benchmark testsも参照してください。