generated from trias-project/checklist-recipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwc_emof.sql
871 lines (765 loc) · 32.6 KB
/
dwc_emof.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
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
/*
Schema: https://rs.gbif.org/extension/obis/extended_measurement_or_fact.xml
See https://github.com/inbo/esas2obis/issues/10 for mapping decisions
*/
/* SAMPLE: PLATFORM CODE */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'platform code' AS measurementType,
'http://vocab.nerc.ac.uk/collection/Q01/current/Q0100001/' AS measurementTypeID,
shipc.Description AS measurementValue, -- Keep capitalization
'http://vocab.nerc.ac.uk/collection/C17/current/' || shipc.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
LEFT JOIN shipc
ON s.PlatformCode = shipc.Key
WHERE
s.PlatformCode IS NOT NULL
UNION
/* SAMPLE: PLATFORM CLASS */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'platform class' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Platform%20Class' AS measurementTypeID,
CASE
WHEN platformclass.Key = 30 THEN 'ship' -- 30: Ship
WHEN platformclass.Key = 62 THEN 'aeroplane' -- 62: aeroplane
WHEN platformclass.Key = 67 THEN 'helicopter' -- 67: Helicopter
ELSE lower(platformclass.Description)
END AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Platform%20Class/' || platformclass.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
LEFT JOIN platformclass
ON s.PlatformClass = platformclass.Key
WHERE
s.PlatformClass IS NOT NULL
UNION
/* SAMPLE: PLATFORM SIDE */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'platform side' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/PlatformSide' AS measurementTypeID,
lower(platformside.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/PlatformSide/' || platformside.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
LEFT JOIN platformside
ON s.PlatformSide = platformside.Key
WHERE
s.PlatformSide IS NOT NULL
UNION
/* SAMPLE: PLATFORM HEIGHT */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'platform height' AS measurementType,
NULL AS measurementTypeID,
s.PlatformHeight AS measurementValue,
NULL AS measurementValueID,
'm' AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/ULAA/' AS measurementUnitID
FROM
samples AS s
WHERE
s.PlatformHeight IS NOT NULL
UNION
/* SAMPLE: TRANSECT WIDTH */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'transect width' AS measurementType,
NULL AS measurementTypeID,
s.TransectWidth AS measurementValue,
NULL AS measurementValueID,
'm' AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/ULAA/' AS measurementUnitID
FROM
samples AS s
WHERE
s.TransectWidth IS NOT NULL
UNION
/* SAMPLE: SAMPLING METHOD */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'sampling method' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P01/current/SAMPPROT/' AS measurementTypeID,
lower(bdcountmethod.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/BD_CountMethod/' || bdcountmethod.Key AS measurementValueID,
NULL AS measurementUnit,
'https://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
LEFT JOIN bdcountmethod
ON s.SamplingMethod = bdcountmethod.Key
WHERE
s.SamplingMethod IS NOT NULL
UNION
/* SAMPLE: PRIMARY SAMPLING */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'primary sampling' AS measurementType,
NULL AS measurementTypeID,
s.PrimarySampling AS measurementValue,
NULL AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
WHERE
s.PrimarySampling IS NOT NULL
UNION
/* SAMPLE: TARGET TAXA */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'target taxa' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/TargetTaxa' AS measurementTypeID,
CASE
-- Keep capitalization of Larus
WHEN targettaxa.Key = 2 THEN 'all species except Larus gulls'
WHEN targettaxa.Key = 4 THEN 'all species except Larus gulls, fulmars and kittiwakes'
ELSE lower(targettaxa.Description)
END AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/TargetTaxa/' || targettaxa.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
LEFT JOIN targettaxa
ON s.TargetTaxa = targettaxa.Key
WHERE
s.TargetTaxa IS NOT NULL
UNION
/* SAMPLE: DISTANCE BINS */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'distance bins' AS measurementType,
NULL AS measurementTypeID,
s.DistanceBins AS measurementValue,
NULL AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
WHERE
s.DistanceBins IS NOT NULL
UNION
/* SAMPLE: USE OF BINOCULARS */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'use of binoculars' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/UseOfBinoculars' AS measurementTypeID,
lower(useofbinoculars.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/UseOfBinoculars/' || useofbinoculars.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
samples AS s
LEFT JOIN useofbinoculars
ON s.UseOfBinoculars = useofbinoculars.Key
WHERE
s.UseOfBinoculars IS NOT NULL
UNION
/* SAMPLE: NUMBER OF OBSERVERS */
SELECT
s.CampaignID || '_' || s.SampleID AS eventID,
NULL AS occurrenceID,
'number of observers' AS measurementType,
NULL AS measurementTypeID,
s.NumberOfObservers AS measurementValue,
NULL AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/UUUU/' AS measurementUnitID
FROM
samples AS s
WHERE
s.NumberOfObservers IS NOT NULL
UNION
/* POSITION: DISTANCE */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'distance' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P01/current/DISTPHMS/' AS measurementTypeID,
p.Distance AS measurementValue,
NULL AS measurementValueID,
'km' AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/ULKM/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
WHERE
p.Distance IS NOT NULL
UNION
/* POSITION: AREA */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'area' AS measurementType,
'https://vocab.nerc.ac.uk/collection/P01/current/SAMPARAX/' AS measurementTypeID,
p.Area AS measurementValue,
NULL AS measurementValueID,
'km2' AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/SQKM/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
WHERE
p.Area IS NOT NULL
UNION
/* POSITION: WINDFORCE */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'wind force' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P01/current/WMOCWFBF/' AS measurementTypeID,
lower(beaufort.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Beaufort/' || beaufort.Key AS measurementValueID,
'Beaufort' AS measurementUnit,
' http://vocab.nerc.ac.uk/collection/P06/current/UUUU/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN beaufort
ON p.WindForce = beaufort.Key
WHERE
p.WindForce IS NOT NULL
UNION
/* POSITION: VISIBILITY */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'visibility' AS measurementType,
CASE
WHEN visibility.Key IN ('A', 'B', 'C', 'D') THEN 'http://vocab.nerc.ac.uk/collection/P01/current/VISHOR04/' -- ESAS specific
ELSE 'http://vocab.nerc.ac.uk/collection/P01/current/VISHOR03/' -- Numeric values
END AS measurementTypeID,
visibility.Key AS measurementValue, -- Codes, not descriptions (defined as such in http://vocab.nerc.ac.uk/collection/P01/current/VISHOR04/)
'https://vocab.ices.dk/services/rdf/collection/Visibility/' || visibility.Key AS measurementValueID, -- Numeric values are also in vocab
CASE
WHEN visibility.Key IN ('A', 'B', 'C', 'D') THEN NULL
ELSE 'km'
END AS measurementUnit,
CASE
WHEN visibility.Key IN ('A', 'B', 'C', 'D') THEN NULL
ELSE 'http://vocab.nerc.ac.uk/collection/P06/current/ULKM/'
END AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN visibility
ON p.Visibility = visibility.Key
WHERE
p.Visibility IS NOT NULL
UNION
/* POSITION: GLARE */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'glare' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Glare' AS measurementTypeID,
lower(glare.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Glare/' || glare.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN glare
ON p.Glare = glare.Key
WHERE
p.Glare IS NOT NULL
UNION
/* POSITION: SUN ANGLE */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'sun angle' AS measurementType,
NULL AS measurementTypeID,
p.SunAngle AS measurementValue,
NULL AS measurementValueID,
'degrees' AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/UAAA/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
WHERE
p.SunAngle IS NOT NULL
UNION
/* POSITION: CLOUD COVER */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'cloud cover' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P02/current/CHEX/' AS measurementTypeID,
lower(cloudcover.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/CloudCover/' || cloudcover.Key AS measurementValueID,
'okta' AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/UUUU/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN cloudcover
ON p.CloudCover = cloudcover.Key
WHERE
p.CloudCover IS NOT NULL
UNION
/* POSITION: PRECIPITATION */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'precipitation' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Precipitation' AS measurementTypeID,
lower(precipitation.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Precipitation/' || precipitation.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN precipitation
ON p.Precipitation = precipitation.Key
WHERE
p.Precipitation IS NOT NULL
UNION
/* POSITION: ICE COVER */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'ice cover' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P07/current/CFSN0424/' AS measurementTypeID,
p.IceCover AS measurementValue,
NULL AS measurementValueID,
'percent' AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/UPCT/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
WHERE
p.IceCover IS NOT NULL
UNION
/* POSITION: OBSERVATION CONDITIONS */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
NULL AS occurrenceID,
'observation conditions' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Sightability' AS measurementTypeID,
lower(sightability.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Sightability/' || sightability.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
positions AS p
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN sightability
ON p.ObservationConditions = sightability.Key
WHERE
p.ObservationConditions IS NOT NULL
UNION
/* OBSERVATION: GROUP IDENTIFIER */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'group identifier' AS measurementType,
NULL AS measurementTypeID,
o.GroupID AS measurementValue,
NULL AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
WHERE
o.GroupID IS NOT NULL
UNION
/* OBSERVATION: TRANSECT */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'in transect' AS measurementType,
NULL AS measurementTypeID,
o.Transect AS measurementValue,
NULL AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
WHERE
o.Transect IS NOT NULL
UNION
/* OBSERVATION: INDIVIDUAL COUNT */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'individual count' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P01/current/OCOUNT01/' AS measurementTypeID,
o.Count AS measurementValue,
NULL AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/UUUU/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
WHERE
o.Count IS NOT NULL
UNION
/* OBSERVATION: OBSERVATION DISTANCE */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'observation distance' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/ObservationDistance' AS measurementTypeID,
CASE
WHEN observationdistance.Key = 'A' THEN '0-50'
WHEN observationdistance.Key = 'B' THEN '50-100'
WHEN observationdistance.Key = 'C' THEN '100-200'
WHEN observationdistance.Key = 'D' THEN '200-300'
WHEN observationdistance.Key = 'E' THEN '>300'
WHEN observationdistance.Key = 'F' THEN lower(observationdistance.Description) -- flying, no contact with water
WHEN observationdistance.Key = 'W' THEN lower(observationdistance.Description) -- in contact with the water, but distance not recorded
ELSE o.ObservationDistance -- Expressed as number
END AS measurementValue,
CASE
WHEN observationdistance.Key IN ('A', 'B', 'C', 'D', 'E', 'F', 'W') -- Only when expressed as letter
THEN 'https://vocab.ices.dk/services/rdf/collection/ObservationDistance/' || observationdistance.Key
END AS measurementValueID,
CASE
WHEN observationdistance.Key = 'F' THEN NULL -- Not meters
WHEN observationdistance.Key = 'W' THEN NULL -- Not meters
ELSE 'm'
END AS measurementUnit,
CASE
WHEN observationdistance.Key = 'F' THEN 'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' -- Not meters
WHEN observationdistance.Key = 'W' THEN 'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' -- Not meters
ELSE 'http://vocab.nerc.ac.uk/collection/P06/current/ULAA/'
END AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN observationdistance
ON o.ObservationDistance = observationdistance.Key
WHERE
o.ObservationDistance IS NOT NULL
UNION
/* OBSERVATION: LIFE STAGE */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'life stage' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P01/current/LSTAGE01/' AS measurementTypeID,
lower(lifestage.Description) AS measurementValue,
CASE
WHEN lifestage.Key = 'A' THEN 'http://vocab.nerc.ac.uk/collection/S11/current/S1116/'
WHEN lifestage.Key = 'I' THEN 'http://vocab.nerc.ac.uk/collection/S11/current/S1171/'
WHEN lifestage.Key = '1' THEN 'https://vocab.ices.dk/services/rdf/collection/LifeStage/' || lifestage.Key
WHEN lifestage.Key = '2' THEN 'https://vocab.ices.dk/services/rdf/collection/LifeStage/' || lifestage.Key
WHEN lifestage.Key = '3' THEN 'https://vocab.ices.dk/services/rdf/collection/LifeStage/' || lifestage.Key
WHEN lifestage.Key = '4' THEN 'https://vocab.ices.dk/services/rdf/collection/LifeStage/' || lifestage.Key
WHEN lifestage.Key = '5' THEN 'https://vocab.ices.dk/services/rdf/collection/LifeStage/' || lifestage.Key
END AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN lifestage
ON o.LifeStage = lifestage.Key
WHERE
o.LifeStage IS NOT NULL
UNION
/* OBSERVATION: MOULT */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'moult' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Moult' AS measurementTypeID,
lower(moult.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Moult/' || moult.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN moult
ON o.Moult = moult.Key
WHERE
o.Moult IS NOT NULL
UNION
/* OBSERVATION: PLUMAGE */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'plumage' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Plumage' AS measurementTypeID,
CASE
-- Keep capitalization of LL, ...
WHEN plumage.Key = 'L' THEN 'light morph (skuas/double light LL fulmars)'
WHEN plumage.Key = 'C' THEN 'coloured morph (L, D & DD fulmars)'
ELSE lower(plumage.Description)
END AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Plumage/' || plumage.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN plumage
ON o.Plumage = plumage.Key
WHERE
o.Plumage IS NOT NULL
UNION
/* OBSERVATION: SEX */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'sex' AS measurementType,
'http://vocab.nerc.ac.uk/collection/P01/current/ENTSEX01/' AS measurementTypeID,
lower(sex.Description) AS measurementValue,
CASE
WHEN sex.Key = 'F' THEN 'http://vocab.nerc.ac.uk/collection/S10/current/S102/'
WHEN sex.Key = 'M' THEN 'http://vocab.nerc.ac.uk/collection/S10/current/S103/'
END AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN sex
ON o.Sex = sex.Key
WHERE
o.Sex IS NOT NULL
UNION
/* OBSERVATION: TRAVEL DIRECTION */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'travel direction' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/TravelDirection' AS measurementTypeID,
CASE
WHEN traveldirection.Key = 'N' THEN '0'
WHEN traveldirection.Key = 'NE' THEN '45'
WHEN traveldirection.Key = 'E' THEN '90'
WHEN traveldirection.Key = 'SE' THEN '135'
WHEN traveldirection.Key = 'S' THEN '180'
WHEN traveldirection.Key = 'SW' THEN '225'
WHEN traveldirection.Key = 'W' THEN '270'
WHEN traveldirection.Key = 'NW' THEN '315'
WHEN traveldirection.Key = 'U' THEN lower(traveldirection.Description) -- flying, no apparent direction
ELSE o.TravelDirection -- Expressed in degrees
END AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/TravelDirection/' || traveldirection.Key AS measurementValueID,
CASE
WHEN traveldirection.Key = 'U' THEN NULL
ELSE 'degrees'
END AS measurementUnit,
CASE
WHEN traveldirection.Key = 'U' THEN 'https://vocab.nerc.ac.uk/collection/P06/current/XXXX/'
ELSE 'https://vocab.nerc.ac.uk/collection/P06/current/UAAA/'
END AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN traveldirection
ON o.TravelDirection = traveldirection.Key
WHERE
o.TravelDirection IS NOT NULL
UNION
/* OBSERVATION: PREY */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'prey' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/PreyType' AS measurementTypeID,
CASE
-- Keep capitalization of scientific names
WHEN preytype.Key = 34 THEN 'worm (e.g. Nereis)'
WHEN preytype.Key = 35 THEN 'barnacles (Balanidae)'
ELSE lower(preytype.Description)
END AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/PreyType/' || preytype.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN preytype
ON o.Prey = preytype.Key
WHERE
o.Prey IS NOT NULL
UNION
/* OBSERVATION: ASSOCIATION x 3 */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'association' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Association' AS measurementTypeID,
lower(substr(association.Description, 1, 1)) || substr(association.Description, 2) AS measurementValue, -- Keep capitalization of MSFA by lowercasing first letter only
'https://vocab.ices.dk/services/rdf/collection/Association/' || association.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN association
ON o.Association_1 = association.Key
WHERE
o.Association_1 IS NOT NULL
UNION
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'association' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Association' AS measurementTypeID,
lower(substr(association.Description, 1, 1)) || substr(association.Description, 2) AS measurementValue, -- Keep capitalization of MSFA by lowercasing first letter only
'https://vocab.ices.dk/services/rdf/collection/Association/' || association.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN association
ON o.Association_2 = association.Key
WHERE
o.Association_2 IS NOT NULL
UNION
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'association' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Association' AS measurementTypeID,
lower(substr(association.Description, 1, 1)) || substr(association.Description, 2) AS measurementValue, -- Keep capitalization of MSFA by lowercasing first letter only
'https://vocab.ices.dk/services/rdf/collection/Association/' || association.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN association
ON o.Association_3 = association.Key
WHERE
o.Association_3 IS NOT NULL
UNION
/* OBSERVATION: BEHAVIOUR x 3 */
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'behaviour' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Behaviour' AS measurementTypeID,
lower(behaviour.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Behaviour/' || behaviour.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN behaviour
ON o.Behaviour_1 = behaviour.Key
WHERE
o.Behaviour_1 IS NOT NULL
UNION
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'behaviour' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Behaviour' AS measurementTypeID,
lower(behaviour.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Behaviour/' || behaviour.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN behaviour
ON o.Behaviour_2 = behaviour.Key
WHERE
o.Behaviour_2 IS NOT NULL
UNION
SELECT
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID AS eventID,
s.CampaignID || '_' || s.SampleID || '_' || p.PositionID || '_' || o.ObservationID AS occurrenceID,
'behaviour' AS measurementType,
'https://vocab.ices.dk/services/rdf/collection/Behaviour' AS measurementTypeID,
lower(behaviour.Description) AS measurementValue,
'https://vocab.ices.dk/services/rdf/collection/Behaviour/' || behaviour.Key AS measurementValueID,
NULL AS measurementUnit,
'http://vocab.nerc.ac.uk/collection/P06/current/XXXX/' AS measurementUnitID
FROM
observations AS o
LEFT JOIN positions AS p
ON o.PositionID = p.PositionID
LEFT JOIN samples AS s
ON p.SampleID = s.SampleID
LEFT JOIN behaviour
ON o.Behaviour_3 = behaviour.Key
WHERE
o.Behaviour_3 IS NOT NULL