-
Notifications
You must be signed in to change notification settings - Fork 3
/
planetDump.m
140 lines (125 loc) · 2.83 KB
/
planetDump.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
planetDump ; Dump the planet
; Copyright (C) 2010 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/>.
; Public ; Run planet dump
; Dump all nodes, ways and relations.
;
;
l +^planetDump("running"):0 e q
d main
l -^planetDump("running")
q
main ;
n iDateTile,file
;
s iDateTime=$$toNumber^date($$nowZulu^date())
s file=$$createPlanetFile(iDateTime)
q
createPlanetFile(iDateTime) ;
;
; iDateTime = ccyymmddhhmmss
;
n directory,tempFile,zipFile,pipe
;
s directory=$g(^planetDump("directory"))
s pipe=directory_"earth.pipe"
s tempFile=directory_"earth-"_iDateTime_".temp"
s zipFile=directory_"earth-"_iDateTime_".osm.bz2"
zsystem "rm "_pipe_"; mkfifo "_pipe_"; bzip2 -9 <"_pipe_" >"_tempFile_" &"
;
o pipe:(nowrap:stream:fifo)
;
; Let's do it
u pipe
d xmlProlog^rest("")
d dump()
;
c pipe
;
zsystem "mv "_tempFile_" "_zipFile
;
q ""
dump() ; Emit everything
;
;
w "<osm"
w $$attribute^osmXml("version","0.6","")
w $$attribute^osmXml("generator","fosm 1.0","")
w ">",$c(13,10)
;
d nodes
d ways
d relations
;
w "</osm>",$c(13,10)
q
nodes ;
n q,n,count
;
k ^planetDump("nodeCount")
k ^planetDump("nodeCheckpoint")
;
s count=0
s q=""
f d i q="" q
. s q=$o(^e(q)) i q="" q
. s n=""
. f d i n="" q
. . s n=$o(^e(q,"n",n)) i n="" q
. . w $$xml^node("",n,"",q)
. . s count=count+1
. . i count#10000=0 d
. . . s ^planetDump("nodeCount")=count
. . . s ^planetDump("nodeCheckpoint")=q_"|"_n
s ^planetDump("nodeCount")=count
;
q
ways ;
n w,count
;
k ^planetDump("wayCount")
k ^planetDump("wayCheckpoint")
;
s count=0
s w=""
f d i w="" q
. s w=$o(^way(w)) i w="" q
. w $$xml^way("",w,"way|nd|tag|@*")
. s count=count+1
. i count#10000=0 d
. . s ^planetDump("wayCount")=count
. . s ^planetDump("wayCheckpoint")=w
s ^planetDump("wayCount")=count
;
q
relations ;
;
n r,count
;
k ^planetDump("relationCount")
k ^planetDump("relationCheckpoint")
;
s count=0
s r=""
f d i r="" q
. s r=$o(^relation(r)) i r="" q
. w $$xml^relation("",r,"relation|member|tag|@*")
. s count=count+1
. i count#10000=0 d
. . s ^planetDump("relationCount")=count
. . s ^planetDump("relationCheckpoint")=r
s ^planetDump("relationCount")=count
;
q