Commit afeb3907 authored by Eliot Blennerhassett's avatar Eliot Blennerhassett

Start on generation of changeset info.

parent 92c7c784
......@@ -19,7 +19,7 @@ from docopt import docopt
import itertools
import os
import pyspatialite.dbapi2 as db
import sys
def generate_osmchange(dbfile, outdir,
......@@ -67,23 +67,33 @@ def generate_osmchange(dbfile, outdir,
while True:
try:
r = rows.next()
suburb = r[5]
city = r[6]
linz_id, housenumber, street, x, y, suburb, city = r
num_nodes += 1
except StopIteration:
finished = True
if (not osmchange or finished
if (osmchange is None
or finished
or ((suburb != prev_suburb) and (num_nodes >= min_nodes))
or (num_nodes >= max_nodes)):
if osmchange:
if osmchange is not None:
osm = ET.Element('osm')
changeset = ET.SubElement(osm, 'changeset')
add_tag(changeset, "created_by", "https://git.nzoss.org.nz/ewblen/osmlinzaddr/blob/master/osmlinzaddr.py")
add_tag(changeset, "attribution", "https://wiki.openstreetmap.org/wiki/Contributors#LINZ")
add_tag(changeset, "source", "https://data.linz.govt.nz/layer/3353-nz-street-address")
add_tag(changeset, "comment", "LINZ address import %s" % fn)
tree = ET.ElementTree(osm)
path = outdir + "/linz_addr_%04d_%s.osm" % (block, fn)
tree.write(path, pretty_print=True)
tree = ET.ElementTree(osmchange)
fn = outdir + "/linz_addr_%04d_%s.osc" % (block, fn)
path = outdir + "/linz_addr_%04d_%s.osc" % (block, fn)
print("Writing", num_nodes, "to", fn)
tree.write(fn, pretty_print=True)
tree.write(path, pretty_print=True)
if finished:
break
......@@ -98,12 +108,11 @@ def generate_osmchange(dbfile, outdir,
fn = fn.replace('/', '_')
num_nodes = 1
osmchange = ET.Element('osmChange',
version="0.6",
generator="linz_address.py",
attribution="https://wiki.openstreetmap.org/wiki/Contributors#LINZ",
source="https://data.linz.govt.nz/layer/3353-nz-street-address"
)
osmchange = ET.Element('osmChange', version="0.6",
generator="osmlinzaddr.py")
if suburb != prev_suburb:
print('city', city, 'suburb/hamlet', suburb)
......@@ -112,17 +121,16 @@ def generate_osmchange(dbfile, outdir,
create = ET.SubElement(osmchange, "create")
dnode = {
'id': "-%d" % r[0],
'changeset': '-1',
'lat': "%8.8f" % r[4],
'lon': "%8.8f" % r[3],
'visible': "true",
'version': "1"
'id': "-%d" % linz_id,
'changeset': '0',
'lat': "%8.8f" % y,
'lon': "%8.8f" % x,
}
node = ET.SubElement(create, "node", dnode)
add_tag(node, "addr:housenumber", r[1])
add_tag(node, "addr:street", r[2])
add_tag(node, "LINZ:address_id", str(linz_id))
add_tag(node, "addr:housenumber", housenumber)
add_tag(node, "addr:street", street)
if include_location:
if city is not None:
add_tag(node, "addr:city", city)
......
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