-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrelation.m
681 lines (634 loc) · 20.4 KB
/
relation.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
relation ; Relation Class
; 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/>.
add(sRelation,delete) ; Public ; Add a relation
; #sRelation = stream object containing a relation in osm xml format
;
n line,relationId,users,lat,lon,timestamp,user,qsBox,uid,version,changeset
n bllat,bllon,trlat,trlon
n conflict,currentUid,a,blockedByUid
;
s line=sRelation("current")
;
s relationId=$$getAttribute^osmXml(line,"id")
s version=$$getAttribute^osmXml(line,"version")
s changeset=$$getAttribute^osmXml(line,"changeset")
s timestamp=$$getAttribute^osmXml(line,"timestamp")
s user=$$getAttribute^osmXml(line,"user")
s uid=$$getAttribute^osmXml(line,"uid")
;
; Don't load older versions
i ($g(^relationtag(relationId,"@version"))>version) d q
. ;
. ; Skip the rest of the element
. i line["/>" q
. f d i line["</relation>" q
. . s line=$$read^stream(.sRelation)
;
; Conflict checks
s conflict=0
s currentUid=$g(^relationtag(relationId,"@uid"),0)
s a=version_$c(1)_changeset_$c(1)_timestamp_$c(1)_uid
;
; Don't load forked elements
i 'conflict,$d(^relationtag(relationId,"@fork")) d
. s conflict=1
. d log^conflict("relation",relationId,currentUid,a,"Edited in fosm")
;
; Don't load edits from blocked users
i 'conflict,uid'="",$g(^user(uid,"osmImport"))="block" d
. s conflict=1
. s blockedByUid=$g(^user(uid,"blockedByUid"),uid)
. d log^conflict("relation",relationId,blockedByUid,a,"User #"_uid_" ("_$g(^user(uid,"name"),"unknown")_") blocked by "_blockedByUid)
;
; Don't delete if current user's edits are marked to be preserved
i 'conflict,delete,currentUid'="",$g(^user(currentUid,"osmImport"))="doNotDelete" d
. s conflict=1
. s blockedByUid=$g(^user(currentUid,"blockedByUid"),currentUid)
. d log^conflict("relation",relationId,blockedByUid,a,"Deletion of element belonging to #"_currentUid_" ("_$g(^user(currentUid,"name"),"unknown")_") preserved. Do not delete requested by user #"_blockedByUid)
;
; If no conflict then delete old relation
i 'conflict d delete(relationId,delete)
;
d setTag(relationId,"@timestamp",timestamp,changeset,version,delete,conflict)
d setTag(relationId,"@user",user,changeset,version,delete,conflict)
d setTag(relationId,"@uid",uid,changeset,version,delete,conflict)
d setTag(relationId,"@version",version,changeset,version,delete,conflict)
d setTag(relationId,"@changeset",changeset,changeset,version,delete,conflict)
i delete d setTag(relationId,"@visible","false",changeset,version,delete,conflict)
i conflict d setTag(relationId,"@conflict","true",changeset,version,delete,conflict)
;
; Changeset by version index
i 'conflict d
. s ^relationVersion(relationId,"v",version)=changeset
. s ^relationVersion(relationId,"c",changeset,version)=""
;
; Changeset headers
s ^c(changeset)=""
s ^c(changeset,"r",relationId)=""
s ^c(changeset,"r",relationId,"v",version)=""
;
s sequenceNo=0
i line'["/>" f d i line["</relation>" q
. s line=$$read^stream(.sRelation)
. i line["<member" s sequenceNo=sequenceNo+1 d addMember(.sRelation,relationId,sequenceNo,changeset,version,delete,conflict) q
. i line["<tag" d addTag(.sRelation,relationId,changeset,version,delete,conflict) q
;
i 'conflict,'delete d indexTags(relationId)
;
; Create export index
i 'conflict s ^export($$nowZulu^date(),"r",changeset,relationId,version)=""
;
; Update user class
d add^user(uid,user)
;
d onEdit^user(uid)
;
; Update metrics (don't count conflicted relations)
i 'conflict d
. i version=1 d update^metric("osmRelationCount",1)
. i delete d update^metric("osmRelationCount",-1)
. d update^metric("osmRelationEdits",1)
;
q
addDiff(sRelation,delete,changeset) ; Public ; Add a relation
; #sRelation = stream object containing a relation in osm xml format
;
n line,relationId,users,lat,lon,timestamp,user,qsBox,uid,version,ok
n bllat,bllon,trlat,trlon
;
s line=sRelation("current")
;
s relationId=$$getAttribute^osmXml(line,"id")
s timestamp=$$nowZulu^date()
;
; New relations
i relationId<0 d
. s oldId=relationId
. l +^id("relation")
. s relationId=^id("relation")+1
. s ^id("relation")=relationId
. l -^id("relation")
. s newId=relationId
. s version=1
. ;
. ; Add to new item map
. s ^temp($j,"relation",oldId)=newId
;
; Existing relations
s ok=1
e d i 'ok q 0
. s version=$$getAttribute^osmXml(line,"version")
. ; check version match
. i $$currentVersion(relationId)'=version d error409^http("Version mismatch: Provided "_version_", server had: "_$$currentVersion(relationId)_" of Relation "_relationId) s ok=0 q ; Version mismatch
. s oldId=relationId
. s newId=relationId
. s version=version+1
. d delete(relationId,delete)
;
s uid=^c(changeset,"t","@uid")
s user=^user(uid,"name")
i user["'" s user=$$xmlEscapeApostrophe(user)
;
d setTag(relationId,"@timestamp",timestamp,changeset,version,delete,0)
d setTag(relationId,"@user",user,changeset,version,delete,0)
d setTag(relationId,"@uid",uid,changeset,version,delete,0)
d setTag(relationId,"@version",version,changeset,version,delete,0)
d setTag(relationId,"@changeset",changeset,changeset,version,delete,0)
d setTag(relationId,"@fork",1,changeset,version,delete,0)
i delete d setTag(relationId,"@visible","false",changeset,version,delete,0)
;
; Changeset by version index
s ^relationVersion(relationId,"v",version)=changeset
s ^relationVersion(relationId,"c",changeset,version)=""
;
; Changeset headers
s ^c(changeset)=""
s ^c(changeset,"r",relationId)=""
s ^c(changeset,"r",relationId,"v",version)=""
;
s sequenceNo=0
i line'["/>" f d i line["</relation>" q
. s line=$$read^stream(.sRelation)
. i line["<member" s sequenceNo=sequenceNo+1 d addMember(.sRelation,relationId,sequenceNo,changeset,version,delete,0) q
. i line["<tag" d addTag(.sRelation,relationId,changeset,version,delete,0) q
;
i 'delete d indexTags(relationId)
;
; Create export index (uses the same timestamp as the element just created)
s ^export(timestamp,"r",changeset,relationId,version)=""
;
s rSeq=$g(^response($j))+1
s ^response($j)=rSeq
;
i delete s newId="",version=""
;
s ^response($j,rSeq,"oldId")=oldId
s ^response($j,rSeq,"newId")=newId
s ^response($j,rSeq,"version")=version
s ^response($j,rSeq,"element")="relation"
;
d onEdit^user(uid)
;
; Update metrics
i version=1 d update^metric("fosmRelationCount",1)
i delete d update^metric("fosmRelationCount",-1)
d update^metric("fosmRelationEdits",1)
;
q 1
addMember(sRelation,relationId,sequenceNo,changeset,version,delete,conflict) ; Private ; Add a member to a relation
;
n line,type,role,ref
;
s line=sRelation("current")
i line'["/>" f d i line["/>" q
. s line=line_$$read^stream(.sRelation)
;
s type=$$getAttribute^osmXml(line,"type") i type="" q
s role=$$getAttribute^osmXml(line,"role") ; null roles are permitted
s ref=$$getAttribute^osmXml(line,"ref") i ref="" q
i ref<0 s ref=$g(^temp($j,type,ref)) ; TODO: This could be a forward reference - if undef then allocate at this point and use when we get to it.
;
i type'="" d
. s ^c(changeset,"r",relationId,"v",version,"s",sequenceNo,"t")=type
. i 'conflict,'delete s ^relation(relationId,"seq",sequenceNo,"type")=type
;
i ref'="" d
. s ^c(changeset,"r",relationId,"v",version,"s",sequenceNo,"i")=ref
. i 'conflict,'delete s ^relation(relationId,"seq",sequenceNo,"ref")=ref
;
s ^c(changeset,"r",relationId,"v",version,"s",sequenceNo,"r")=role
i 'conflict,'delete s ^relation(relationId,"seq",sequenceNo,"role")=role
;
i 'conflict,'delete s ^relationMx(type,ref,relationId)=""
q
addTag(sRelation,relationId,changeset,version,delete,conflict) ; Private ; Load a tag and add it
;
n line,k,v
;
s line=sRelation("current")
i line'["/>" f d i line["/>" q
. s line=line_$$read^stream(.sRelation)
;
s k=$$getAttribute^osmXml(line,"k") i k="" q
i $l(k)>100 s k=$e(k,1,100)_".."
s v=$$getAttribute^osmXml(line,"v")
i v["'" s v=$$xmlEscapeApostrophe(v)
i $l(v)>4000 s v=$e(v,1,4000)_".."
d setTag(relationId,k,v,changeset,version,delete,conflict)
q
setTag(relationId,k,v,changeset,version,delete,conflict) ; Private ; Add a tag
;
; Add to changeset
s ^c(changeset,"r",relationId,"v",version,"t",k)=v
;
; Add to active dataset
i 'conflict,'delete d
. s ^relationtag(relationId,k)=v
q
getTag(relationId,tag) ; Public ; Get the value of a tag for a relation
;
i relationId="" q ""
;
q $g(^relationtag(relationId,tag))
indexTags(relationId) ; Private ; Create index entries for a single relation
;
n k,v
n bllat,bllon,trlat,trlon
;
d bbox(relationId,.bllat,.bllon,.trlat,.trlon)
s qsBox=$$bbox^quadString(bllat,bllon,trlat,trlon)
i qsBox="" s qsBox="*"
;
; If a relation has no members, then it will not have any spatial extent. Use # to indicate this.
i $o(^relation(relationId,""))="" s qsBox="#"
;
s k=""
f d i k="" q
. s k=$o(^relationtag(relationId,k)) i k="" q
. i k="@xapi:users" q
. i k="@version" q
. i k="@timestamp" q
. i k="@fork" q
. s v=^relationtag(relationId,k)
. i $l(v)>100 s v=$e(v,1,100)_".."
. i v="" q
. s ^relationx(k,v,qsBox,relationId)=""
. s ^relationx(k,"*",qsBox,relationId)=""
;
s ^relation(relationId)=qsBox_$c(1)_bllat_$c(1)_bllon_$c(1)_trlat_$c(1)_trlon ; Save the qsBox because a member might get moved independently
s ^relationx("*","*",qsBox,relationId)=""
;
q
xml(indent,relationId,select) ; Public ; Generate xml for a relation
;
;
n user,uid,uidUser,timestamp,version,changeset
n xml
;
s user=$g(^relationtag(relationId,"@user"))
s uid=$g(^relationtag(relationId,"@uid"))
s timestamp=$g(^relationtag(relationId,"@timestamp"))
s version=$g(^relationtag(relationId,"@version"))
s changeset=$g(^relationtag(relationId,"@changeset"))
;
s xml="<relation"
s xml=xml_$$attribute^osmXml("id",relationId)
s xml=xml_$$attribute^osmXml("visible","true")
i timestamp'="" s xml=xml_$$attribute^osmXml("timestamp",timestamp)
i version'="" s xml=xml_$$attribute^osmXml("version",version)
i changeset'="" s xml=xml_$$attribute^osmXml("changeset",changeset)
i user'="" s xml=xml_$$attribute^osmXml("user",user)
i uid'="" s xml=xml_$$attribute^osmXml("uid",uid)
;
s xml=xml_">"_$c(13,10)
;
d xmlMembers(relationId,.xml)
;
d xmlTags(relationId,.xml)
s xml=xml_"</relation>"_$c(13,10)
;
q xml
xmlMembers(wayId,xml) ; Public ; Generate xml for a relation's members
;
n seq,type,ref,role
;
s seq=""
f d i seq="" q
. s seq=$o(^relation(relationId,"seq",seq)) i seq="" q
. s xml=xml_"<member"
. s type=$g(^relation(relationId,"seq",seq,"type"))
. s ref=$g(^relation(relationId,"seq",seq,"ref"))
. s role=$g(^relation(relationId,"seq",seq,"role"))
. i type'="" s xml=xml_$$attribute^osmXml("type",type)
. i ref'="" s xml=xml_$$attribute^osmXml("ref",ref)
. s xml=xml_$$attribute^osmXml("role",role)
. s xml=xml_"/>"_$c(13,10)
. i $l(xml)>10000 d w^write(xml) s xml=""
q
xmlTags(id,xml) ; Public ; Generate xml for a relation's tags
;
n k
;
s k=""
f d i k="" q
. s k=$o(^relationtag(id,k)) i k="" q
. i $e(k,1)="@" s k="@zzzzzzzzzzzzzzzzzz" q ; Skip attributes
. i $d(^relationtag(id,k))#10=0 q
. s xml=xml_"<tag"
. s xml=xml_$$attribute^osmXml("k",k)
. s xml=xml_" v='"_^relationtag(id,k)_"'" ; Tags are stored as escaped strings
. s xml=xml_"/>"_$c(13,10)
. i $l(xml)>10000 d w^write(xml) s xml=""
q
bbox(relationId,bllat,bllon,trlat,trlon,parents,recalculate) ; Public ; Get the bbox for a relation
;
; Inputs:
; recalculate - 0 = used stored value if available (default). The stored value may be wrong if nodes have been moved subsequently.
; 1 = recalculate from current node locations (slow).
;
n seq,ref,type,relation
n bllat1,bllon1,trlat1,trlon1
;
s recalculate=$g(recalculate)=1
;
; Use previously calculated values if present
i 'recalculate d i bllat'="" q
. s relation=$g(^relation(relationId))
. s bllat=$p(relation,$c(1),2)
. s bllon=$p(relation,$c(1),3)
. s trlat=$p(relation,$c(1),4)
. s trlon=$p(relation,$c(1),5)
;
; Create list of parents to handle recursive relations
s parents=$g(parents)_"|"_relationId
;
s bllat=999999,bllon=999999,trlat=-999999,trlon=-999999
s bllat1=999999,bllon1=999999,trlat1=-999999,trlon1=-999999
s seq=""
f d i seq="" q
. s seq=$o(^relation(relationId,"seq",seq)) i seq="" q
. s ref=$g(^relation(relationId,"seq",seq,"ref"))
. s type=$g(^relation(relationId,"seq",seq,"type")) i type="" q
. i type="node" d bbox^node(ref,.bllat1,.bllon1,.trlat1,.trlon1)
. i type="way" d bbox^way(ref,.bllat1,.bllon1,.trlat1,.trlon1)
. i type="relation",parents_"|"'[("|"_ref_"|") d bbox^relation(ref,.bllat1,.bllon1,.trlat1,.trlon1,parents,recalculate)
. i trlat1>trlat s trlat=trlat1
. i bllat1<bllat s bllat=bllat1
. i trlon1>trlon s trlon=trlon1
. i bllon1<bllon s bllon=bllon1
q
delete(relationId,delete) ; Public ; Delete a relation
;
n qsBox
;
i relationId="" q
i '$d(^relation(relationId)) q
;
s qsBox=$p($g(^relation(relationId)),$c(1),1)
;
d deleteMembers(relationId)
i qsBox'="" d deleteTags(relationId,qsBox)
;
i qsBox'="" k ^relationx("*","*",qsBox,relationId)
k ^relation(relationId)
;
q
deleteMembers(relationId) ; Private ; Delete all members of a relation
;
n seq,ref,type
;
s seq=""
f d i seq="" q
. s seq=$o(^relation(relationId,"seq",seq)) i seq="" q
. s ref=$g(^relation(relationId,"seq",seq,"ref"))
. s type=$g(^relation(relationId,"seq",seq,"type"))
. i type'="",ref'="" k ^relationMx(type,ref,relationId)
. k ^relation(relationId,"seq",seq)
;
q
deleteTags(relationId,qsBox) ; Private ; Delete all tags and tag indices for a relation
;
n key,value
;
s key=""
f d i key="" q
. s key=$o(^relationtag(relationId,key)) i key="" q
. s value=^relationtag(relationId,key)
. i value="" q
. i $l(value)>100 s value=$e(value,1,100)_".."
. k ^relationx(key,value,qsBox,relationId)
. k ^relationx(key,"*",qsBox,relationId)
;
k ^relationtag(relationId)
;
q
appendUser(users,user) ; Private ; Append a user to a list of users
;
s user=$tr(user,",","") ; Remove commas from name
;
i $$contains^string(users,user,",") q users
;
i users="" s users=user
e s users=users_","_user
q users
xmlEscapeApostrophe(string) ; Private ; Escape apostrophe
;
n out,x,c
;
s out=""
f x=1:1:$l(string) d
. s c=$e(string,x)
. i "'"[c s out=out_"'" q
. s out=out_c
q out
hasRealTag(id) ; Public ; Does this way have a real tag?
;
n hasRealTag,tag
;
s hasRealTag=0
s tag="@zzzzzzzzzzzzzzzz"
f d i tag="" q
. s tag=$o(^relationtag(id,tag)) i tag="" q
. s hasRealTag=1,tag=""
;
q hasRealTag
versionAtChangeset(relationId,changeset,relationChangeset,relationVersion) ; Public ; Get the changeset and version that was current at a given changeset time
;
; Usage:
; d versionAtChangeset^relation(relationId,changeset,.relationChangeset,.relationVersion)
; Output:
; relationChangeset - null if not found
; relationVersion - null if not found
;
s relationChangeset=changeset
s relationVersion=""
i '$d(^relationVersion(relationId,"c",relationChangeset)) s relationChangeset=$o(^relationVersion(relationId,"c",relationChangeset),-1) i relationChangeset="" q
s relationVersion=$o(^relationVersion(relationId,"c",relationChangeset,""),-1) i relationVersion="" s relationChangeset="" q
;
q
restRelation(string) ; Public ; Single relation query
;
; Inputs:
; string - relationId[ /full | /version/full ]
;
n step,relationId,full,logId,indent
n seq,nodeId,wayId,ndSeq,subRelationId
n count
;
; Get next step
s step=$p(string,SLASH,1),string=$p(string,SLASH,2,$l(string))
s relationId=step
;
; Get next step
s step=$p(string,SLASH,1),string=$p(string,SLASH,2,$l(string))
;
; Three choices here:
; / - current relation only
; /history - all versions of relation
; /full - current relation plus current members
; /#version/full - historic way plus historic nodes
s full=0
i step="" s full=0
i step="full" s full=1
i step="history" d restRelationHistory(relationId) q
i step?1.n d restRelation^relationVersion(relationId,step,string) q
;
k ^temp($j)
s count=0
;
s logId=$$logStart^xapi("relation/"_relationId_$s(full:"/full",1:""),"")
;
; Bad query?
i relationId'?1.n d notFound^http,logEnd^xapi(logId,0,"404 Not found") q
;
; Is it there?
i '$d(^relation(relationId)) d gone^http,logEnd^xapi(logId,0,"410 Gone") q
;
d header^http("text/xml")
d xmlProlog^rest("")
;
s indent=""
d osm^xapi(indent)
;
; Select all nodes that belong to this relation and all nodes that belong to
; ways that belong to this relation
s seq=""
i full f d i seq="" q
. s seq=$o(^relation(relationId,"seq",seq)) i seq="" q
. ;
. ; Nodes
. i ^relation(relationId,"seq",seq,"type")="node" d q
. . s nodeId=^relation(relationId,"seq",seq,"ref")
. . i $d(^temp($j,"node",nodeId)) q
. . s ^temp($j,"node",nodeId)=""
. . w $$xml^node(indent,nodeId,"node|@*|tag|")
. . s count=count+1
. ;
. ; Nodes within ways
. i ^relation(relationId,"seq",seq,"type")="way" d q
. . s wayId=^relation(relationId,"seq",seq,"ref")
. . s ndSeq=""
. . f d i ndSeq="" q
. . . s ndSeq=$o(^way(wayId,ndSeq)) i ndSeq="" q
. . . s nodeId=^way(wayId,ndSeq)
. . . i $d(^temp($j,"node",nodeId)) q
. . . s ^temp($j,"node",nodeId)=""
. . . w $$xml^node(indent,nodeId,"node|@*|tag|")
. . . s count=count+1
;
; Select all ways that belong to this relation
s seq=""
i full f d i seq="" q
. s seq=$o(^relation(relationId,"seq",seq)) i seq="" q
. i ^relation(relationId,"seq",seq,"type")'="way" q
. s wayId=^relation(relationId,"seq",seq,"ref")
. w $$xml^way(indent,wayId,"way|@*|nd|tag|")
. s count=count+1
;
; Select this relation
w $$xml(indent,relationId,"relation|@*|member|tag|")
s count=count+1
;
; Select all relations that belong to this relation
s seq=""
i full f d i seq="" q
. s seq=$o(^relation(relationId,"seq",seq)) i seq="" q
. i ^relation(relationId,"seq",seq,"type")'="relation" q
. s subRelationId=^relation(relationId,"seq",seq,"ref")
. w $$xml(indent,subRelationId,"relation|@*|member|tag|")
. s count=count+1
;
w indent,"</osm>",$c(13,10)
;
d logEnd^xapi(logId,count,"")
;
q
restRelations(step,string) ; Public ; Multi node query
;
n logId,relationIds,ok,i,relationId,indent
;
s logId=$$logStart^xapi($$decode^xapi(step),"")
;
s relationIds=$p(step,EQUALS,2)
;
; Validate query
s ok=1
f i=1:1:$l(relationIds,",") d i 'ok q
. s relationId=$p(relationIds,",",i)
. i relationId'?1.n d notFound^http,logEnd^xapi(logId,0,"404 Not found") s ok=0 q
. i '$d(^relation(relationId)) d gone^http,logEnd^xapi(logId,0,"410 Gone") s ok=0 q
i 'ok q
;
d header^http("text/xml")
d xmlProlog^rest("")
;
s indent=""
d osm^xapi(indent)
;
f i=1:1:$l(relationIds,",") w $$xml(indent,$p(relationIds,",",i),"relation|@*|member|tag|")
;
w indent,"</osm>",$c(13,10)
;
d logEnd^xapi(logId,i,"")
;
q
restRelationHistory(relationId) ; Public ; All versions of relation
;
n logId,count,indent
n version,changeset
;
s count=0
s logId=$$logStart^xapi("relation/"_relationId_"/history","")
;
; Bad query?
i relationId'?1.n d notFound^http,logEnd^xapi(logId,0,"404 Not found") q
;
; Is it there?
i '$d(^relationVersion(relationId)) d notFound^http,logEnd^xapi(logId,0,"404 Not found") q
;
d header^http("text/xml")
d xmlProlog^rest("")
;
s indent=""
d osm^xapi(indent)
;
; Iterate all changesets
s version=""
f d i version="" q
. s version=$o(^relationVersion(relationId,"v",version)) i version="" q
. s changeset=^relationVersion(relationId,"v",version)
. ;
. w $$xml^relationVersion(indent,relationId,changeset,version,"relation|@*|member|tag|")
. s count=count+1
;
w indent,"</osm>",$c(13,10)
;
d logEnd^xapi(logId,count,"")
;
q
currentVersion(relationId) ; Public ; Return the current version number of a relation
;
; Usage: s currentVersion=$$currentVersion^relation(relationId)
; Input:
; relationId - relation id, must not be null
; Output:
; currentVersion - if the relation does not exists then null is returned
;
n version
;
s version=$o(^relationVersion(relationId,"v",""),-1)
i version="" s version=$g(^relationtag(relationId,"@version"))
q version