...
 
Commits (4)
# Currently python2 because pyspatialite is 2 only
""" OSM LINZ Address
Usage: my_program.py [-h -o DIRECTORY --min-nodes=COUNT --max-nodes=COUNT --include-location=LEVEL] [-d DATABASE]
......@@ -16,10 +14,9 @@ Options:
from __future__ import print_function, division, unicode_literals
from lxml import etree as ET
from docopt import docopt
import itertools
import os
import pyspatialite.dbapi2 as db
import sys
import sqlite3.dbapi2 as db
def add_tag(node, k, v):
......@@ -27,9 +24,9 @@ def add_tag(node, k, v):
def generate_osmchange(dbfile, outdir,
changeset = 1,
min_nodes = 1, max_nodes = 8000,
include_location = False):
changeset=1,
min_nodes=1, max_nodes=8000,
include_location=False):
try:
os.makedirs(outdir)
......@@ -37,6 +34,9 @@ def generate_osmchange(dbfile, outdir,
pass
con = db.connect(dbfile)
con.enable_load_extension(True)
con.execute("SELECT load_extension('mod_spatialite')")
cur = con.cursor()
# Select subsets by place
......@@ -51,7 +51,7 @@ def generate_osmchange(dbfile, outdir,
changeset, include_location)
def generate_josm_tags_place(place, fn, outdir='.', source_rev='53'):
def generate_josm_tags_place(place, fn, outdir='.', source_rev='66'):
tags = []
tags.append('created_by=https://git.nzoss.org.nz/ewblen/osmlinzaddr/blob/master/osmlinzaddr.py')
tags.append('attribution=https://wiki.openstreetmap.org/wiki/Contributors#LINZ')
......@@ -65,7 +65,7 @@ def generate_josm_tags_place(place, fn, outdir='.', source_rev='53'):
def generate_osmchange_place(place, dbcursor, outdir,
changeset, include_location):
changeset, include_location):
if place[0] is None:
q = '''select linz_id, housenumber, street, x, y from linz_not_osm
......@@ -82,7 +82,7 @@ def generate_osmchange_place(place, dbcursor, outdir,
city, suburb = place[0:2]
if city is None or city == suburb:
if city is None:
fn = suburb
else:
fn = city + '-' + suburb
......@@ -107,14 +107,16 @@ def generate_osmchange_place(place, dbcursor, outdir,
generator="osmlinzaddr.py")
for r in lrows:
(linz_id, housenumber, street, x, y) = r
(linz_id, housenumber, street, lon, lat) = r
if lon > 180.0:
lon = lon - 360
create = ET.SubElement(osmchange, "create")
dnode = {
'id': "-%d" % linz_id,
'changeset': '0',
'lat': "%8.8f" % y,
'lon': "%8.8f" % x,
'lat': "%8.8f" % lat,
'lon': "%8.8f" % lon,
}
node = ET.SubElement(create, "node", dnode)
......@@ -134,7 +136,7 @@ def generate_osmchange_place(place, dbcursor, outdir,
if __name__ == '__main__':
opts = docopt(__doc__, version='osmlinzaddr v0.1')
opts = docopt(__doc__, version='osmlinzaddr v0.2')
for k in opts.keys():
try:
opts[k] = int(opts[k])
......