6 @given(u'the ([0-9.]+ )?grid')
7 def define_node_grid(context, grid_step):
9 Define a grid of node positions.
11 if grid_step is not None:
12 grid_step = float(grid_step.strip())
16 context.osm.clear_grid()
19 for h in context.table.headings:
21 context.osm.add_grid_node(int(h), 0, i)
25 for r in context.table:
29 context.osm.add_grid_node(int(h), x, y)
34 @when(u'loading osm data')
35 def load_osm_file(context):
37 Load the given data into a freshly created test data using osm2pgsql.
38 No further indexing is done.
40 The data is expected as attached text in OPL format.
42 # create a OSM file in /tmp and import it
43 with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd:
45 for line in context.text.splitlines():
46 if line.startswith('n') and line.find(' x') < 0:
47 coord = context.osm.grid_node(int(line[1:].split(' ')[0]))
49 coord = (random.random() * 360 - 180,
50 random.random() * 180 - 90)
51 line += " x%f y%f" % coord
52 fd.write(line.encode('utf-8'))
55 context.nominatim.run_setup_script('import-data', osm_file=fname,
58 ### reintroduce the triggers/indexes we've lost by having osm2pgsql set up place again
59 cur = context.db.cursor()
60 cur.execute("""CREATE TRIGGER place_before_delete BEFORE DELETE ON place
61 FOR EACH ROW EXECUTE PROCEDURE place_delete()""")
62 cur.execute("""CREATE TRIGGER place_before_insert BEFORE INSERT ON place
63 FOR EACH ROW EXECUTE PROCEDURE place_insert()""")
64 cur.execute("""CREATE UNIQUE INDEX idx_place_osm_unique on place using btree(osm_id,osm_type,class,type)""")
69 @when(u'updating osm data')
70 def update_from_osm_file(context):
72 Update a database previously populated with 'loading osm data'.
73 Needs to run indexing on the existing data first to yield the correct result.
75 The data is expected as attached text in OPL format.
77 context.nominatim.run_setup_script('create-functions', 'create-partition-functions')
79 cur = context.db.cursor()
80 cur.execute("""insert into placex (osm_type, osm_id, class, type, name, admin_level, address, extratags, geometry)
81 select osm_type, osm_id, class, type, name, admin_level, address, extratags, geometry from place""")
83 """insert into location_property_osmline (osm_id, address, linegeo)
84 SELECT osm_id, address, geometry from place
85 WHERE class='place' and type='houses' and osm_type='W'
86 and ST_GeometryType(geometry) = 'ST_LineString'""")
88 context.nominatim.run_setup_script('index', 'index-noanalyse')
89 context.nominatim.run_setup_script('create-functions', 'create-partition-functions',
90 'enable-diff-updates')
92 # create a OSM file in /tmp and import it
93 with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd:
95 for line in context.text.splitlines():
96 if line.startswith('n') and line.find(' x') < 0:
97 line += " x%d y%d" % (random.random() * 360 - 180,
98 random.random() * 180 - 90)
99 fd.write(line.encode('utf-8'))
102 context.nominatim.run_update_script(import_diff=fname)