3 个版本
0.2.2 | 2020 年 8 月 11 日 |
---|---|
0.2.1 | 2020 年 8 月 6 日 |
0.2.0 | 2020 年 8 月 6 日 |
1351 在 编码
485KB
2K SLoC
osm-pbf2json
OSM protobuf bundle 的解析器/过滤器
构建
本地
可以通过 rustup 安装 rust 构建 环境。
cargo test
cargo build --release
Docker
在 MacOS 上构建 Linux 图像。构建工件位于 ./docker-target/release
之后。
mkdir docker-target
docker run \
-v $PWD/Cargo.toml:/build/Cargo.toml \
-v $PWD/Cargo.lock:/build/Cargo.lock \
-v $PWD/src:/build/src \
-v $PWD/benches:/build/benches \
-v $PWD/tests:/build/tests \
-v $PWD/docker-target:/build/target \
-w /build \
rust:1.43 cargo build --release
运行
检索对象
您必须通过 --tags
或 -t
指定查询,语法相对简单
通过声明一个键(-t amenity
)将选择所有使用该键标记的实体。为了进一步缩小结果,可以使用 ~
字段分隔符(-t 'amenity~fountain'
)给出一个特定值。要检查同一实体的多个标记,可以使用 +
操作符(-t 'amenity~fountain+tourism'
)将语句组合起来。最后,可以通过使用 ,
(-t 'amenity~fountain+tourism,amenity~townhall'
)将语句组连接起来指定选项。如果一个实体符合任一组的标准,它将被包括在输出中。
一个裁剪的 PBF 示例包含在 ./tests/data
文件夹中。
./target/release/osm_pbf2json berlin.pbf objects -t="addr:housenumber+addr:street+addr:postcode~10178" | tail -3
{"id":544604702,"type":"way","tags":{"addr:city":"Berlin","addr:country":"DE","addr:housenumber":"17","addr:postcode":"10178","addr:street":"Sophienstraße","addr:suburb":"Mitte","building":"residential","heritage":"4","heritage:operator":"lda","lda:criteria":"Ensembleteil","ref:lda":"09080182"},"centroid":{"lat":52.52571770265661,"lon":13.401513737828404},"bounds":{"e":13.4015869,"n":52.525649699999995,"s":52.5254975,"w":13.4013709}}
{"id":569067822,"type":"way","tags":{"addr:city":"Berlin","addr:housenumber":"1","addr:postcode":"10178","addr:street":"Anna-Louisa-Karsch-Straße","amenity":"library","email":"[email protected]","internet_access":"wlan","internet_access:fee":"no","name":"Humboldt-Universität zu Berlin Universitätsbibliothek Zweigbibliothek Theologie","name:en":"Humboldt University of Berlin University Library Theology Branch Library","opening_hours":"Mo-Fr 09:30-20:30; Sa 09:30-13:30","operator":"Universitätsbibliothek der Humboldt-Universität zu Berlin","phone":"+49 30 2093-91800","ref:isil":"DE-11-133","website":"https://www.ub.hu-berlin.de/de/standorte/zwbtheologie","wheelchair":"yes","wikidata":"Q73146656"},"centroid":{"lat":52.52113243392209,"lon":13.401373781610301},"bounds":{"e":13.4016009,"n":52.521282,"s":52.520961,"w":13.4011406}}
{"id":625034881,"type":"way","tags":{"addr:city":"Berlin","addr:housenumber":"1","addr:postcode":"10178","addr:street":"Karl-Marx-Allee","building":"commercial","building:levels":"1","height":"5","name":"Werkstatt Haus der Statistik"},"centroid":{"lat":52.52212174147001,"lon":13.418398630534096},"bounds":{"e":13.418516499999999,"n":52.5221701,"s":52.5220175,"w":13.4182626}}
提取街道
街道在 OSM 中表示为一系列较小的道路段。为了将这些段分组为街道实体,采用了一些启发式方法,特别是名称标记和地理距离。可以指定一个边界级别来沿着边界线分割街道。
./target/release/osm_pbf2json tests/data/alexanderplatz.pbf streets --geojson -n="Gontardstraße"
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"Gontardstraße","stroke":"#7DA86A"},"geometry":{"type":"MultiLineString","coordinates":[[[13.410188699999999,52.521660999999995],[13.4108953,52.521203799999995],[13.410997,52.521133199999994],[13.4114945,52.5208095],[13.4119613,52.520479099999996]],[[13.410188699999999,52.521660999999995],[13.410212399999999,52.521679899999995],[13.4102321,52.5216956],[13.4102623,52.5217192],[13.4102997,52.5217484]],[[13.4095035,52.522308699999996],[13.4095806,52.5222255],[13.4096047,52.5221899],[13.4098305,52.5220348],[13.4102997,52.5217484]]]}}]}
提取行政边界
行政边界存储为 OSM 关系(例如国家、州)具有复杂和不连续的几何形状,如果需要的话。边界的级别对每个国家都是特定的,可以在 这里 找到一份列表。可以在单个运行中指定和提取多个边界级别。默认情况下,考虑级别 4、6、8、9 & 10。此选项可提供 GeoJSON 输出。
./target/release/osm_pbf2json berlin.pbf boundaries -l 9
{"name":"Reinickendorf","admin_level":9,"bbox":{"sw":[13.201617599999999,52.5488072],"ne":[13.3892817,52.660741099999996]}}
{"name":"Spandau","admin_level":9,"bbox":{"sw":[13.109295,52.439614999999996],"ne":[13.2824665,52.598796899999996]}}
{"name":"Mitte","admin_level":9,"bbox":{"sw":[13.3015376,52.4987357],"ne":[13.4294017,52.5676686]}}
{"name":"Steglitz-Zehlendorf","admin_level":9,"bbox":{"sw":[13.088344999999999,52.3872254],"ne":[13.3716004,52.4718369]}}
{"name":"Treptow-Köpenick","admin_level":9,"bbox":{"sw":[13.4396363,52.3382448],"ne":[13.7611609,52.497706799999996]}}
{"name":"Friedrichshain-Kreuzberg","admin_level":9,"bbox":{"sw":[13.368229099999999,52.4827923],"ne":[13.4914434,52.5310256]}}
{"name":"Gosen","admin_level":9,"bbox":{"sw":[13.6861251,52.377441399999995],"ne":[13.7228219,52.399721299999996]}}
{"name":"Tempelhof-Schöneberg","admin_level":9,"bbox":{"sw":[13.3199923,52.376138399999995],"ne":[13.42746,52.5049424]}}
{"name":"Neukölln","admin_level":9,"bbox":{"sw":[13.3994933,52.395945399999995],"ne":[13.5241327,52.495864999999995]}}
{"name":"Marzahn-Hellersdorf","admin_level":9,"bbox":{"sw":[13.5168837,52.4704779],"ne":[13.658503399999999,52.574508599999994]}}
{"name":"Pankow","admin_level":9,"bbox":{"sw":[13.3475571,52.519927599999995],"ne":[13.523022,52.675508699999995]}}
{"name":"Charlottenburg-Wilmersdorf","admin_level":9,"bbox":{"sw":[13.1865954,52.4664729],"ne":[13.3414287,52.5494336]}}
{"name":"Lichtenberg","admin_level":9,"bbox":{"sw":[13.456196499999999,52.4678355],"ne":[13.5677059,52.5964629]}}
{"name":"Lindenberg","admin_level":9,"bbox":{"sw":[13.4966616,52.586616899999996],"ne":[13.566374999999999,52.620224099999994]}}
{"name":"Schönerlinde","admin_level":9,"bbox":{"sw":[13.3979077,52.6354682],"ne":[13.4742692,52.6734271]}}
测试
cargo test
cargo bench
依赖项
~13MB
~237K SLoC