Commit ab718f05 authored by Eliot Blennerhassett's avatar Eliot Blennerhassett

Use full housenumber incl. unitnumber from LINZ data

E.g. 2/345A
Unit number if present is part of full housenumber.
Stop emitting addr:unit
parent 8b4f9fc9
......@@ -2,7 +2,7 @@
# Currently python2 because pyspatialite is 2 only
""" OSM LINZ Address
Usage: my_program.py [-hl -o DIRECTORY --min-nodes=COUNT --max-nodes=COUNT] [-d DATABASE]
Usage: my_program.py [-h -o DIRECTORY --min-nodes=COUNT --max-nodes=COUNT --include-location=LEVEL] [-d DATABASE]
Options:
-d DATABASE --database DATABASE spatialite database containing linz_addr table [default: osmlinzaddr.sqlite]
......@@ -10,7 +10,7 @@ Options:
-o DIRECTORY --output=DIRECTORY Specify output directory. [default: linz_places]
--min-nodes=COUNT Minimum number of nodes per output file. [default: 1]
--max-nodes=COUNT Maximum number of nodes per output file. [default: 8000]
-l --include-location Include suburb and city tags in output.
--include-location=LEVEL 1:Include suburb/hamlet 2: and city tags in output. [default: 1]
"""
from __future__ import print_function, division, unicode_literals
......@@ -68,11 +68,11 @@ def generate_osmchange_place(place, dbcursor, outdir,
changeset, include_location):
if place[0] is None:
q = '''select * from linz_not_osm
q = '''select linz_id, housenumber, street, x, y from linz_not_osm
where city is NULL and suburb="{1}"
'''.format(*(place))
else:
q = '''select * from linz_not_osm
q = '''select linz_id, housenumber, street, x, y from linz_not_osm
where city="{0}" and suburb="{1}"
'''.format(*(place))
......@@ -107,8 +107,7 @@ def generate_osmchange_place(place, dbcursor, outdir,
generator="osmlinzaddr.py")
for r in lrows:
(linz_id, housenumber, street, x, y,
unit, number, suffix, high, suburb, city) = r
(linz_id, housenumber, street, x, y) = r
create = ET.SubElement(osmchange, "create")
dnode = {
......@@ -120,20 +119,15 @@ def generate_osmchange_place(place, dbcursor, outdir,
node = ET.SubElement(create, "node", dnode)
add_tag(node, "ref:linz:address_id", str(linz_id))
if unit is not None:
add_tag(node, "addr:unit", unit)
number = str(number)
if suffix:
number += suffix
add_tag(node, "addr:housenumber", number)
add_tag(node, "addr:housenumber", housenumber)
add_tag(node, "addr:street", street)
if city is not None:
add_tag(node, "addr:city", city)
add_tag(node, "addr:suburb", suburb)
else:
add_tag(node, "addr:hamlet", suburb)
if include_location:
if city is not None:
if include_location > 1:
add_tag(node, "addr:city", city)
add_tag(node, "addr:suburb", suburb)
else:
add_tag(node, "addr:hamlet", suburb)
tree = ET.ElementTree(osmchange)
tree.write(path, pretty_print=True)
......@@ -141,10 +135,17 @@ def generate_osmchange_place(place, dbcursor, outdir,
if __name__ == '__main__':
opts = docopt(__doc__, version='osmlinzaddr v0.1')
opts['--min-nodes'] = int(opts['--min-nodes'])
opts['--max-nodes'] = int(opts['--max-nodes'])
for k in opts.keys():
try:
opts[k] = int(opts[k])
except:
pass
print(opts)
if True:
generate_osmchange(opts['--database'], opts['--output'],
min_nodes=opts['--min-nodes'], max_nodes=opts['--max-nodes'],
include_location=opts['--include-location'])
generate_osmchange(
opts['--database'],
opts['--output'],
min_nodes=opts['--min-nodes'],
max_nodes=opts['--max-nodes'],
include_location=opts['--include-location']
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment