You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT id, version, tstamp::timestamp with time zoneAS created, tags, NULL::bigint[] AS nodes, NULL::jsonb AS members, geom, 'n'AS osm_type FROM nodes;
2
+
SELECT id, version, tstamp, changeset_id, user_id, tags, NULL::bigint[] AS nodes, NULL::jsonb AS members, geom, 'n'AS osm_type FROM nodes;
3
3
4
4
CREATE OR REPLACE TEMP VIEW way AS
5
-
SELECT id, version, tstamp::timestamp with time zoneAS created, tags, nodes, NULL::jsonb AS members, linestring AS geom, 'w'AS osm_type FROM ways;
5
+
SELECT id, version, tstamp, changeset_id, user_id, tags, nodes, NULL::jsonb AS members, linestring AS geom, 'w'AS osm_type FROM ways;
6
6
7
7
CREATE OR REPLACE TEMP VIEW relation AS
8
-
SELECT
9
-
id,
10
-
version,
11
-
tstamp::timestamp with time zoneAS created,
12
-
tags,
13
-
NULL::bigint[] AS nodes,
14
-
jsonb_agg(jsonb_build_object(
15
-
'type', CASE relation_members.member_type WHEN 'N' THEN 'node' WHEN 'W' THEN 'way' WHEN 'R' THEN 'relation' END,
16
-
'ref', relation_members.member_id,
17
-
'role', relation_members.member_role
18
-
)) AS members,
19
-
NULL::geometry AS geom,
20
-
'r'AS osm_type
21
-
FROM relations
22
-
JOIN relation_members ON
23
-
relation_members.relation_id=relations.id
24
-
GROUP BY
25
-
relations.id,
26
-
relations.version,
27
-
relations.tstamp,
28
-
relations.tags
29
-
;
8
+
SELECT id, version, tstamp, changeset_id, user_id, tags, NULL::bigint[] AS nodes, NULL::jsonb AS members, NULL::geometry AS geom, 'r'AS osm_type FROM relations;
30
9
31
10
CREATE OR REPLACE TEMP VIEW nwr AS
32
11
SELECT*FROM node
@@ -37,7 +16,7 @@ SELECT * FROM relation
37
16
;
38
17
39
18
CREATE OR REPLACE TEMP VIEW area AS
40
-
SELECT id, NULL::integerAS version, NULL::timestamp with time zoneAScreated, tags, NULL::bigint[] AS nodes, NULL::jsonb AS members, poly AS geom, 'a'AS osm_type FROM multipolygons WHERE id >3600000000
19
+
SELECT id, NULL::integerAS version, NULL::timestamp without time zoneAStstamp, NULL::bigintAS changeset_id, NULL::integerAS user_id, tags, NULL::bigint[] AS nodes, NULL::jsonb AS members, poly AS geom, 'a'AS osm_type FROM multipolygons WHERE id >3600000000
41
20
UNION ALL
42
-
SELECT id, version, tstamp::timestamp with time zoneAS created, tags, nodes AS nodes, NULL::jsonb AS members, ST_MakePolygon(linestring)::geometry(Geometry,4326) AS geom, 'w'AS osm_type FROM ways WHERE id <3600000000AND ST_IsClosed(linestring) AND ST_Dimension(ST_MakePolygon(linestring)) =2
21
+
SELECT id, version, tstamp::timestamp with time zoneAS created, changeset_id, user_id, tags, nodes AS nodes, NULL::jsonb AS members, ST_MakePolygon(linestring)::geometry(Geometry,4326) AS geom, 'w'AS osm_type FROM ways WHERE id <3600000000AND ST_IsClosed(linestring) AND ST_Dimension(ST_MakePolygon(linestring)) =2
-- Ensure all ways are downloaded; may be false at extract borders
39
+
-- If false, calculations like ST_Area would give invalid results
40
+
bool_and(ways.idIS NOT NULL) AND
41
+
-- Avoid dealing with very large multi-polygons
42
+
ST_NPoints(ST_Collect(ways.linestring)) <100000
43
+
) LOOP
44
+
BEGIN
45
+
IF ST_BuildArea(mp.linestrings) IS NOT NULLAND NOT ST_IsEmpty(ST_BuildArea(mp.linestrings))
46
+
-- Ensure no linestrings are dropped by ST_BuildArea, which would result in e.g. missing inners (see #2169)
47
+
AND ST_CoveredBy(ST_Points(mp.linestrings), ST_Points(ST_BuildArea(mp.linestrings))) THEN
48
+
WITH
49
+
unary AS (
50
+
SELECT
51
+
id +3600000000AS id, tags,
52
+
(ST_Dump(poly)).geom AS poly
53
+
FROM (VALUES (
54
+
mp.id,
55
+
mp.tags,
56
+
ST_BuildArea(mp.linestrings)
57
+
)) AS t(id, tags, poly)
58
+
),
59
+
simplified AS (
60
+
SELECT
61
+
id, tags,
62
+
ST_BuildArea(ST_Collect(
63
+
ST_ExteriorRing(poly),
64
+
(SELECT ST_Union(ST_MakePolygon(ST_InteriorRingN(poly, n))) FROM generate_series(1, ST_NumInteriorRings(poly)) AS t(n)) -- ST_MakePolygon is needed to union touching inner rings #2169
65
+
)) AS poly
66
+
FROM
67
+
unary
68
+
),
69
+
multi AS (
70
+
SELECT
71
+
id, tags,
72
+
ST_CollectionHomogenize(ST_Collect(poly)) AS poly
73
+
FROM
74
+
simplified
75
+
GROUP BY
76
+
id, tags
77
+
)
78
+
INSERT INTO
79
+
multipolygons
80
+
SELECT
81
+
*,
82
+
ST_IsValid(poly) AS is_valid -- see #2058 sometimes poly is considered valid but poly_proj not
0 commit comments