Skip to content

Commit

Permalink
Update addresses.sql
Browse files Browse the repository at this point in the history
Delete nodes that belonged to ways and relations deleted previously as reported at https://osmlatvija.github.io/zulip-archive/stream/360959-adreses/topic/Bots.20nodz.C4.93sa.20.22m.C4.81ju.22.html
  • Loading branch information
Davis-Klavins committed Apr 16, 2023
1 parent e2f252c commit 343ee5d
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions addresses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ FROM relations_addr_add_2 s
WHERE relations.id = s.id;

--Delete ways that are not part of relations, have no tags, but previously had only address tags.
DELETE
CREATE TEMPORARY TABLE ways_del AS
SELECT id
FROM ways
WHERE tags = ''::hstore
AND id NOT IN (
Expand All @@ -629,15 +630,30 @@ WHERE tags = ''::hstore
FROM ways_old
);

--Delete relations that have no tags, but previously had only address tags.
DELETE
FROM ways
WHERE id IN (
SELECT id
FROM ways_del
);

--Delete relations that have no tags, but previously had only address tags.
CREATE TEMPORARY TABLE relations_del AS
SELECT id
FROM relations
WHERE tags = ''::hstore
AND id IN (
SELECT id
FROM relations_old
);

DELETE
FROM relations
WHERE id IN (
SELECT id
FROM relations_del
);

--Add addresses for address points (nodes containing only addr:* tags) from the State Address Register. Only address codes not already assigned to isolated dwellings, ways and relations (buildings).
---Address code matches (address points added previously).
CREATE TEMPORARY TABLE nodes_addr_add_5 AS
Expand Down Expand Up @@ -845,7 +861,7 @@ SET tags = s.tags
FROM nodes_addr_add_2 s
WHERE nodes.id = s.id;

--Delete nodes that are not part of ways or relations, have no tags, but previously had only address tags.
--Delete nodes that are not part of ways or relations (except previously deleted ones), have no tags, but previously had only address tags.
CREATE TEMPORARY TABLE nodes_del AS
SELECT a.id
FROM nodes a
Expand All @@ -860,8 +876,20 @@ LEFT OUTER JOIN (
FROM way_nodes
) d ON a.id = d.node_id
WHERE a.tags = ''::hstore
AND c.member_id IS NULL
AND d.node_id IS NULL;
AND (
c.member_id IS NULL
OR a.id IN (
SELECT id
FROM relations_del
)
)
AND (
d.node_id IS NULL
OR a.id IN (
SELECT id
FROM ways_del
)
);

DELETE
FROM nodes
Expand Down

0 comments on commit 343ee5d

Please sign in to comment.