New OSM Postgis Script - Count the number of Restaurants inside each admin_level=4 polygon
Posted by baditaflorin on 14 April 2016 in English.This script works in 2 parts.

1. First it will generate from the osm.pbf file the list with all the admin_level=4 (al_4)
Then it will remove the ones that are not closed. Then it will make a polygon from each al_4, using the ST_BuildArea
After it will have a inner join that will search for all the nodes and ways that are a restaurant.
2. Then, using st_contains we are searching to see in what polygon each restaurant fits.
Took 4 seconds to do it for Romania
You can find the query here https://github.com/baditaflorin/osm-postgis-scripts/blob/master/statistics/count_number_of_restaurants_inside_each_al_4.sql
| Admin_level_4 | Count |
|---|---|
| Municipiul București | 505 |
| Cluj | 249 |
| Constanța | 217 |
| Iași | 155 |
| Prahova | 128 |
| Brașov | 124 |
| Timiș | 121 |
| Mureș | 109 |
| Hunedoara | 88 |
| Sibiu | 78 |
| Arad | 74 |
| Galați | 68 |
| Buzău | 56 |
| Neamț | 53 |
| Harghita | 53 |
| Dolj | 52 |
| Argeș | 47 |
| Bihor | 41 |
| Covasna | 38 |
| Ilfov | 36 |
| Brăila | 35 |
| Vâlcea | 33 |
| Alba | 32 |
| Maramureș | 29 |
| Suceava | 28 |
| Bacău | 28 |
| Mehedinți | 28 |
| Caraș Severin | 26 |
| Călărași | 22 |
| Tulcea | 22 |
| Olt | 20 |
| Satu Mare | 19 |
| Gorj | 18 |
| Dâmbovița | 16 |
| Giurgiu | 13 |
| Ialomița | 13 |
| Botoșani | 13 |
| Bistrița-Năsăud | 12 |
| Vaslui | 11 |
| Vrancea | 11 |
| Teleorman | 7 |
| Sălaj | 5 |
Discussion