/
listJSONExample.vbs
2053 lines (1750 loc) · 81.7 KB
/
listJSONExample.vbs
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
option explicit
!INC Local Scripts.EAConstants-VBScript
' script: listJsonExample
' purpose: Generates example objects in a combination (?) of GeoJSON and JSON-FG from all non-abstract feature types in a model
' note: Important vbs-snag: decimal point character for numbers need to be set to "." in the regional settings
'
' author: Kent Jonsrud
'
' version: 2022-11-11/30 geometry types (WGS84 TBD)
' version: 2022-11-09 rydda i skilletegn, lagt inn en links
' version: 2022-11-04 timestamp
' version: 2022-10-17 Based on a script listGMLExample from 2018 to generate GML-example in system output from classe in a ApplicationSchema package
'
' candidates for improvement:
' TBD: variants of GM_Solid geometry (Polyhedron, Prism, ...)
' TBD: add the prefix on elements from external ApplicationSchema packages, sort (attributes?+roles!) by tagged value sequenceNumber
' TBD: utf8 (for all codes with any sami characters) does not survive the clipboard, should concider to write directly to file
' TBD: loopdetection on inheritance and datatype, association is ok-ish
' TBD: standard (getFeatureById-) container for the single object selection
' TBD: documentation and cleanup
DIM epsg, debug, namespace, kortnavn, pnteller, cuteller, suteller, soteller, obteller, eastoffset, eastdelta, ftcount, ftnum, gnum
'roof - starting on 1
dim p1(18,2)
'walls - starting on 1
dim b1(29,2)
'surface - starting on 0
dim s1(7,2)
'point
dim r1, r2, r3
'curve - starting on 1
dim q1(5), q2(5), q3(5)
debug = false
sub listJsonExample()
' Show and clear the script output window
Repository.EnsureOutputVisible "Script"
dim ftname
Dim theElement as EA.Element
Set theElement = Repository.GetTreeSelectedObject()
if not theElement is nothing then
if Repository.GetTreeSelectedItemType() = otPackage then
if UCASE(theElement.Element.Stereotype) = "APPLICATIONSCHEMA" then
dim message, indent
' dim box
' box = Msgbox ("Script listJsonExample" & vbCrLf & vbCrLf & "Scriptversion 2022-10-17" & vbCrLf & "Listing to JSON example for package : [" & theElement.Name & "].",1)
' select case box
' case vbOK
dim xsdfile
'tømmer System Output
Repository.ClearOutput "Script"
Repository.CreateOutputTab "Error"
Repository.ClearOutput "Error"
kortnavn = getPackageTaggedValue(theElement,"SOSI_kortnavn")
if kortnavn = "" then
kortnavn = theElement.Name
end if
namespace = getPackageTaggedValue(theElement,"targetNamespace")
if namespace = "" then
namespace = "http://schemas.someserver.org/" & kortnavn
end if
xsdfile = getPackageTaggedValue(theElement,"xsdDocument")
if xsdfile = "" then
xsdfile = kortnavn & ".xsd"
end if
SessionOutput("{")
SessionOutput(" ""type"": ""FeatureCollection"",")
SessionOutput(" ""time"": { ""timestamp"": """ & nao() & """ },")
SessionOutput(" ""describedby"": { ""href"": """ & namespace & "/" & kortnavn & """ },")
SessionOutput(" ""features"": [")
ftnum = 0
ftcount = 0
call getFeatureTypeCount(theElement)
call initCoord()
call listFeatureTypes(theElement)
SessionOutput(" ]")
SessionOutput("}")
' case VBcancel
' end select
else 'No «ApplicationSchema» Package or a «FeatureType» Class selected in the tree
MsgBox( "This script requires a «ApplicationSchema» Package or a «FeatureType» Class to be selected in the Project Browser." & vbCrLf & _
"Please select a «ApplicationSchema» Package or a «FeatureType» Class in the Project Browser and try again." )
end if
Else
if Repository.GetTreeSelectedItemType() = otElement then
if theElement.Type="Class" and UCASE(theElement.Stereotype) = "FEATURETYPE" then
if debug then Repository.WriteOutput "Script", "Debug: theElement.Name [«" & theElement.Stereotype & "» " & theElement.Name & "] currentElement.Type [" & theElement.Type & "] currentElement.Abstract [" & theElement.Abstract & "].",0
Repository.ClearOutput "Script"
Repository.CreateOutputTab "Error"
Repository.ClearOutput "Error"
namespace = "http://schemas.someserver.org/someproduct"
kortnavn = "shortNamespace"
indent = " "
ftname = theElement.Name
indent = " "
SessionOutput("{")
SessionOutput(" ""type"": ""Feature"",")
SessionOutput(" ""time"": { ""timestamp"": """ & nao() & """ },")
SessionOutput(" ""describedby"": { ""href"": """ & namespace & "/" & kortnavn & """ },")
call initCoord()
SessionOutput(" ""id"": """ & "http://data.geonorge.no/sosi/" & Kortnavn & "/" & ftname & ".1"",")
SessionOutput(" ""featureType"": """ & ftname & """,")
SessionOutput(" ""time"": { ""timestamp"": """ & nao() & """ },")
SessionOutput(" ""coordRefSys"": ""http://www.opengis.net/def/crs/EPSG/0/5972"",")
gnum = 0
SessionOutput(" ""place"": {")
call listJsonFgGeometry(ftname,theElement,indent)
SessionOutput(" },")
gnum = 0
SessionOutput(" ""geometry"": {")
call listGeoJsonGeometry(ftname,theElement,indent)
SessionOutput(" },")
SessionOutput(" ""links"": [")
call listLinks(indent)
SessionOutput(" ],")
SessionOutput(" ""properties"": {")
call listDatatypes(ftname,theElement,indent)
SessionOutput(" }")
SessionOutput("}")
' SessionOutput(" </" & utf8(theElement.Name) & ">")
' SessionOutput(" </wfs:member>")
else
'Other than «ApplicationSchema» Package or a «FeatureType» Class selected in the tree
MsgBox( "This script requires a Package or a «FeatureType» Class to be selected in the Project Browser." & vbCrLf & _
"Please select a Package or a «FeatureType» Class in the Project Browser and try again." )
end if
else
'Other than «ApplicationSchema» Package or a «FeatureType» Class selected in the tree
MsgBox( "Element type selected: " & theElement.Type & vbCrLf & _
"This script requires a Package or a «FeatureType» Class to be selected in the Project Browser." & vbCrLf & _
"Please select a Package or a «FeatureType» Class in the Project Browser and try again." )
end If
end if
'Repository.WriteOutput "Script", Now & " Finished, check the Error and Types tabs", 0
end if
end sub
sub listFeatureTypes(pkg)
dim presentasjonsnavn
dim elements as EA.Collection
dim super as EA.Element
dim datatype as EA.Element
dim conn as EA.Collection
set elements = pkg.Elements
dim i, sosinavn, sositype, sosilengde, sosimin, sosimax, koder, prikkniv, sosierlik, superlist
dim indent, ftname
if debug then Repository.WriteOutput "Script", "<!-- Debug: pkg.Name [" & pkg.Name & "]. -->",0
dim currentElement as EA.Element
for i = 0 to elements.Count - 1
set currentElement = elements.GetAt( i )
if debug then Repository.WriteOutput "Script", "<!-- Debug: currentElement.Name [«" & currentElement.Stereotype & "» " & currentElement.Name & "] currentElement.Type [" & currentElement.Type & "] currentElement.Abstract [" & currentElement.Abstract & "]. -->",0
if currentElement.Type = "Class" and LCase(currentElement.Stereotype) = "featuretype" and currentElement.Abstract = 0 then
ftnum = ftnum + 1
SessionOutput(" {")
SessionOutput(" ""type"": ""Feature"",")
ftname = currentElement.Name
superlist = ""
indent = " "
SessionOutput(" ""id"": """ & "http://data.geonorge.no/sosi/" & Kortnavn & "/" & ftname & ".1"",")
SessionOutput(" ""featureType"": """ & ftname & """,")
SessionOutput(" ""time"": { ""timestamp"": """ & nao() & """ },")
SessionOutput(" ""coordRefSys"": ""http://www.opengis.net/def/crs/EPSG/0/5972"",")
gnum = 0
SessionOutput(" ""place"": {")
call listJsonFgGeometry(ftname,currentElement,indent)
SessionOutput(" },")
gnum = 0
SessionOutput(" ""geometry"": {")
call listGeoJsonGeometry(ftname,currentElement,indent)
SessionOutput(" },")
SessionOutput(" ""links"": [")
call listLinks(indent)
SessionOutput(" ],")
SessionOutput(" ""properties"": {")
call listDatatypes(ftname,currentElement,indent)
SessionOutput(" }")
if ftnum >= ftcount then
SessionOutput(" }")
else
SessionOutput(" },")
end if
' SessionOutput(" </" & utf8(currentElement.Name) & ">")
' SessionOutput(" </wfs:member>")
eastoffset = eastoffset + eastdelta
end if
next
dim subP as EA.Package
for each subP in pkg.packages
call listFeatureTypes(subP)
next
end sub
'
' List association roles as links, attributes and subattributes except attributes with geometry type
'
sub listDatatypes(ftname,element,indent)
dim presentasjonsnavn
dim elements as EA.Collection
dim element0 as EA.Element
dim super as EA.Element
dim datatype as EA.Element
dim subbtype as EA.Element
dim conn as EA.Collection
dim connEnd as EA.ConnectorEnd
dim i, umlnavn, sosinavn, sositype, sosilengde, sosimin, sosimax, sosierlik, koder, prikkniv1, roleEndElementID, sosidef, selfref, subID
dim indent0, indent1, superlist, ccount, acount, cnum, anum, cont
dim code1, code2, codeListUrl
' eastoffset = eastoffset + eastdelta
if debug then Repository.WriteOutput "Script", "<!-- Debug: --------listDatatypes element.Name [" & element.Name & "] element.ElementID [" & element.ElementID & "]. -->",0
'ZZZ if element.Type = "Datatype" or (element.Type = "Class" and LCase(element.Stereotype) = "datatype" or LCase(element.Stereotype) = "union" or LCase(element.Stereotype) = "featuretype") then
if element.Type = "Datatype" or (element.Type = "Class" and LCase(element.Stereotype) = "" or LCase(element.Stereotype) = "datatype" or LCase(element.Stereotype) = "union" or LCase(element.Stereotype) = "featuretype") then
' sjekk om siste klasse i arverekken er tom
acount = element.Attributes.Count
ccount = element.Connectors.Count
for each conn in element.Connectors
if debug then Repository.WriteOutput "Script", "<!-- Debug: conn.Type [" & conn.Type & "] conn.ClientID [" & conn.ClientID & "] conn.SupplierID [" & conn.SupplierID & "]. -->",0
if conn.Type = "Generalization" or conn.Type = "Realisation" or conn.Type = "NoteLink" then
ccount = ccount - 1
end if
if conn.Type = "Generalization" then
if element.ElementID = conn.ClientID then
if debug then Repository.WriteOutput "Script", "<!-- Debug: supertype [" & Repository.GetElementByID(conn.SupplierID).Name & "]. -->",0
' superlist = getSupertypes(ftname, conn.SupplierID, indent)
set super = Repository.GetElementByID(conn.SupplierID)
call listDatatypes(ftname,super,indent)
if acount > 0 or ccount > 0 then
SessionOutput(indent & "," )
' TBD empty supertypes ?
end if
end if
end if
next
dim attr as EA.Attribute
anum = 0
cont = ","
for each attr in element.Attributes
anum = anum + 1
' if anum >= acount or LCase(element.Stereotype) = "union" then
if anum >= acount and ccount = 0 then
cont = ""
'TBD if isLastNonGeometryAttribute(element,attr.Name...)
end if
if debug then Repository.WriteOutput "Script", "<!-- Debug: anum,acount,ccont,cont [" & anum & " " & acount & " " & ccount & " " & cont & "] -->",0
if getSosiGeometritype(attr) = "" then
' normal attribute, not geometry
if debug then Repository.WriteOutput "Script", "<!-- Debug: attr.Name [" & attr.Name & "] not geometry. -->",0
if attr.ClassifierID <> 0 and getBasicSOSIType(attr.Type) = "*" then
set datatype = Repository.GetElementByID(attr.ClassifierID)
'see if the datatype has a supertype, if so then write all its elements first - TBD
if datatype.Name = element.Name and datatype.ParentID = element.ParentID then
'if datatype.ClassifierID = element.ClassifierID then
Repository.WriteOutput "Script", "Error - circular self reference: datatype.Name [" & datatype.Name & "] from attribute name [" & element.Name & "." & attr.Name & "].",0
exit sub
else
if datatype.Type = "Enumeration" or LCase(datatype.Stereotype) = "codelist" or LCase(datatype.Stereotype) = "enumeration" then
'list first code in the list
if getTaggedValue(attr,"inlineOrByReference") = "byReference" then
'variant gml:ReferenceType
'if debug then
if attr.UpperBound <> "1" then
' SessionOutput(indent & "<" & attr.Name & ">" & listCodeType(datatype) & "</" & attr.Name & ">")
' SessionOutput(indent & "<" & attr.Name & " xlink:href=""" & namespace & "/" & attr.Type & "/" & listCodeType(datatype) & """/>")
SessionOutput(indent & """" & attr.Name & """: """ & namespace & "/" & attr.Type & "/" & listCodeType(datatype) & """")
end if
SessionOutput(indent & "<" & attr.Name & " xlink:href=""" & namespace & "/" & attr.Type & "/" & listCodeType(datatype) & """/>")
'SessionOutput(indent & "<" & attr.Name & " xlink:href=""" & listReferenceType(attr.Type) & """/>")
else
if getTaggedValue(datatype,"asDictionary") = "true" then
' if getTaggedValue(datatype,"codeList") <> "" and getTaggedValue(datatype,"codeList") = getTaggedValue(attr,"defaultCodeSpace") then
if getTaggedValue(datatype,"codeList") <> "" then
'TBD read tag defaultCodeSpace on the attribute instead
codeListUrl = getTaggedValue(datatype,"codeList")
if getTaggedValue(attr,"defaultCodeSpace") <> "" then
if getTaggedValue(attr,"defaultCodeSpace") <> codeListUrl then
Repository.WriteOutput "Script", "<!-- Info: attr.Name [" & attr.Name & "] has a tagged value defaultCodeSpace [" & getTaggedValue(attr,"defaultCodeSpace") & "] that is different from the codelist class tagged value codeList [" & codeListUrl & "]. -->",0
end if
codeListUrl = getTaggedValue(attr,"defaultCodeSpace")
end if
if debug then Repository.WriteOutput "Script", "<!-- Debug: codeListUrl [" & codeListUrl & "]. -->",0
call get2firstCodes(codeListUrl,code1,code2)
if code1 = "" then
code1 = "someExternalCodelistCode"
end if
if code2 = "" then
code2 = "someOtherExternalCodelistCode"
end if
else
code1 = "someExternalCodelistCode"
code2 = "someOtherExternalCodelistCode"
end if
if attr.UpperBound <> "1" then
SessionOutput(indent & """" & attr.Name & """: """ & code1 & """,")
SessionOutput(indent & """" & attr.Name & """: """ & code2 & """" & cont)
else
SessionOutput(indent & """" & attr.Name & """: """ & code1 & """" & cont)
end if
else
'TBD asDictionary= false, variant gml:CodeType
if code1 = "" then
code1 = "someInternalCodelistCode"
end if
if code2 = "" then
code2 = "someOtherInternalCodelistCode"
end if
if attr.UpperBound <> "1" then
SessionOutput(indent & """" & attr.Name & """: """ & code1 & """,")
SessionOutput(indent & """" & attr.Name & """: """ & code2 & """")
else
SessionOutput(indent & """" & attr.Name & """: """ & code1 & """")
end if
end if
end if
'listCodeType(attr)
else
if attr.UpperBound <> "1" then
SessionOutput(indent & """" & utf8(attr.Name) & """: {")
indent0 = indent & " "
call listDatatypes(ftname, datatype,indent0)
SessionOutput(indent & "},")
end if
SessionOutput(indent & """" & utf8(attr.Name) & """: {")
indent0 = indent & " "
call listDatatypes(ftname, datatype,indent0)
SessionOutput(indent & "}" & cont)
end if
end if
else
'base type
if attr.UpperBound <> "1" then
SessionOutput(indent & """" & utf8(attr.Name) & """: """ & listBaseType(ftname, attr.Name,attr.Type) & """,")
end if
SessionOutput(indent & """" & utf8(attr.Name) & """: """ & listBaseType(ftname, attr.Name,attr.Type) & """" & cont)
end if
else
'geometry type
end if
'TBD if Union then jump out of the loop after first(!) variant, this does not support well Unions having several different datatypes
if LCase(element.Stereotype) = "union" then
Exit For
end if
next
cnum = 0
cont = ","
for each conn in element.Connectors
if conn.Type = "Generalization" or conn.Type = "Realisation" or conn.Type = "NoteLink" then
else
cnum = cnum + 1
if cnum >= ccount then
cont = ""
end if
if debug then Repository.WriteOutput "Script", "<!-- Debug: cnum,acount,ccont,cont [" & cnum & " " & acount & " " & ccount & " " & cont & "] -->",0
if debug then Repository.WriteOutput "Script", "<!-- Debug: Supplier Role.Name [" & conn.SupplierEnd.Role & "] datatypens navn [" & Repository.GetElementByID(conn.SupplierID).Name & "], conn.SupplierID [" & conn.SupplierID & "]. -->",0
if debug then Repository.WriteOutput "Script", "<!-- Debug: Client Role.Name [" & conn.ClientEnd.Role & "] datatypens navn [" & Repository.GetElementByID(conn.ClientID).Name & "], conn.ClientID [" & conn.ClientID & "]. -->",0
if conn.ClientID = element.ElementID then
' if getConnectorEndTaggedValue(conn.SupplierEnd,"xsdEncodingRule") <> "notEncoded" then
set datatype = Repository.GetElementByID(conn.SupplierID)
umlnavn = conn.SupplierEnd.Role
if conn.ClientEnd.Aggregation = 2 and conn.SupplierID <> conn.ClientID then
' if conn.ClientEnd.Aggregation = 2 and conn.SupplierID <> conn.ClientID or getConnectorEndTaggedValue(conn.SupplierEnd,"inlineOrByReference") = "inline" then
'composition+mandatory->nest as datatype inline?
'inLineOrByReference?
call listComposition(ftname,umlnavn,datatype,indent,conn.SupplierEnd.Cardinality,cont)
else
call listAssociation(ftname,umlnavn,datatype,indent,conn.SupplierEnd.Cardinality,conn.SupplierEnd.Navigable,element.Name,cont)
end if
' end if
else
' if getConnectorEndTaggedValue(conn.ClientEnd,"xsdEncodingRule") <> "notEncoded" then
set datatype = Repository.GetElementByID(conn.ClientID)
umlnavn = conn.ClientEnd.Role
if conn.SupplierEnd.Aggregation = 2 then
'composition+mandatory->nest as datatype inline?
'inLineOrByReference?
call listComposition(ftname,umlnavn,datatype,indent,conn.ClientEnd.Cardinality,cont)
else
call listAssociation(ftname,umlnavn,datatype,indent,conn.ClientEnd.Cardinality,conn.ClientEnd.Navigable,element.Name,cont)
end if
' end if
end if
end if
next
end if
end sub
sub listLinks(indent)
SessionOutput(indent & "{")
SessionOutput(indent & " ""href"": ""https://example.org/data/v1/collections/buildings/items/DENW19AL0000giv5BL?f=jsonfg"",")
SessionOutput(indent & " ""rel"": ""self"",")
SessionOutput(indent & " ""type"": ""application/vnd.ogc.fg+json"",")
SessionOutput(indent & " ""title"": ""This document""")
SessionOutput(indent & "}")
end sub
sub listComposition(ftname,umlnavn,datatype,indent,cardinality,cont)
dim indent0, indent1, subID
dim subbtype as EA.Element
SessionOutput(indent & """" & utf8(umlnavn) & """ {")
indent0 = indent & " "
' ' SessionOutput(indent0 & "<" & utf8(datatype.Name) & ">")
indent1 = indent0 & " "
if datatype.Abstract = 1 then
'must move down to make an example of a instanciable subtype of the class pointed to TODO, NB needed on mandatory attributes!
call getFirstConcreteSubtypeName(datatype,subID)
set subbtype = Repository.GetElementByID(subID)
' SessionOutput(indent0 & """" & utf8(subbtype.Name) & """: ")
call listDatatypes(ftname, subbtype,indent1)
' SessionOutput(indent0 & "}")
else
' SessionOutput(indent0 & "<" & utf8(datatype.Name) & ">")
call listDatatypes(ftname, datatype,indent1)
' SessionOutput(indent0 & "}")
end if
SessionOutput(indent & "}")
if cardinality <> "0..1" and cardinality <> "1..1" and cardinality <> "1" then
SessionOutput(indent & "<" & utf8(umlnavn) & ">")
indent0 = indent & " "
SessionOutput(indent0 & "<" & utf8(datatype.Name) & ">")
indent1 = indent0 & " "
if datatype.Abstract = 1 then
'must move down to make an example of a instanciable subtype of the class pointed to TODO, NB needed on mandatory attributes!
call getFirstConcreteSubtypeName(datatype,subID)
set subbtype = Repository.GetElementByID(subID)
SessionOutput(indent0 & "<" & utf8(subbtype.Name) & ">")
call listDatatypes(ftname, subbtype,indent1)
SessionOutput(indent0 & "</" & utf8(subbtype.Name) & ">")
else
SessionOutput(indent0 & "<" & utf8(datatype.Name) & ">")
call listDatatypes(ftname, datatype,indent1)
SessionOutput(indent0 & "</" & utf8(datatype.Name) & ">")
end if
SessionOutput(indent0 & "</" & utf8(datatype.Name) & ">")
SessionOutput(indent & "</" & utf8(umlnavn) & ">")
end if
end sub
sub listAssociation(ftname,umlnavn,datatype,indent,cardinality,navigable,elementname,cont)
'sub listComposition(ftname,umlnavn,datatype,indent,cardinality)
dim indent0, indent1, subID, selfref
dim subbtype as EA.Element
if navigable = "Navigable" then
'self assoc? if so make xlinks to other (imaginary) instances of the same class
selfref = 1
if datatype.Name = elementname then
selfref = 2
end if
if cardinality <> "0..1" and cardinality <> "1..1" and cardinality <> "1" then
if datatype.Abstract = 1 then
'must move down to make an example of a instanciable subtype of the class pointed to TODO, NB needed on mandatory attributes!
SessionOutput(indent & """" & utf8(umlnavn) & """: ""#" & utf8(getFirstConcreteSubtypeName(datatype,subID)) & "." & selfref & """,")
else
SessionOutput(indent & """" & utf8(umlnavn) & """: ""#" & utf8(datatype.Name) & "." & selfref & """,")
end if
if datatype.Name = elementname then
selfref = 3
end if
end if
if datatype.Abstract = 1 then
SessionOutput(indent & """" & utf8(umlnavn) & """: ""#" & utf8(getFirstConcreteSubtypeName(datatype,subID)) & "." & selfref & """" & cont)
else
SessionOutput(indent & """" & utf8(umlnavn) & """: ""#" & utf8(datatype.Name) & "." & selfref & """" & cont)
end if
if debug then Repository.WriteOutput "Script", "<!-- Debug: .Cardinality [" & cardinality & "]. -->",0
end if
end sub
function listBaseType(ftname,umlname, umltype)
listBaseType = "FIX"
if umltype = "CharacterString" then
if umlname = "navnerom" or umlname = "namespace" then
listBaseType = "http://data.geonorge.no/sosi/" & Kortnavn
else
if umlname = "lokalId" or umlname = "localId" then
listBaseType = ftname & ".1"
else
if umlname = "versjonId" or umlname = "versionId" then
listBaseType = "version_1_of_this_object"
else
listBaseType = "Some meaningful text"
end if
end if
end if
end if
if umltype = "Boolean" then
listBaseType = "true"
end if
if umltype = "Date" then
listBaseType = "2022-11-04"
end if
if umltype = "DateTime" then
listBaseType = "2022-11-04T21:08:00Z"
end if
if umltype = "Integer" then
listBaseType = "42"
end if
if umltype = "Real" then
listBaseType = "21.22"
end if
if UCase(umltype) = "URI" then
listBaseType = "http://"
end if
end function
function listCodeType(element)
listCodeType = "*"
dim attr as EA.Attribute
if element.Attributes.Count = 0 then
listCodeType = "someExternalRegistryCode"
else
for each attr in element.Attributes
listCodeType = attr.Name
if attr.Default <> "" then listCodeType = attr.Default
exit for
next
end if
end function
sub get2firstCodes(codeListUrl,code1,code2)
Dim codelist
codelist = ""
code1 = ""
code2 = ""
' testing http get
if codeListUrl <> "" then
' Session.Output("<!-- DEBUG codeListUrl: " & codeListUrl & " -->")
Dim httpObject
Dim parseText, line, linepart, part, kodenavn, kodedef, ualias, kodelistenavn
Set httpObject = CreateObject("MSXML2.XMLHTTP")
' httpObject.open "GET", "http://skjema.geonorge.no/SOSI/basistype/Integer.html", false
httpObject.open "GET", codeListUrl & ".gml", false
httpObject.send
if httpObject.status = 200 then
' Session.Output("DEBUG gml:Dictionary: "&httpObject.responseText&"")
'' parseText = split(split(split(ResponseXML,SearchTag)(1),"</")(0),">")(1)
parseText = split(httpObject.responseText,"<",-1,1)
kodelistenavn = ""
for each line in parseText
' Session.Output("DEBUG line: "&line&"")
if mid(line,1,25) = "gml:identifier codeSpace=" then
linepart = split(line,">",-1,1)
for each part in linepart
ualias = part
next
end if
if mid(line,1,16) = "gml:description>" then
linepart = split(line,">",-1,1)
for each part in linepart
kodedef = part
next
end if
if mid(line,1,9) = "gml:name>" then
linepart = split(line,">",-1,1)
for each part in linepart
kodenavn = part
next
end if
if codelist <> "" and code1 <> "" and code2 = "" and ualias <> "" then code2 = ualias
' if codelist <> "" and code1 <> "" and code2 = "" then code2 = kodenavn
if codelist <> "" and code1 = "" and ualias <> "" then code1 = ualias
' if codelist <> "" and code1 = "" then code1 = kodenavn
if codelist = "" and ualias <> "" then codelist = ualias
ualias = ""
'if code2 <> "" then exit for
next
' Session.Output("|===")
else
' Session.Output("Kodeliste kunne ikke hentes fra register: "&codeListUrl&"")
' Session.Output(" ")
if debug then Session.Output("<!-- DEBUG feil ved lesing av kodeliste: ["&codeListUrl&"] status:["&httpObject.status&"]-->")
end if
end if
end sub
sub listGeometryType(elementName, geomtype, indent)
if geomtype = "Punkt" or geomtype = "GM_Point" then
pnteller = pnteller + 1
if epsg = 5972 then
' SessionOutput(indent & "<gml:Point gml:id=""" & elementName & ".pn." & pnteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
SessionOutput(indent & "<gml:Point srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
' SessionOutput(indent & " <gml:pos>568497.68 6662024.15 90.67</gml:pos>")
SessionOutput(indent & " <gml:pos>"&r1+eastoffset&" "&r2&" "&r3&"</gml:pos>")
else
SessionOutput(indent & "<gml:Point gml:id=""" & elementName & ".pn." & pnteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/4258"">")
SessionOutput(indent & " <gml:pos>60.02 10.1</gml:pos>")
end if
SessionOutput(indent & "</gml:Point>")
end if
if geomtype = "Sverm" or geomtype = "GM_MultiPoint" then
'getSosiGeometritype = "SVERM"
end if
if geomtype = "Kurve" or geomtype = "GM_Curve" then
cuteller = cuteller + 1
if epsg = 5972 then
' SessionOutput(indent & "<gml:LineString gml:id=""" & elementName & ".cu." & cuteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
SessionOutput(indent & "<gml:LineString srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
' SessionOutput(indent & " <gml:posList>568597.68 6662024.15 90.67 568497.68 6662024.15 90.67</gml:posList>")
SessionOutput(indent & " <gml:posList>"&q1(1)+eastoffset&" "&q2(1)&" "&q3(1)&" "&q1(2)+eastoffset&" "&q2(2)&" "&q3(2)&" "&q1(3)+eastoffset&" "&q2(3)&" "&q3(3)&" "&q1(4)+eastoffset&" "&q2(4)&" "&q3(4)&"</gml:posList>")
else
SessionOutput(indent & "<gml:LineString gml:id=""" & elementName & ".cu." & cuteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/4258"">")
SessionOutput(indent & " <gml:posList>60.02 10.1 60.02 10.3 60.03 10.2</gml:posList>")
end if
SessionOutput(indent & "</gml:LineString>")
end if
if geomtype = "GM_CompositeCurve" then
cuteller = cuteller + 1
' SessionOutput(indent & "<gml:Curve gml:id = """ & elementName & ".cc." & cuteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
SessionOutput(indent & "<gml:CompositeCurve>")
SessionOutput(indent & " <gml:curveMember>")
if epsg = 5972 then
SessionOutput(indent & " <gml:LineString gml:id=""" & elementName & ".cu." & cuteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
' SessionOutput(indent & " <gml:posList>568597.68 6662024.15 90.67 568497.68 6662024.15 90.67</gml:posList>")
SessionOutput(indent & " <gml:posList>"&q1(1)+eastoffset&" "&q2(1)&" "&q3(1)&" "&q1(2)+eastoffset&" "&q2(2)&" "&q3(2)&" "&q1(3)+eastoffset&" "&q2(3)&" "&q3(3)&" "&q1(4)+eastoffset&" "&q2(4)&" "&q3(4)&"</gml:posList>")
else
SessionOutput(indent & " <gml:LineString gml:id=""" & elementName & ".cu." & cuteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/4258"">")
SessionOutput(indent & " <gml:posList>60.02 10.1 60.02 10.3 60.03 10.2</gml:posList>")
end if
SessionOutput(indent & " </gml:LineString>")
SessionOutput(indent & " </gml:curveMember>")
SessionOutput(indent & "</gml:CompositeCurve>")
'eller <gml:CompositeCurve>
' <gml:curveMember>
' <gml:Curve gml:id = "PblTiltak.cc.1" srsName="http://www.opengis.net/def/crs/epsg/0/5972" srsDimension="3">
' <gml:segments>
' <gml:LineStringSegment>
' <gml:posList>568597.68 6662024.15 90.67 568497.68 6662024.15 90.67</gml:posList>
' </gml:LineStringSegment>
' </gml:segments>
' </gml:Curve>
' </gml:curveMember>
' </gml:CompositeCurve>
end if
if geomtype = "Flate" or geomtype = "GM_Surface" then
' SessionOutput(indent & "<gml:Surface gml:id = """ & elementName & ".su.1"" srsName=""http://www.opengis.net/def/crs/epsg/0/4258"">")
suteller = suteller + 1
if epsg = 5972 then
' SessionOutput(indent & "<gml:Polygon gml:id=""" & elementName & ".su." & suteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
' call generateSurfaceExample(elementName, indent, height)
call generatePolygonExample(elementName, indent, height)
' SessionOutput(indent & "<gml:Polygon srsName=""http://www.opengis.net/def/crs/epsg/0/5972"" srsDimension=""3"">")
else
SessionOutput(indent & "<gml:Polygon gml:id=""" & elementName & ".su." & suteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/4258"">")
SessionOutput(indent & " <gml:exterior>")
SessionOutput(indent & " <gml:LinearRing>")
SessionOutput(indent & " <gml:posList>60.02 10.1 60.02 10.3 60.03 10.2 60.02 10.1</gml:posList>")
SessionOutput(indent & " </gml:LinearRing>")
SessionOutput(indent & " </gml:exterior>")
SessionOutput(indent & "</gml:Polygon>")
end if
' if epsg = 5972 then
' SessionOutput(indent & " <gml:posList>568444.03 6661981.48 89.20 568506.41 6662009.49 91.20 568525.84 6661998.97 90.80 568529.64 6662001.85 91.00 568535.02 6662054.94 91.50 568476.33 6662067.85 90.50 568466.50 6662054.49 90.50 568444.03 6661981.48 89.20</gml:posList>")
' end if
' SessionOutput(indent & "</gml:Surface>")
'
'eller <gml:CompositeSurface srsName="http://www.opengis.net/def/crs/epsg/0/4258" gml:id="Havneavsnitt.CS111111">
' <gml:surfaceMember>
' <gml:Surface srsName="http://www.opengis.net/def/crs/epsg/0/4258" gml:id="Havneavsnitt.S111111">
' <gml:patches>
' <gml:PolygonPatch>
' <gml:exterior>
' <gml:Ring>
' <gml:curveMember xlink:href="Havneavsnittgrense.C444444"/>
' </gml:Ring>
' </gml:exterior>
' </gml:PolygonPatch>
' </gml:patches>
' </gml:Surface>
' </gml: surfaceMember >
' </gml:CompositeSurface>
end if
if geomtype = "GM_CompositeSurface" then
call generateCompositeSurfaceExample(elementName, indent)
'eller delt mellom flere objekter
' <gml:CompositeSurface gml:id = "PblTiltak.cs.0" srsName="http://www.opengis.net/def/crs/epsg/0/5972" srsDimension="3">
' <gml:surfaceMember>
' <gml:Surface gml:id = "PblTiltak.su.0" srsName="http://www.opengis.net/def/crs/epsg/0/5972" srsDimension="3">
' <gml:patches>
' <gml:PolygonPatch>
' <gml:exterior>
' <gml:Ring>
' <gml:curveMember xlink:href="#Tiltaksgrense.cc.2"/>
' </gml:Ring>
' </gml:exterior>
' </gml:PolygonPatch>
' </gml:patches>
' </gml:Surface>
' </gml:surfaceMember>
' </gml:CompositeSurface>
end if
if geomtype = "GM_Solid" or geomtype = "GM_CompositeSolid" then
'getSosiGeometritype = "NO GO"
dim height
height = 6.0
call generateSolidExample(elementName, indent, height)
''' call generateSOSISolidExample(elementName, indent, height)
end if
if geomtype = "GM_Object" or geomtype = "GM_Primitive" then
obteller = obteller + 1
SessionOutput(indent & "<gml:Point gml:id=""" & elementName & ".ob." & obteller & """ srsName=""http://www.opengis.net/def/crs/epsg/0/4258"">")
SessionOutput(indent & " <gml:pos>60.02 10.1</gml:pos>")
SessionOutput(indent & "</gml:Point>")
end if
end sub
function getSosiGeometritype(element)
getSosiGeometritype = ""
if element.Type = "Punkt" or element.Type = "GM_Point" then
getSosiGeometritype = "PUNKT"
end if
if element.Type = "Sverm" or element.Type = "GM_MultiPoint" then
getSosiGeometritype = "SVERM"
end if
if element.Type = "Kurve" or element.Type = "GM_Curve" or element.Type = "GM_CompositeCurve" then
getSosiGeometritype = "KURVE,BUEP,KLOTOIDE"
end if
if element.Type = "Flate" or element.Type = "GM_Surface" or element.Type = "GM_CompositeSurface" then
getSosiGeometritype = "FLATE"
end if
if element.Type = "GM_Solid" or element.Type = "GM_CompositeSolid" then
getSosiGeometritype = "NO GO"
end if
if element.Type = "GM_Object" or element.Type = "GM_Primitive" then
getSosiGeometritype = "PUNKT,SVERM,KURVE,BUEP,KLOTOIDE,FLATE"
end if
end function
function getTaggedValue(element,taggedValueName)
dim i, existingTaggedValue
getTaggedValue = ""
for i = 0 to element.TaggedValues.Count - 1
set existingTaggedValue = element.TaggedValues.GetAt(i)
if existingTaggedValue.Name = taggedValueName then
getTaggedValue = existingTaggedValue.Value
end if
next
end function
function getPackageTaggedValue(package,taggedValueName)
dim i, existingTaggedValue
getPackageTaggedValue = ""
for i = 0 to package.element.TaggedValues.Count - 1
set existingTaggedValue = package.element.TaggedValues.GetAt(i)
if existingTaggedValue.Name = taggedValueName then
getPackageTaggedValue = existingTaggedValue.Value
end if
next
end function
function getConnectorEndTaggedValue(connectorEnd,taggedValueName)
getConnectorEndTaggedValue = ""
if not connectorEnd is nothing and Len(taggedValueName) > 0 then
dim existingTaggedValue as EA.RoleTag
dim i
for i = 0 to connectorEnd.TaggedValues.Count - 1
set existingTaggedValue = connectorEnd.TaggedValues.GetAt(i)
if existingTaggedValue.Tag = taggedValueName then
getConnectorEndTaggedValue = existingTaggedValue.Value
end if
next
end if
end function
function getBasicSOSIType(umltype)
getBasicSOSIType = "*"
if umltype = "CharacterString" then
getBasicSOSIType = "T"
end if
if umltype = "Boolean" then
getBasicSOSIType = "BOOLSK"
end if
if umltype = "Date" then
getBasicSOSIType = "DATO"
end if
if umltype = "DateTime" then
getBasicSOSIType = "DATOTID"
end if
if umltype = "Integer" then
getBasicSOSIType = "H"
end if
if umltype = "Real" then
getBasicSOSIType = "D"
end if
end function
function utf8(str)
' make string utf-8
Dim txt, res, tegn, utegn, vtegn, wtegn, xtegn, i
utf8 = str
exit function
res = ""
txt = Trim(str)
' loop gjennom alle tegn
For i = 1 To Len(txt)
tegn = Mid(txt,i,1)
'if (c < 0x80) { *out++= c; bits= -6; }
'else if (c < 0x800) { *out++= ((c >> 6) & 0x1F) | 0xC0; bits= 0; }
'else if (c < 0x10000) { *out++= ((c >> 12) & 0x0F) | 0xE0; bits= 6; }
'else { *out++= ((c >> 18) & 0x07) | 0xF0; bits= 12; }
if AscW(tegn) < 128 then
res = res + tegn
else if AscW(tegn) < 2048 then
'u = AscW(tegn)
'Repository.WriteOutput "Script", "tegn: " & AscW(tegn) & " " & Chr(AscW(tegn) / 64) & " " & int(u / 64),0
' c 229=E5/1110 0101
' c 192=C0/1100 0000 64=40/0100 0000
utegn = Chr((int(AscW(tegn) / 64) or 192) )
res = res + utegn
' c 63=3F/0011 1111
vtegn = Chr((AscW(tegn) and 63) or 128)
res = res + vtegn
' C3A5=å 195/1100 0011 165/1010 0101
'Repository.WriteOutput "Script", "utf8: " & tegn & " -> " & utegn & " + " & vtegn,0
'Repository.WriteOutput "Script", "int : " & AscW(tegn) & " -> " & Asc(utegn) & " + " & Asc(vtegn),0
else if AscW(tegn) < 65536 then
utegn = Chr((int(AscW(tegn) / 4096) or 224) )
res = res + utegn
vtegn = Chr((int(AscW(tegn) / 64) or 128) )
res = res + vtegn
wtegn = Chr((AscW(tegn) and 63) or 128)
res = res + wtegn
'putchar (0xE0 | c>>12); E0=224, 2^12=4096
'putchar (0x80 | c>>6 & 0x3F); 80=128, 2^6=64
'putchar (0x80 | c & 0x3F); 80=128
else if AscW(tegn) < 2097152 then '/* 2^21 */
utegn = Chr((int(AscW(tegn) / 262144) or 240) )
res = res + utegn
vtegn = Chr((int(AscW(tegn) / 4096) or 128) )
res = res + vtegn
wtegn = Chr((int(AscW(tegn) / 64) or 128) )
res = res + wtegn
xtegn = Chr((AscW(tegn) and 63) or 128)
res = res + xtegn
'putchar (0xF0 | c>>18); F0=240, 2^18=262144
'putchar (0x80 | c>>12 & 0x3F); 80=128, 2^12=4096
'putchar (0x80 | c>>6 & 0x3F); 80=128, 2^6=64
'putchar (0x80 | c & 0x3F); 80=128, 3F=63
end if
end if
end if
end if
Next
' return res
utf8 = res
End function
sub listJsonFgGeometry(ftname,element,indent)
dim presentasjonsnavn
dim elements as EA.Collection
dim element0 as EA.Element
dim super as EA.Element
dim datatype as EA.Element
dim subbtype as EA.Element
dim conn as EA.Collection
dim connEnd as EA.ConnectorEnd
dim i, umlnavn, sosinavn, sositype, sosilengde, sosimin, sosimax, sosierlik, koder, prikkniv1, roleEndElementID, sosidef, selfref, subID
dim indent0, indent1, superlist
dim geomtype
dim height
height = 6.0
' eastoffset = eastoffset + eastdelta
if debug then Repository.WriteOutput "Script", "<!-- Debug: --------listDatatypes element.Name [" & element.Name & "] element.ElementID [" & element.ElementID & "]. -->",0
'ZZZ if element.Type = "Datatype" or (element.Type = "Class" and LCase(element.Stereotype) = "datatype" or LCase(element.Stereotype) = "union" or LCase(element.Stereotype) = "featuretype") then
if element.Type = "Datatype" or (element.Type = "Class" and LCase(element.Stereotype) = "" or LCase(element.Stereotype) = "datatype" or LCase(element.Stereotype) = "union" or LCase(element.Stereotype) = "featuretype") then
for each conn in element.Connectors
if debug then Repository.WriteOutput "Script", "<!-- Debug: conn.Type [" & conn.Type & "] conn.ClientID [" & conn.ClientID & "] conn.SupplierID [" & conn.SupplierID & "]. -->",0
if conn.Type = "Generalization" then
if element.ElementID = conn.ClientID then
if debug then Repository.WriteOutput "Script", "<!-- Debug: supertype [" & Repository.GetElementByID(conn.SupplierID).Name & "]. -->",0
' superlist = getSupertypes(ftname, conn.SupplierID, indent)
set super = Repository.GetElementByID(conn.SupplierID)
call listJsonFgGeometry(ftname,super,indent)
end if
end if
next
' if debug then Repository.WriteOutput "Script", "Debug: superlist [" & superlist & "].",0
'' TBD first find first geometry
dim attr as EA.Attribute
for each attr in element.Attributes
if getSosiGeometritype(attr) <> "" then
'' TBD
if gnum > 0 then
SessionOutput(" ,")
end if
gnum = gnum + 1
geomtype = getSosiGeometritype(attr)
geomtype = attr.Type
' SessionOutput("geomtype "&geomtype)
if geomtype = "Punkt" or geomtype = "GM_Point" then
pnteller = pnteller + 1
SessionOutput(" ""type"": ""Point"",")
SessionOutput(" ""coordinates"": [" &r1+eastoffset&", "&r2&", "&r3&"]")
end if