Python Forum

Full Version: How can I export or query all hospitals from Open Street Map?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
dear experts good day,


okay - this is not a simple python-question - but we can do this with python as well i suppose.

How can I export or query all hospitals from Open Street Map?


'd like to extract all the hospital locations in the from Open Street Map as a reference for my ,little geocoding project.

I know how to get all the OSM data for a small area with the QGIS plugin but not sure how to query a larger area  eg for the whole planet-file?



some ideas:


1) The read-only Overpass API. I don't know that it'll work for the whole planet-file in one pass, but maybe if we extend the time out enough?
For a smaller area and with the benefit of a (minimal) UI, we can access Overpass via the XAPI Query Builder. There, we can put amenity=hospital in the tag search, select our area, and go.



2) Geofabrik downloads, filtered with Osmosis, as described in How to extract partial data for large regions? on the OpenStreetMap Help.


3) what about using healthsites.io:  regarding healthsites this is the most important link: https://healthsites.io/api/docs

can i use healthsites.io for my project!?




what is aimed: i want to maintain the dataset in a pustgresql-db



update: since i am interested especially in the dataset of healthsites.io i can download it at this page:_ https://healthsites.io/map


- and import all that OSM-data to PostGIS for the purpose of visualization and further analytics. There are a bunch of tools on the market— osm2pgsql; imposm; ogr2org; just to mention some of those. i will do any further steps according this manual: https://www.cybertec-postgresql.com/en/o...he-basics/
you can download a dataset here: https://catalog.data.gov/dataset/hospitals-dcdfc
the question of today: acquire the POI of every hospital in Africa, Asia, America from OSM


I need to acquire the POI if every hospital in Africa, Asia, America from OSM: which approach should i choose? 

At this point, I've only played with downloading extracts from other services like geofabrik, I haven't actually pulled any data down myself. What's the best way to do this in a pinch? I'm looking for a crash course. Thanks in advance for your help!

on a sidenote; there is a high likelihood that many non-hospital medical facilities have been mapped for example. One other issue which is also common is multiple hospital objects existing on one hospital site: this is frequently, but not always, incorrect. See an example in Tanzania.

https://wiki.openstreetmap.org/wiki/Down...ts_of_data

some approaches: 

- osmconvert: https://wiki.openstreetmap.org/wiki/Osmconvert

- osmfilter: https://wiki.openstreetmap.org/wiki/Osmfilter

- XAPI, Overpass API: https://wiki.openstreetmap.org/wiki/Xapi

- overpass-turbo:  http://overpass-turbo.eu/

- osmium https://osmcode.org/osmium-tool/ 

"XAPI, Overpass API and the Export Tool allow to download custom data sets like arbitrary bounding boxes, elements with specific tags, public transport networks or other features." might take a bit of experimenting with parameters and validation because you're relying on consistent tagging by other users

we can try with overpass turbo http://overpass-turbo.eu/ but I suspect that it will be too much data and we would need to use suitably defined bounding boxes. What should work is doing this on a country by country base, which would also allow us to define exactly which ones us believe belong to Africa and which not (we will need to convert the output to a shapefile).

The other approach is to download an extract  - let us take Africa for example: 
- that just contains "Africa" for example http://download.geofabrik.de/africa.html (the fsvo bit: this contains the Canary Islands which you may want to or may not want to include), and filter it with a suitable command line tool (and then convert to a shapefile).

Examples: osmium https://osmcode.org/osmium-tool/ osmfilter https://wiki.openstreetmap.org/wiki/Osmfilter

healthsites.io: hat is actually a hospital? amenity=hospital is a fairly sure bet, but you might want to include amenity=clinic and potentially give the healthcare tags a look too. see the Data of healthsites.io : etc https://healthsites.io/map Healthsites.io is supposed to curate healthcare data based on OSM for more widespread usage by healthcare specialists.

btw: For some reason OSM tagging is quite weak regardivng nuances of healthcare facilities (for instance how should one map a private hair transplant practice?). It's also extremely difficult to judge the validity of tagging without good knowledge of the local healthcare system. see more of healthsites.io-Projcet: http://www.healthsites.io 


note: once downloaded i want to maintain the dataset in a PostgreSQL db.
btw: when trying to get the data from overpass-turbo i get somewhat full set of POI data

[out:csv(::id,::type,"name","addr:postcode","addr:city","addr:street","addr:housenumber","website","contact:email=*")][timeout:600];
area["ISO3166-1"="AT"]->.a;
( node(area.a)[amenity=hospital];
  way(area.a)[amenity=hospital];
  rel(area.a)[amenity=hospital];);
out;
see the results: 

    @id    @type    name    addr:postcode    addr:city    addr:street    addr:housenumber    website     contact:email=*
    2656877    relation    Unfallkrankenhaus Lorenz Böhler    1200    Wien    Donaueschingenstraße    13    https://www.auva.at/ukhboehler/   
    2685003    relation    Landeskrankenhaus Hörgas-Enzenbach                    http://www.lkh-hoergas.at   
    2685004    relation    Landeskrankenhaus Judenburg-Knittelfeld                    http://www.lkh-judenburg.at   
    2685005    relation    Landeskrankenhaus Hochsteiermark                    http://www.lkh-hochsteiermark.at   
    2685006    relation    Landeskrankenhaus Mürzzuschlag-Mariazell                    http://www.lkh-muerzzuschlag.at   
    2685007    relation    Landeskrankenhaus Rottenmann-Bad Aussee                    http://www.lkh-rottenmann.at   
    2755244    relation    Landesklinikum Scheibbs    3270    Scheibbs    Feldgasse    26       
    2764083    relation    Allgemeines Krankenhaus Wien    1090    Wien    Währinger Gürtel    18-20    https://www.akhwien.at   
    2882269    relation    Unfallkrankenhaus Salzburg                    http://www.ukh-salzburg.at   
    3333391    relation    Krankenhaus St. Josef    5280    Braunau am Inn    Ringstraße    60    https://www.khbr.at/   
or to take a second example: 

    30850910 way Hôpital Nord Guillaume et René Laennec 44093 Nantes Cedex 1 Bd professeur Jacques-Monod - Saint-Herblain https://www.chu-nantes.fr/ 
    30979413 way Hôpital Albert Chenevier 94010 Créteil rue de Mesly 40 http://chu-mondor.aphp.fr/hopital-albert-chenevier1/ 
    31150222 way Centre de Psychiatrie Les Tournesols 
    31150223 way Clinique du Saint-Coeur http://www.saint-coeur.groupe-elsan.com/ 
    31252310 way Hôpital Avicenne http://chu93.aphp.fr/hopital-avicenne-bobigny/ 
    32229408 way Centre hospitalier du Rouvray 76300 Sotteville-lès-Rouen Rue Paul Éluard 4 www.ch-lerouvray.fr 
    32354044 way Centre hospitalier intercommunal Fréjus Saint-Raphaël https://www.chi-fsr.fr/ 
    32388820 way Clinique des Cèdres https://clinique-cedres.capio.fr/ 
    32471086 way Hôpital Saint-Jacques 
    32522247 way Centre hospitalier de Dieppe 76200 Dieppe Avenue Pasteur http://www.ch-dieppe.fr 
    32617022 way Hôpital Désandrouins 55100 Verdun Avenue d'Étain 
    32679701 way Hôpital Belle-Isle https://www.hpmetz.fr/fr/etablissement/hopital-belle-isle 
    32851894 way Clinique d'Occitanie 31600 Muret Avenue Bernard IV 20 http://www.clinique-occitanie.com/ 
question: why do i get such a detailed list while running an request against overpass-turbo.eu  - the output is very very detailed. 

should i stick to overpass-turbo.eu?  and run a request contry by country... and then put all the data to a MySQL or PostGreSQL-DB to maintain all the data!?

Look forward to hear from  you



update: i will do like so:


1 . osmconvert - running the Option --all-to-nodes to transfer all objects to POIs - afterwards
2 . work with osmfilter to filter all the wanted objects

see more:


http://manpages.ubuntu.com/manpages/trus...ert.1.html

--all-to-nodes
Quote: Some applications do not have the ability to process ways or relations, they just
accept nodes as input. However, more and more complex object are mapped as ways or
even relations in order to get all their details into the database. Apply this
option if you want to convert ways and relations to nodes and thereby make them
available to applications which can only deal with nodes. For each way a node is
created. The way's id is increased by 10^15 and taken as id for the new node. The
node's longitude and latitude are set to the way's geographical center. Same
applies to relations, however they get 2*10^15 as id offset.



Look forward to hear from you
Have you looked at the QuickQSM plugin capability to do this?
Quick Query:
key=Amenity
value=hospital
set your geographic preference in the 'IN" section
hello dear Larz60,


first of all; many thanks for the quick reply. happy to hear from you

(Aug-07-2020, 11:08 PM)Larz60+ Wrote: [ -> ]Have you looked at the QuickQSM plugin capability to do this?
Quick Query:
key=Amenity
value=hospital
set your geographic preference in the 'IN" section

great idea i will test it: https://github.com/3liz/QuickOSM

by the way: how do you like thie idea of the pythonwrapper: note that a completely new version of the Python bindings was released recently. It's under the same namespace in PyPi (maproulette) but the interface and yes: is a bit different. See the new info at https://pypi.org/project/maproulette/

how do you like Maproulette!? one of its creators is Martijn van Exel

well i try to find a solution that works - again many many thanks