Commit 3875ecc0 authored by Eliot Blennerhassett's avatar Eliot Blennerhassett

Add more sql code for address duplicate detection

parent e8c30a71
-- .open "osmlinzaddr.sqlite"
-- spatialite "osmlinzaddr.sqlite" < import-xref.sql
-- as main
.trace ON
/*
ATTACH DATABASE "nz-street-address.gpkg" as "linz";
--SELECT AutoGPKGStart();
-- gpkg doesn't contain this one?!
-- INSERT into linz.spatial_ref_sys SELECT * FROM ol."spatial_ref_sys" WHERE srid = 4326
DELETE FROM linz_addr;
-- Convert LINZ geometry from NZ2000 to WGS84 SRID 4326
INSERT INTO linz_addr
......@@ -27,6 +29,7 @@ DETACH linz;
ATTACH DATABASE "nz_address-osm_raw.sqlite" AS "osm";
DELETE FROM osm_addr;
-- Gathering the OSM addresses as points
INSERT INTO osm_addr
SELECT
......@@ -61,6 +64,9 @@ DETACH osm;
-- matching linz vs OSM nodes on housenumber and empirically determined distance
-- (Will take quite a long time!)
--
DELETE FROM osm_linz;
-- first, exact match on road, number; close proximity
INSERT INTO osm_linz
SELECT
o.osm_id as osm_id,
......@@ -69,7 +75,63 @@ SELECT
FROM osm_addr as o
JOIN linz_addr as l on
o.housenumber = l.full_address_number
-- and (o.street IS NULL or (o.street = l.full_road_name))
and o.street = l.full_road_name
and D < 0.001;
-- remaining OSM entries with streets
-- 6539/46858
create table temp.inexact as
select type, osm_addr.osm_id, housenumber, street, geom
from osm_addr
left outer join osm_linz as done
on osm_addr.osm_id = done.osm_id
where done.osm_id is null and street is not null
order by street, housenumber
;
-- and without streets
insert into temp.inexact
select type, osm_addr.osm_id, housenumber, street, geom
from osm_addr
left outer join osm_linz as done
on osm_addr.osm_id = done.osm_id
where done.osm_id is null and street is null
order by street, housenumber
;
--
-- Inexact matches with LINZ data on housenumber and proximity
CREATE TABLE temp.linz_inexact AS
SELECT
o.osm_id as osm_id,
l.linz_id as linz_id,
Distance(o.geom, l.geom) as D
FROM temp.inexact as o
JOIN linz_addr as l on
o.housenumber = l.full_address_number
and D < 0.001
;
-- Can be reviewed, then
INSERT INTO osm_linz
SELECT * from temp.linz_inexact;
-- The LINZ addresses identified as not already in OSM
drop table linz_not_osm;
create table linz_not_osm as
select
linz_addr.linz_id,
linz_addr.full_address_number as housenumber,
linz_addr.full_road_name as street,
X(linz_addr.geom) as x,
Y(linz_addr.geom) as y,
linz_addr.suburb_locality as s,
linz_addr.town_city as c
from linz_addr
left outer join osm_linz
on (osm_id = linz_addr.linz_id)
where
osm_linz.linz_id is NULL
and linz_addr.addr_type != "Water"
order by linz_addr.town_city, linz_addr.suburb_locality
;
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