[英]How can I download all hospitals in Africa from OpenStreetMap using Python and the Overpass API?
I need a shapefile of every hospital in continental Africa from OSM.我需要 OSM 提供的非洲大陆每家医院的 shapefile。 At this point, I've only played with downloading extracts from other services like geofabrik, I haven't actually pulled any data down myself.
在这一点上,我只玩过从 geofabrik 等其他服务下载提取物,实际上我自己并没有提取任何数据。 While I intend on learning how to use the Overpass API, I need a quick turnaround for this project.
虽然我打算学习如何使用立交桥 API,但我需要快速完成这个项目。 How can I use Python and the Overpass API to download a dataset of Africa's hospitals?
如何使用 Python 和立交桥 API 下载非洲医院的数据集?
A spectacularly quick and short crash course:一个惊人的快速和简短的速成课程:
osmosis
to filter it to keep only certain tagsosmosis
过滤它以仅保留某些标签ogr2ogr
ogr2ogr
将过滤后的数据转换为 shapefile The example below uses Congo only because it's smaller than all of Africa, and you may need to also add eg healthcare=*
as a filter:下面的示例仅使用刚果,因为它比整个非洲都小,您可能还需要添加
healthcare=*
作为过滤器:
$ wget https://download.geofabrik.de/africa/congo-democratic-republic-latest.osm.pbf
(Progress...)
$ osmosis --read-pbf congo-democratic-republic-latest.osm.pbf --log-progress --tf accept-ways amenity=hospital,clinic,doctors,dentist --used-node --write-pbf congolese-hospitals.osm.pbf
INFO: Osmosis Version 0.48.2
INFO: Preparing pipeline.
INFO: Launching pipeline execution.
INFO: Pipeline executing, waiting for completion.
INFO: Processing Node 2096625632, 419655.26894621074 objects/second.
INFO: Processing Node 6901615718, 515231.3074770092 objects/second.
INFO: Processing Way 661735764, 877193.7612477505 objects/second.
INFO: Processing completion steps.
INFO: Completion steps took 13.833 seconds.
INFO: Processing complete.
INFO: Pipeline complete.
INFO: Total execution time: 90156 milliseconds.
$ ogr2ogr -f "ESRI Shapefile" congolese-hospitals ./congolese-hospitals.osm.pbf
0...10...20...30...40...50...60...70...80...90...100 - done.
Warning 6: Normalized/laundered field name: 'admin_level' to 'admin_leve'
ERROR 6: Geometry type of `Geometry Collection' not supported in shapefiles. Type can be overridden with a layer creation option of SHPT=POINT/ARC/POLYGON/MULTIPOINT/POINTZ/ARCZ/POLYGONZ/MULTIPOINTZ/MULTIPATCH.
$
As you can see from the warnings and errors, shapefiles are slightly legacy;从警告和错误中可以看出,shapefile 有点遗留; if GeoPackages are an option,
如果 GeoPackages 是一个选项,
$ ogr2ogr -f GPKG congolese-hospitals.gpkg ./congolese-hospitals.osm.pbf
0...10...20...30...40...50...60...70...80...90...100 - done.
For proof, here's a part of the result being browsed in JOSM:为了证明,这是在 JOSM 中浏览的部分结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.