mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-10 12:04:06 +00:00
bdd: move grid generation code into geometry factory
This commit is contained in:
@@ -9,7 +9,7 @@ class GeometryFactory:
|
|||||||
defpath = Path(__file__) / '..' / '..' / '..' / 'scenes' / 'data'
|
defpath = Path(__file__) / '..' / '..' / '..' / 'scenes' / 'data'
|
||||||
self.scene_path = os.environ.get('SCENE_PATH', defpath.resolve())
|
self.scene_path = os.environ.get('SCENE_PATH', defpath.resolve())
|
||||||
self.scene_cache = {}
|
self.scene_cache = {}
|
||||||
self.clear_grid()
|
self.grid = {}
|
||||||
|
|
||||||
def parse_geometry(self, geom, scene):
|
def parse_geometry(self, geom, scene):
|
||||||
""" Create a WKT SQL term for the given geometry.
|
""" Create a WKT SQL term for the given geometry.
|
||||||
@@ -103,11 +103,20 @@ class GeometryFactory:
|
|||||||
|
|
||||||
return scene
|
return scene
|
||||||
|
|
||||||
def clear_grid(self):
|
def set_grid(self, lines, grid_step):
|
||||||
|
""" Replace the grid with one from the given lines.
|
||||||
|
"""
|
||||||
self.grid = {}
|
self.grid = {}
|
||||||
|
y = 0
|
||||||
def add_grid_node(self, nodeid, x, y):
|
for line in lines:
|
||||||
self.grid[nodeid] = (x, y)
|
x = 0
|
||||||
|
for pt_id in line:
|
||||||
|
if pt_id.isdigit():
|
||||||
|
self.grid[int(pt_id)] = (x, y)
|
||||||
|
x += grid_step
|
||||||
|
y += grid_step
|
||||||
|
|
||||||
def grid_node(self, nodeid):
|
def grid_node(self, nodeid):
|
||||||
|
""" Get the coordinates for the given grid node.
|
||||||
|
"""
|
||||||
return self.grid.get(nodeid)
|
return self.grid.get(nodeid)
|
||||||
|
|||||||
@@ -7,28 +7,16 @@ import os
|
|||||||
def define_node_grid(context, grid_step):
|
def define_node_grid(context, grid_step):
|
||||||
"""
|
"""
|
||||||
Define a grid of node positions.
|
Define a grid of node positions.
|
||||||
|
Use a table to define the grid. The nodes must be integer ids. Optionally
|
||||||
|
you can give the grid distance. The default is 0.00001 degrees.
|
||||||
"""
|
"""
|
||||||
if grid_step is not None:
|
if grid_step is not None:
|
||||||
grid_step = float(grid_step.strip())
|
grid_step = float(grid_step.strip())
|
||||||
else:
|
else:
|
||||||
grid_step = 0.00001
|
grid_step = 0.00001
|
||||||
|
|
||||||
context.osm.clear_grid()
|
context.osm.set_grid([context.table.headings] + [list(h) for h in context.table],
|
||||||
|
grid_step)
|
||||||
i = 0
|
|
||||||
for h in context.table.headings:
|
|
||||||
if h.isdigit():
|
|
||||||
context.osm.add_grid_node(int(h), 0, i)
|
|
||||||
i += grid_step
|
|
||||||
|
|
||||||
x = grid_step
|
|
||||||
for r in context.table:
|
|
||||||
y = 0
|
|
||||||
for h in r:
|
|
||||||
if h.isdigit():
|
|
||||||
context.osm.add_grid_node(int(h), x, y)
|
|
||||||
y += grid_step
|
|
||||||
x += grid_step
|
|
||||||
|
|
||||||
|
|
||||||
@when(u'loading osm data')
|
@when(u'loading osm data')
|
||||||
|
|||||||
Reference in New Issue
Block a user