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
- without the --slim option, only tables _point _line and _polygon are created, with filtered data. These tables also contain the geometry.
4
+
- with --slim, 3 other tables containing the raw OSM elements are created : _nodes, _ways, _rels
5
+
*/
6
+
7
+
/************** ABOUT TAGS COLUMNS *****************/
8
+
/*
9
+
- tags in tables _nodes, _ways, _rels are identical to the ones in OSM (they are "raw data" tables)
10
+
- but tags in tables _point _line and _polygon are always (slightly) different depending on the hstore options:
11
+
# With --hstore any tags without a column will be added to the hstore column.
12
+
# With --hstore-all all tags are added to the hstore column unless they appear in the style file with a delete flag
13
+
*/
14
+
15
+
/************** ABOUT METADATA *****************/
16
+
/* adding metadata to the DB requires -x option */
17
+
/* without it, all the CAST(tags->...) will return NULL */
18
+
19
+
20
+
/************** NODES *****************/
21
+
/* read data only in table planet_osm_point since planet_osm_nodes may be absent if you used flat nodes mode or did not use --slim */
22
+
CREATE OR REPLACE TEMP VIEW node AS
23
+
SELECT
24
+
osm_id AS id,
25
+
CAST(tags->'osm_version'ASinteger) AS version,
26
+
CAST(tags->'osm_timestamp'AStimestamp without time zone) AS created,
27
+
CAST(tags->'osm_changeset'ASbigint) AS changeset,
28
+
CAST(tags->'osm_uid'ASinteger) AS uid,
29
+
CAST(tags->'osm_user'AStext) AS user,
30
+
to_jsonb(tags) AS tags,
31
+
NULL::bigint[] AS nodes,
32
+
NULL::jsonb AS members,
33
+
ST_Transform(way,4326) AS geom,
34
+
'n'AS osm_type
35
+
FROM planet_osm_point;
36
+
37
+
/************** WAYS *****************/
38
+
/* ways are in tables _line and _polygon (excluding id<0 which are relations) */
39
+
CREATE OR REPLACE TEMP VIEW way AS
40
+
SELECT
41
+
l.osm_idAS id,
42
+
CAST(l.tags->'osm_version'ASinteger) AS version,
43
+
CAST(l.tags->'osm_timestamp'AStimestamp without time zone) AS created,
44
+
CAST(l.tags->'osm_changeset'ASbigint) AS changeset,
45
+
CAST(l.tags->'osm_uid'ASinteger) AS uid,
46
+
CAST(l.tags->'osm_user'AStext) AS user,
47
+
to_jsonb(l.tags) AS tags,
48
+
w.nodesAS nodes, /* replace by `NULL::bigint[] AS nodes` if did not use --slim */
49
+
NULL::jsonb AS members,
50
+
ST_Transform(l.way,4326) AS geom,
51
+
'w'AS osm_type
52
+
FROM planet_osm_line AS l
53
+
LEFT JOIN planet_osm_ways AS w ON osm_id = id /* remove if you did not use --slim */
54
+
UNION ALL
55
+
SELECT
56
+
p.osm_idAS id,
57
+
CAST(p.tags->'osm_version'ASinteger) AS version,
58
+
CAST(p.tags->'osm_timestamp'AStimestamp without time zone) AS created,
59
+
CAST(p.tags->'osm_changeset'ASbigint) AS changeset,
60
+
CAST(p.tags->'osm_uid'ASinteger) AS uid,
61
+
CAST(p.tags->'osm_user'AStext) AS user,
62
+
to_jsonb(p.tags) as tags,
63
+
w.nodesAS nodes, /* replace by `NULL::bigint[] AS nodes` if did not use --slim */
64
+
NULL::jsonb AS members,
65
+
ST_Transform(p.way,4326) AS geom,
66
+
'w'AS osm_type
67
+
FROM planet_osm_polygon AS p
68
+
LEFT JOIN planet_osm_ways AS w ON osm_id = id /* remove if you did not use --slim */
69
+
WHEREp.osm_id>0
70
+
;
71
+
72
+
/************** RELATIONS *****************/
73
+
/* complete version if you used --slim */
74
+
CREATE OR REPLACE TEMP VIEW relation AS
75
+
SELECT
76
+
r.idAS id,
77
+
CAST(r.tags->>'osm_version'ASinteger) AS version,
78
+
CAST(r.tags->>'osm_timestamp'AStimestamp without time zone) AS created,
79
+
CAST(r.tags->>'osm_changeset'ASbigint) AS changeset,
80
+
CAST(r.tags->>'osm_uid'ASinteger) AS uid,
81
+
CAST(r.tags->>'osm_user'AStext) AS user,
82
+
r.tagsas tags,
83
+
NULL::bigint[] AS nodes,
84
+
r.membersAS members,
85
+
ST_Transform(p.way,4326) AS geom,
86
+
'r'AS osm_type
87
+
FROM planet_osm_rels AS r
88
+
LEFT JOIN planet_osm_polygon AS p ON id =-osm_id;
89
+
90
+
/* simple version if you did not used --slim */
91
+
/* returns only some relations : multipolygon, boundary, routes */
92
+
/*
93
+
CREATE OR REPLACE TEMP VIEW relation AS
94
+
SELECT
95
+
-osm_id as id, /* relation ids are stored as negative values in planet_osm_polygon */
96
+
CAST(tags->'osm_version'ASinteger) AS version,
97
+
CAST(tags->'osm_timestamp'AStimestamp without time zone) AS created,
98
+
CAST(tags->'osm_changeset'ASbigint) AS changeset,
99
+
CAST(tags->'osm_uid'ASinteger) AS uid,
100
+
CAST(tags->'osm_user'AStext) AS user,
101
+
to_jsonb(tags) as tags,
102
+
NULL::bigint[] AS nodes,
103
+
NULL::jsonb AS members,
104
+
ST_Transform(way,4326) AS geom,
105
+
'r'AS osm_type
106
+
FROM planet_osm_polygon;
107
+
*/
108
+
109
+
/************** NWR *****************/
110
+
CREATE OR REPLACE TEMP VIEW nwr AS
111
+
SELECT*FROM node
112
+
UNION ALL
113
+
SELECT*FROM way
114
+
UNION ALL
115
+
SELECT*FROM relation
116
+
;
117
+
118
+
/************** AREA *****************/
119
+
/* complete version if you used --slim */
120
+
CREATE OR REPLACE TEMP VIEW area AS
121
+
SELECT
122
+
CASE
123
+
WHEN p.osm_id<0 THEN 3600000000-p.osm_id/* transform the negative values used for relations in _polygon table to the id format used for areas in overpass */
124
+
ELSE p.osm_id
125
+
END AS id,
126
+
CAST(p.tags->'osm_version'ASinteger) AS version,
127
+
CAST(p.tags->'osm_timestamp'AStimestamp without time zone) AS created,
128
+
CAST(p.tags->'osm_changeset'ASbigint) AS changeset,
129
+
CAST(p.tags->'osm_uid'ASinteger) AS uid,
130
+
CAST(p.tags->'osm_user'AStext) AS user,
131
+
to_jsonb(p.tags) as tags,
132
+
w.nodesAS nodes, /* For ways only : get nodes from table planet_osm_ways */
133
+
r.membersAS members, /* For relations only : get members from table planet_osm_rels */
134
+
ST_Transform(p.way,4326) AS geom,
135
+
'a'AS osm_type
136
+
FROM planet_osm_polygon AS p
137
+
LEFT JOIN planet_osm_ways AS w ON osm_id=w.id
138
+
LEFT JOIN planet_osm_rels AS r ON osm_id=-r.id
139
+
/* I don't know if JOIN to get nodes and members are useful for areas. Maybe geom is enough? */
140
+
;
141
+
142
+
/* simple version if you did not used --slim */
143
+
/*
144
+
CREATE OR REPLACE TEMP VIEW area AS
145
+
SELECT
146
+
CASE
147
+
WHEN p.osm_id<0 THEN 3600000000-p.osm_id /* transform the negative values used here for relations to the id format used for areas in overpass */
148
+
ELSE p.osm_id
149
+
END AS id,
150
+
CAST(p.tags->'osm_version'ASinteger) AS version,
151
+
CAST(p.tags->'osm_timestamp'AStimestamp without time zone) AS created,
152
+
CAST(p.tags->'osm_changeset'ASbigint) AS changeset,
0 commit comments