-
Notifications
You must be signed in to change notification settings - Fork 0
/
shops-completeness.py
executable file
·65 lines (53 loc) · 1.76 KB
/
shops-completeness.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# This script generates completeness statistics for some chain shops in the
# Netherlands. It can be easily adapted for other shops by modifying the
# shops array.
#
# Make sure to set the total number of shops manually in the "shops" array.
#
# Before running this script, you will need to load OSM-data into an
# PostGIS-database with osm2pgsql:
# sudo -u postgres createdb --encoding=UTF8 gis
# psql --dbname=gis -c "CREATE EXTENSION postgis;"
# psql --dbname=gis -c "CREATE EXTENSION hstore;"
# osm2pgsql --slim -d gis -C 2000 --hstore --number-processes 3 netherlands-latest.osm.pbf
#
# Usage: Simply run './shops-completeness.py'.
from __future__ import division
import psycopg2
import sys
db = "gis"
user = "postgres"
con = None
try:
# Set here the shop names and the total number of shops
shops = [
("Albert Heijn", 850),
("Bijenkorf", 7),
("Gamma", 165),
("C&A", 132),
("BCC", 73),
("Kwantum", 99),
("Mango", 30),
("Bruna", 335),
("Blokker", 622),
("Specsavers", 118),
("Witteveen", 100),
("Shoeby", 225),
]
con = psycopg2.connect(database=db, user=user)
cur = con.cursor()
for shop in shops:
cur.execute("SELECT COUNT(*) FROM planet_osm_polygon WHERE name LIKE %s AND NOT shop IS NULL;", (shop[0]+'%',))
totalpolygon = cur.fetchone()[0]
cur.execute("SELECT COUNT(*) FROM planet_osm_point WHERE name LIKE %s AND NOT shop IS NULL;", (shop[0]+'%',))
totalpoint = cur.fetchone()[0]
total = totalpoint + totalpolygon
percentage = total / shop[1] * 100
print shop[0], total, shop[1], "%.2f" % percentage + '%'
except psycopg2.DatabaseError, e:
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()