-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadPlanetWay.m
274 lines (261 loc) · 9.04 KB
/
loadPlanetWay.m
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
loadPlanetWay ; Load ways from planet.osm
; Copyright (C) 2008 Etienne Cherdlu <[email protected]>
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as
; published by the Free Software Foundation, either version 3 of the
; License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
; Loads nodes and segments from a planet.osm. Replaces any existing nodes and segments
; Deletes any nodes and segments that are not in planet.osm.
d add
;d delete
q
add ; Look for things that need to be added
;
n q,ccyymmdd
n sPipe,line
n gNodeCount,gNodeAdd,gNodeModified
n gWayCount,gWayAdd,gWayModified
n gRelCount,gRelAdd,gRelModified
n gNodeUser
;
s q=""""
s gNodeCount=0
s gNodeAdd=0 ; Count of missing nodes added
s gNodeModified=0 ; Count of nodes added that had different timestamps
s gWayCount=0
s gWayAdd=0 ; Count of missing ways added
s gWayModified=0 ; Count of ways added that had different timestamps
s gRelCount=0
s gRelAdd=0 ; Count of missing ways added
s gRelModified=0 ; Count of ways added that had different timestamps
s gNodeUser=0
;
;k ^osmLoadPlanet("node")
;k ^osmLoadPlanet("way")
;k ^osmLoadPlanet("relation")
k ^osmLoadPlanet("addWay")
;
s ^osmLoadPlanet("addWay","start")=$h
s ^osmLoadPlanet("addWay","pid")=$j
;
;
; Read the file
d openPipe^stream(.sPipe,"planetWay.pipe")
s line=$$read^stream(.sPipe) ; prolog
s line=$$read^stream(.sPipe) ; <osm...>
;
f d i line="</osm>" q
. s line=$$read^stream(.sPipe)
. i sPipe("recordCount")#100000=0 d
. . s ^osmLoadPlanet("addWay","currentLineCount")=sPipe("recordCount")
. . s ^osmLoadPlanet("addWay","currentNodeCount")=gNodeCount
. . s ^osmLoadPlanet("addWay","currentNodesAdded")=gNodeAdd
. . s ^osmLoadPlanet("addWay","currentNodesModified")=gNodeModified
. . s ^osmLoadPlanet("addWay","currentWayCount")=gWayCount
. . s ^osmLoadPlanet("addWay","currentWaysAdded")=gWayAdd
. . s ^osmLoadPlanet("addWay","currentWaysModified")=gWayModified
. . s ^osmLoadPlanet("addWay","currentRelCount")=gRelCount
. . s ^osmLoadPlanet("addWay","currentRelationsAdded")=gRelAdd
. . s ^osmLoadPlanet("addWay","currentRelationsModified")=gRelModified
. . s ^osmLoadPlanet("addWay","currentNodeUser")=gNodeUser
. ;i line["<node" s gNodeCount=gNodeCount+1 d addNode q
. i line["<way" s gWayCount=gWayCount+1 d addWay q
. ;i line["<relation" s gRelCount=gRelCount+1 d addRelation q
;
s ^osmLoadPlanet("addWay","end")=$h
s ^osmLoadPlanet("addWay","totalLines")=sPipe("recordCount")
s ^osmLoadPlanet("addWay","totalNodes")=gNodeCount
s ^osmLoadPlanet("addWay","nodesAdded")=gNodeAdd
s ^osmLoadPlanet("addWay","nodesModified")=gNodeModified
s ^osmLoadPlanet("addWay","totalWays")=gWayCount
s ^osmLoadPlanet("addWay","waysAdded")=gWayAdd
s ^osmLoadPlanet("addWay","waysModified")=gWayModified
s ^osmLoadPlanet("addWay","totalRelations")=gRelCount
s ^osmLoadPlanet("addWay","relationsAdded")=gRelAdd
s ^osmLoadPlanet("addWay","relationsModified")=gRelModified
s ^osmLoadPlanet("addWay","duration")=$p(^osmLoadPlanet("addWay","end"),",",2)-$p(^osmLoadPlanet("addWay","start"),",",2)
;
d close^stream(.sPipe)
;
q
addNode ; Private ; Check for nodes that need to be added
;
n id,user,oldUser,timestamp,oldTimestamp
n usersExists,users
;
s id=$p($p(line,"id="_q,2),q,1)
i id="" q
;
; ; Patch to add version tag
; ; **********************************
; i '$d(^node(id)) q
; i $d(^nodetag(id,"@version")) q
; s gNodeAdd=gNodeAdd+1
; s lat=$p(^node(id),$c(0),1),lon=$p(^node(id),$c(0),2)
; s version=$p($p(line,"version=""",2),"""",1) i version="" q
; s ^nodetag(id,"@version")=version
; s ^count("node","@version","*")=$g(^count("node","@version","*"))+1
; s ^count("node","@version",version)=$g(^count("node","@version",version))+1
; s qsBox=$$llToQs^quadString(lat,lon)
; s ^nodex("@version",version,qsBox,id)=""
; s ^nodex("@version","*",qsBox,id)=""
; s ^nodex("*",version,qsBox,id)=""
; i line["/>" q
; ;
; f d i line["</node>" q
; . s line=$$read^stream(.sPipe)
; q
; ;
; ; **********************************
s timestamp=$p($p(line,"timestamp="_q,2),q,1)
s ^osmLoadPlanet("node",id)=timestamp
i '$d(^nodeVersion(id)) s gNodeAdd=gNodeAdd+1 d add^node(.sPipe) q
;
s oldTimestamp=$p($g(^e($$qsBox^node(id),"n",id,"a")),$c(1),3)
i oldTimestamp="" s oldTimestamp=$g(^e($$qsBox^node(id),"n",id,"t","@timestamp"))
i $$toNumber^date(timestamp)>$$toNumber^date(oldTimestamp) s gNodeModified=gNodeModified+1 d add^node(.sPipe) q
;
i line["/>" q
;
f d i line["</node>" q
. s line=$$read^stream(.sPipe)
q
addWay ; Private ; Check for ways that need to be added
;
n id,timestamp,oldTimestamp
;
s id=$p($p(line,"id="_q,2),q,1)
i id="" q
;
; ; Patch to add version tag
; ; **********************************
; i '$d(^way(id)) q
; i $d(^waytag(id,"@version")) q
; s gWayAdd=gWayAdd+1
; s version=$p($p(line,"version=""",2),"""",1) i version="" q
; s ^waytag(id,"@version")=version
; s ^count("way","@version","*")=$g(^count("way","@version","*"))+1
; s ^count("way","@version",version)=$g(^count("way","@version",version))+1
; s qsBox=^way(id)
; s ^wayx("@version",version,qsBox,id)=""
; s ^wayx("@version","*",qsBox,id)=""
; s ^wayx("*",version,qsBox,id)=""
; i line["/>" q
; ;
; f d i line["</way>" q
; . s line=$$read^stream(.sPipe)
; q
; ;
; ; **********************************
s timestamp=$p($p(line,"timestamp="_q,2),q,1)
;s ^osmLoadPlanet("way",id)=timestamp
i '$d(^way(id)) s gWayAdd=gWayAdd+1 d add^way(.sPipe) q
;
s oldTimestamp=$g(^waytag(id,"@timestamp"))
i $$toNumber^date(timestamp)>$$toNumber^date(oldTimestamp) s gWayModified=gWayModified+1 d add^way(.sPipe) q
;
i line["/>" q
;
f d i line["</way>" q
. s line=$$read^stream(.sPipe)
q
addRelation ; Private ; Check for relations that need to be added
;
n id,timestamp,oldTimestamp
;
s id=$p($p(line,"id="_q,2),q,1)
i id="" q
;
; ; Patch to add version tag
; ; **********************************
; i '$d(^relation(id)) q
; i $d(^relationtag(id,"@version")) q
; s gRelAdd=gRelAdd+1
; s version=$p($p(line,"version=""",2),"""",1) i version="" q
; s ^relationtag(id,"@version")=version
; s ^count("relation","@version","*")=$g(^count("relation","@version","*"))+1
; s ^count("relation","@version",version)=$g(^count("relation","@version",version))+1
; s qsBox=^relation(id)
; s ^relationx("@version",version,qsBox,id)=""
; s ^relationx("@version","*",qsBox,id)=""
; s ^relationx("*",version,qsBox,id)=""
; i line["/>" q
; ;
; f d i line["</relation>" q
; . s line=$$read^stream(.sPipe)
; q
; ;
; ; **********************************
s timestamp=$p($p(line,"timestamp="_q,2),q,1)
s ^osmLoadPlanet("relation",id)=timestamp
i '$d(^relation(id)) s gRelAdd=gRelAdd+1 d add^relation(.sPipe) q
;
s oldTimestamp=$g(^relationtag(id,"@timestamp"))
i $$toNumber^date(timestamp)>$$toNumber^date(oldTimestamp) s gRelModified=gRelModified+1 d add^relation(.sPipe) q
;
i line["/>" q
;
f d i line["</relation>" q
. s line=$$read^stream(.sPipe)
q
delete ; Check for deletions
;
n planetDate
n itemCount,deleteCount,id,itemDate,date
;
w !,"Planet date ccyymmdd: " r planetDate i planetDate'?8n q
w !
;
; Delete nodes
s itemCount=0,deleteCount=0
s id=""
f d i id="" q
. s id=$o(^nodeVersion(id)) i id="" q
. s itemCount=itemCount+1 i itemCount#1000000=0 w "#"
. i $d(^osmLoadPlanet("node",id)) q
. s itemDate=$p($g(^e($$qsBox^node(id),"n",id,"a")),$c(1),3)
. i itemDate="" s itemDate=$g(^e($$qsBox^node(id),"n",id,"t","@timestamp"))
. i itemDate="" q
. s date=$tr($e(itemDate,1,10),"-","")
. i date<planetDate d delete^node(id) s deleteCount=deleteCount+1 i deleteCount#1000=0 w "."
;
w !,"Nodes: ",itemCount," items checked, ",deleteCount," items deleted."
;
; Delete ways
s itemCount=0,deleteCount=0
s id=""
f d i id="" q
. s id=$o(^waytag(id)) i id="" q
. s itemCount=itemCount+1 i itemCount#1000000=0 w "#"
. i $d(^osmLoadPlanet("way",id)) q
. s itemDate=$g(^waytag(id,"@timestamp"))
. i itemDate="" q
. s date=$tr($e(itemDate,1,10),"-","")
. i date<planetDate d delete^way(id) s deleteCount=deleteCount+1 i deleteCount#1000=0 w "."
;
w !,"Ways: ",itemCount," items checked, ",deleteCount," items deleted."
;
; Delete relations
s itemCount=0,deleteCount=0
s id=""
f d i id="" q
. s id=$o(^relationtag(id)) i id="" q
. s itemCount=itemCount+1 i itemCount#1000000=0 w "#"
. i $d(^osmLoadPlanet("relation",id)) q
. s itemDate=$g(^relationtag(id,"@timestamp"))
. i itemDate="" q
. s date=$tr($e(itemDate,1,10),"-","")
. i date<planetDate d delete^relation(id) s deleteCount=deleteCount+1 i deleteCount#1000=0 w "."
;
w !,"Relations: ",itemCount," items checked, ",deleteCount," items deleted."
;
q