Remove interpolation lines from placex and save them in an extra table.

This commit is contained in:
Markus Gail
2016-04-25 09:44:01 +02:00
parent 0419aada6e
commit 7879ad44cd
19 changed files with 1627 additions and 1155 deletions

View File

@@ -35,6 +35,7 @@ def check_placex_names(step, osmtyp, osmid):
@step(u'table ([a-z_]+) contains$')
def check_placex_content(step, tablename):
""" check that the given lines are in the given table
@@ -49,13 +50,21 @@ def check_placex_content(step, tablename):
q = 'SELECT *'
if tablename == 'placex':
q = q + ", ST_X(centroid) as clat, ST_Y(centroid) as clon"
q = q + ", ST_GeometryType(geometry) as geometrytype"
q = q + ' FROM %s where osm_type = %%s and osm_id = %%s' % (tablename,)
if tablename == 'location_property_osmline':
q = q + ' FROM %s where osm_id = %%s' % (tablename,)
else:
q = q + ' FROM %s where osm_type = %%s and osm_id = %%s' % (tablename,)
if cls is None:
params = (osmtype, osmid)
if tablename == 'location_property_osmline':
params = (osmid,)
else:
params = (osmtype, osmid)
else:
q = q + ' and class = %s'
params = (osmtype, osmid, cls)
if tablename == 'location_property_osmline':
params = (osmid, cls)
else:
params = (osmtype, osmid, cls)
cur.execute(q, params)
assert(cur.rowcount > 0)
for res in cur:
@@ -92,6 +101,18 @@ def check_placex_missing(step, tablename, osmtyp, osmid, placeclass):
cur.close()
world.conn.commit()
@step(u'table location_property_osmline has no entry for W(\d+)?')
def check_osmline_missing(step, osmid):
cur = world.conn.cursor()
try:
q = 'SELECT count(*) FROM location_property_osmline where osm_id = %s' % (osmid, )
cur.execute(q)
numres = cur.fetchone()[0]
assert_equals (numres, 0)
finally:
cur.close()
world.conn.commit()
@step(u'search_name table contains$')
def check_search_name_content(step):
cur = world.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
@@ -134,12 +155,35 @@ def check_interpolated_housenumbers(step, nodeid):
FROM placex WHERE osm_type = 'W' and osm_id = %s
and class = 'place' and type = 'address'""",
(int(nodeid),))
assert_equals(len(numbers), cur.rowcount)
for r in cur:
assert_in(r["housenumber"], numbers)
world.match_geometry((r['clat'], r['clon']), numbers[r["housenumber"]])
del numbers[r["housenumber"]]
@step(u'way (\d+) expands to lines')
def check_interpolation_lines(step, wayid):
"""Check that the correct interpolation line has been entered in
location_property_osmline for the given source line/nodes. Expected are three columns:
startnumber, endnumber and linegeo
"""
lines = {}
for line in step.hashes:
assert line["startnumber"] not in lines
lines[line["startnumber"]] = {'endnumber': line["endnumber"], 'geometry': line["geometry"]}
cur = world.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("""SELECT startnumber::text, endnumber::text, st_astext(linegeo) as geometry
FROM location_property_osmline WHERE osm_id = %s""",
(int(wayid),))
assert_equals(len(lines), cur.rowcount)
for r in cur:
assert_in(r["startnumber"], lines)
assert_equals(r["endnumber"], lines[r["startnumber"]]["endnumber"])
linegeo = str(str(r["geometry"].split('(')[1]).split(')')[0]).replace(',', ', ')
assert_equals(linegeo, lines[r["startnumber"]]["geometry"])
del lines[r["startnumber"]]
@step(u'way (\d+) expands exactly to housenumbers ([0-9,]*)')
def check_interpolated_housenumber_list(step, nodeid, numberlist):
""" Checks that the interpolated house numbers corresponds
@@ -149,7 +193,7 @@ def check_interpolated_housenumber_list(step, nodeid, numberlist):
cur = world.conn.cursor()
cur.execute("""SELECT housenumber FROM placex
WHERE osm_type = 'W' and osm_id = %s
and class = 'place' and type = 'address'""", (int(nodeid),))
and class = 'place' and type = 'address'""", (int(nodeid),))
for r in cur:
assert_in(r[0], expected, "Unexpected house number %s for node %s." % (r[0], nodeid))
expected.remove(r[0])

View File

@@ -23,6 +23,7 @@ import os
import subprocess
import random
import base64
import sys
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
@@ -143,8 +144,8 @@ def import_set_scene(step, scene):
@step(u'the (named )?place (node|way|area)s')
def import_place_table_nodes(step, named, osmtype):
"""Insert a list of nodes into the placex table.
Expects a table where columns are named in the same way as placex.
"""Insert a list of nodes into the place table.
Expects a table where columns are named in the same way as place.
"""
cur = world.conn.cursor()
cur.execute('ALTER TABLE place DISABLE TRIGGER place_before_insert')
@@ -214,18 +215,19 @@ def import_database(step):
""" Runs the actual indexing. """
world.run_nominatim_script('setup', 'create-functions', 'create-partition-functions')
cur = world.conn.cursor()
#world.db_dump_table('place')
cur.execute("""insert into placex (osm_type, osm_id, class, type, name, admin_level,
housenumber, street, addr_place, isin, postcode, country_code, extratags,
geometry) select * from place""")
geometry) select * from place where not (class='place' and type='houses' and osm_type='W')""")
cur.execute("""select insert_osmline (osm_id, housenumber, street, addr_place, postcode, country_code, geometry) from place where class='place' and type='houses' and osm_type='W'""")
world.conn.commit()
world.run_nominatim_script('setup', 'index', 'index-noanalyse')
#world.db_dump_table('placex')
#world.db_dump_table('location_property_osmline')
@step(u'updating place (node|way|area)s')
def update_place_table_nodes(step, osmtype):
""" Replace a geometry in place by reinsertion and reindex database.
"""
""" Replace a geometry in place by reinsertion and reindex database."""
world.run_nominatim_script('setup', 'create-functions', 'create-partition-functions', 'enable-diff-updates')
if osmtype == 'node':
_insert_place_table_nodes(step.hashes, False)

View File

@@ -123,16 +123,19 @@ def match_geometry(coord, matchstring):
logger.debug("Distances expected: %f, got: %f" % (expdist, dist))
assert dist <= expdist, "Geometry too far away, expected: %f, got: %f" % (expdist, dist)
@world.absorb
def print_statement(element):
print '\n\n\n'+str(element)+'\n\n\n'
@world.absorb
def db_dump_table(table):
cur = world.conn.cursor()
cur.execute('SELECT * FROM %s' % table)
print '<<<<<<< BEGIN OF TABLE DUMP %s' % table
print '\n\n\n<<<<<<< BEGIN OF TABLE DUMP %s' % table
for res in cur:
print res
print '<<<<<<< END OF TABLE DUMP %s' % table
print '<<<<<<< END OF TABLE DUMP %s\n\n\n' % table
@world.absorb
def db_drop_database(name):