LoginSignup
0
0

More than 1 year has passed since last update.

osmium-tool の tags-filter 処理(シェルスクリプト)

Last updated at Posted at 2021-06-07

こんにちは。
OpenStreetMap データ(osm.pbf ファイルの way データ)に対して、osmium-tool の tags-filter コマンドの処理を行うシェルスクリプトを作りました。 and 条件も指定可能です(& で区切った条件を与えます)。GeoJSON データを標準出力します(GDAL (ogr2ogr) を使っています)。

動作例(下記)は、

  1. 最初に、tags-filter: w/highway=motorway,motorway_link を処理し1
  2. 次にこれに対して、tags-filter: w/moped=yes w/bicycle=yes を処理する例です:
$ ./tags_filter.sh "w/highway=motorway,motorway_link & w/moped=yes w/bicycle=yes" japan-latest.osm.pbf > result.geojson
tags_filter.sh
#!/bin/sh

WAYS="$1"
inputfile="$2"

## function ##
realpath_() {
  case "$1" in /*) ;; *) printf '%s/' "$PWD";; esac; echo "$1"
}

## main ##
resultfile=ways.osm.pbf
inputfile=$(realpath_ "$inputfile")
tmpdir=$(mktemp -d)
cd "$tmpdir" || exit

echo "$WAYS" | tr '&' '\n' | { while read -r ways; do
  cp -f "$inputfile" input.osm.pbf
  osmium tags-filter input.osm.pbf $ways -O -o "$resultfile"
  inputfile="$resultfile"
done }

ogr2ogr -f "GeoJSON" result.json "$resultfile" lines >/dev/null
cat result.json
rm -rf "$tmpdir"
exit

  1. 複数条件を指定すると or 扱いです(osmium-tool の tags-filter の仕様です)。 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0