-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubresource.go
More file actions
75 lines (70 loc) · 2.73 KB
/
Copy pathsubresource.go
File metadata and controls
75 lines (70 loc) · 2.73 KB
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
// OGC temporal sub-resource assembly in the tier: the TemporalGeometrySequence
// envelope and the temporalProperty valueSequence reshaping. The engine returns
// the canonical asMFJSON outputs; their reshaping into the OGC objects is JSON
// framing, assembled here once for every backend.
package main
import (
"encoding/json"
"strconv"
)
type tPropDoc struct {
Name string `json:"name"`
Type string `json:"type"`
Form string `json:"form"`
Description string `json:"description"`
ValueSequence []map[string]json.RawMessage `json:"valueSequence"`
Links []ogcLink `json:"links"`
}
// reshapeTemporalProperty turns a value's asMFJSON (continuous values under
// "sequences" or a discrete top-level datetimes/values object) into an OGC
// temporalProperty, keeping each segment's interpolation verbatim.
func reshapeTemporalProperty(name, typ, form, desc, self string, mfjson []byte) ([]byte, error) {
var j map[string]json.RawMessage
if err := json.Unmarshal(mfjson, &j); err != nil {
return nil, err
}
interp := j["interpolation"]
seg := func(m map[string]json.RawMessage) map[string]json.RawMessage {
return map[string]json.RawMessage{
"datetimes": m["datetimes"], "values": m["values"], "interpolation": interp,
"lower_inc": m["lower_inc"], "upper_inc": m["upper_inc"]}
}
vs := []map[string]json.RawMessage{}
if raw, ok := j["sequences"]; ok {
var arr []map[string]json.RawMessage
if err := json.Unmarshal(raw, &arr); err != nil {
return nil, err
}
for _, s := range arr {
vs = append(vs, seg(s))
}
} else if _, ok := j["datetimes"]; ok {
vs = append(vs, seg(j))
}
return json.Marshal(tPropDoc{Name: name, Type: typ, Form: form, Description: desc,
ValueSequence: vs, Links: []ogcLink{{Rel: "self", Href: self}}})
}
type tgSeqDoc struct {
Type string `json:"type"`
GeometrySequence []json.RawMessage `json:"geometrySequence"`
Links []ogcLink `json:"links"`
}
// buildTGSequence assembles the TemporalGeometrySequence: each member is the
// asMFJSON of one sequence with its 1-based id, addressable as {tGeometryId}.
func buildTGSequence(self string, ns []int, mfjsons [][]byte) ([]byte, error) {
elems := []json.RawMessage{}
for i, n := range ns {
var m map[string]json.RawMessage
if err := json.Unmarshal(mfjsons[i], &m); err != nil {
return nil, err
}
m["id"] = json.RawMessage(strconv.Itoa(n))
b, err := json.Marshal(m)
if err != nil {
return nil, err
}
elems = append(elems, b)
}
return json.Marshal(tgSeqDoc{Type: "TemporalGeometrySequence",
GeometrySequence: elems, Links: []ogcLink{{Rel: "self", Href: self}}})
}