6 @given(u'the ([0-9.]+ )?grid')
7 def define_node_grid(context, grid_step):
9 Define a grid of node positions.
10 Use a table to define the grid. The nodes must be integer ids. Optionally
11 you can give the grid distance. The default is 0.00001 degrees.
13 if grid_step is not None:
14 grid_step = float(grid_step.strip())
18 context.osm.set_grid([context.table.headings] + [list(h) for h in context.table],
22 @when(u'loading osm data')
23 def load_osm_file(context):
25 Load the given data into a freshly created test data using osm2pgsql.
26 No further indexing is done.
28 The data is expected as attached text in OPL format.
30 # create a OSM file in /tmp and import it
31 with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd:
33 for line in context.text.splitlines():
34 if line.startswith('n') and line.find(' x') < 0:
35 coord = context.osm.grid_node(int(line[1:].split(' ')[0]))
37 coord = (random.random() * 360 - 180,
38 random.random() * 180 - 90)
39 line += " x%f y%f" % coord
40 fd.write(line.encode('utf-8'))
43 context.nominatim.run_setup_script('import-data', osm_file=fname,
46 ### reintroduce the triggers/indexes we've lost by having osm2pgsql set up place again
47 cur = context.db.cursor()
48 cur.execute("""CREATE TRIGGER place_before_delete BEFORE DELETE ON place
49 FOR EACH ROW EXECUTE PROCEDURE place_delete()""")
50 cur.execute("""CREATE TRIGGER place_before_insert BEFORE INSERT ON place
51 FOR EACH ROW EXECUTE PROCEDURE place_insert()""")
52 cur.execute("""CREATE UNIQUE INDEX idx_place_osm_unique on place using btree(osm_id,osm_type,class,type)""")
57 @when(u'updating osm data')
58 def update_from_osm_file(context):
60 Update a database previously populated with 'loading osm data'.
61 Needs to run indexing on the existing data first to yield the correct result.
63 The data is expected as attached text in OPL format.
65 context.nominatim.run_setup_script('create-functions', 'create-partition-functions')
67 cur = context.db.cursor()
68 cur.execute("""insert into placex (osm_type, osm_id, class, type, name, admin_level, address, extratags, geometry)
69 select osm_type, osm_id, class, type, name, admin_level, address, extratags, geometry from place""")
71 """insert into location_property_osmline (osm_id, address, linegeo)
72 SELECT osm_id, address, geometry from place
73 WHERE class='place' and type='houses' and osm_type='W'
74 and ST_GeometryType(geometry) = 'ST_LineString'""")
76 context.nominatim.run_setup_script('index', 'index-noanalyse')
77 context.nominatim.run_setup_script('create-functions', 'create-partition-functions',
78 'enable-diff-updates')
80 # create a OSM file in /tmp and import it
81 with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd:
83 for line in context.text.splitlines():
84 if line.startswith('n') and line.find(' x') < 0:
85 line += " x%d y%d" % (random.random() * 360 - 180,
86 random.random() * 180 - 90)
87 fd.write(line.encode('utf-8'))
90 context.nominatim.run_update_script(import_diff=fname)