/
load-layers.sql
220 lines (196 loc) · 4.27 KB
/
load-layers.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
delete from roads;
delete from buildings;
delete from addr_points;
delete from rivers_ways;
delete from water_polygons;
delete from railroads;
delete from amenity_polygons;
delete from poi;
delete from coastline;
delete from barier_line;
delete from barier_point;
delete from landuse;
delete from leisure;
insert into roads
select
nextval('roads_id_seq'),
tags -> 'highway',
tags -> 'name',
tags -> 'ref',
tags -> 'oneway' in ('yes', '1', 'true'),
tags -> 'bridge' in ('yes', '1', 'true'),
tags -> 'tunnel' in ('yes', '1', 'true'),
tags -> 'surface',
tags -> 'smoothenes',
NULLIF(substring(tags -> 'maxspeed' from '^\\d+$'), '')::smallint,
NULLIF(substring(tags -> 'lanes' from '^\\d+$'), '')::smallint,
linestring
from
ways
where
tags ? 'highway'
and tags -> 'highway'
in ('motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'residential', 'unclassified', 'service', 'track', 'pedestrian', 'footway', 'path', 'steps')
or tags -> 'highway' like '%link'
and not tags @> hstore(ARRAY['area', 'yes']);
insert into buildings
select
nextval('buildings_id_seq'),
tags->'building',
tags->'name',
tags->'addr:housenumber',
tags->'addr:street',
NULLIF(substring(tags -> 'building:levels' from '^\\d+$'), '')::smallint,
ST_GeometryN(geom, 1)
from polygons
where tags ? 'building' and not tags -> 'building' in ('no', '0', 'false');
insert into addr_points
select
tags->'addr:housenumber',
tags->'addr:street',
null,
true,
ST_PointOnSurface(ST_GeometryN(geom, 1))
from polygons
where tags ? 'building' and tags ? 'addr:housenumber';
insert into addr_points
select
tags->'addr:housenumber',
tags->'addr:street',
null,
false,
geom
from nodes
where tags ? 'addr:housenumber';
update addr_points p
set angle=ST_Azimuth(ST_StartPoint(st_shortestline(p.geom, r.geom)), ST_EndPoint(st_shortestline(p.geom, r.geom))) * 57.2957795
from roads r
where r.name=p.street;
insert into rivers_ways
select
tags->'waterway',
tags->'name',
linestring
from ways
where tags ? 'waterway';
insert into water_polygons
select
tags -> 'water',
tags -> 'name',
geom
from polygons
where
tags ? 'water';
insert into water_polygons
select
tags -> 'water',
tags -> 'name',
geom
from polygons
where
not tags ? 'water' and tags @> 'waterway=>riverbank';
insert into railroads
select
tags->'railway',
linestring
from ways
where
tags ? 'railway';
insert into amenity_polygons
select
tags -> 'amenity',
tags -> 'name',
tags -> 'building' in ('yes', '1', 'true'),
false,
geom
from polygons
where
tags ? 'amenity';
insert into poi
select
'amenity',
tags -> 'amenity',
tags -> 'name',
concat_ws('; ', tags -> 'phone', tags -> 'contact:phone'),
concat_ws('; ', tags -> 'website', tags -> 'contact:website'),
tags->'opening_hours',
false,
geom
from nodes
where
tags ? 'amenity';
update amenity_polygons ap
set has_point_nsd = true
from poi p
where
St_Contains(ap.geom, p.geom) and p.primary_type = 'amenity' and p.secondary_type = ap.type;
insert into poi
select
'shop',
tags -> 'shop',
tags -> 'name',
concat_ws('; ', tags -> 'phone', tags -> 'contact:phone'),
concat_ws('; ', tags -> 'website', tags -> 'contact:website'),
tags->'opening_hours',
false,
geom
from nodes
where
tags ? 'shop';
insert into poi
select
'tourism',
tags -> 'tourism',
tags -> 'name',
concat_ws('; ', tags -> 'phone', tags -> 'contact:phone'),
concat_ws('; ', tags -> 'website', tags -> 'contact:website'),
tags->'opening_hours',
false,
geom
from nodes
where
tags ? 'tourism';
insert into poi
select
'pt',
tags -> 'bus_stop',
tags -> 'name',
null,
null,
tags->'opening_hours',
false,
geom
from nodes
where
tags @> 'highway=>bus_stop';
insert into coastline
select linestring from ways where tags @> 'natural=>coastline';
insert into barier_line
select
tags -> 'barrier',
tags -> 'name',
linestring
from ways
where tags ? 'barrier';
insert into barier_point
select
tags -> 'barrier',
tags -> 'name',
tags -> 'access',
geom
from nodes
where tags ? 'barrier';
insert into landuse
select
tags -> 'landuse',
tags -> 'name',
geom
from polygons
where tags ? 'landuse';
insert into leisure
select
tags -> 'leisure',
tags -> 'name',
geom
from polygons
where tags ? 'leisure';