5 from nose.tools import * # for assert functions
7 @when(u'loading osm data')
8 def load_osm_file(context):
10 # create a OSM file in /tmp and import it
11 with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd:
13 for line in context.text.splitlines():
14 if line.startswith('n') and line.find(' x') < 0:
15 line += " x%d y%d" % (random.random() * 360 - 180,
16 random.random() * 180 - 90)
17 fd.write(line.encode('utf-8'))
20 context.nominatim.run_setup_script('import-data', osm_file=fname,
23 ### reintroduce the triggers/indexes we've lost by having osm2pgsql set up place again
24 cur = context.db.cursor()
25 cur.execute("""CREATE TRIGGER place_before_delete BEFORE DELETE ON place
26 FOR EACH ROW EXECUTE PROCEDURE place_delete()""")
27 cur.execute("""CREATE TRIGGER place_before_insert BEFORE INSERT ON place
28 FOR EACH ROW EXECUTE PROCEDURE place_insert()""")
29 cur.execute("""CREATE UNIQUE INDEX idx_place_osm_unique on place using btree(osm_id,osm_type,class,type)""")
34 @when(u'updating osm data')
35 def update_from_osm_file(context):
36 context.nominatim.run_setup_script('create-functions', 'create-partition-functions')
38 cur = context.db.cursor()
39 cur.execute("""insert into placex (osm_type, osm_id, class, type, name,
40 admin_level, housenumber, street, addr_place, isin, postcode,
41 country_code, extratags, geometry) select * from place""")
43 context.nominatim.run_setup_script('index', 'index-noanalyse')
44 context.nominatim.run_setup_script('create-functions', 'create-partition-functions',
45 'enable-diff-updates')
47 # create a OSM file in /tmp and import it
48 with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd:
50 for line in context.text.splitlines():
51 if line.startswith('n') and line.find(' x') < 0:
52 line += " x%d y%d" % (random.random() * 360 - 180,
53 random.random() * 180 - 90)
54 fd.write(line.encode('utf-8'))
57 context.nominatim.run_update_script(import_diff=fname)