annotate pkg/models/cross.go @ 633:6093016fac88

Cross sections: started with implementation of web service (WIP).
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 12 Sep 2018 19:51:46 +0200
parents
children 7a867e48b3c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 package models
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 import (
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 "encoding/json"
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 "errors"
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 "time"
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 )
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 type (
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10 GeoJSONFeature string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 GeoJSONLineStringType string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13 GeoJSONDate struct{ time.Time }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 GeoJSONLineString struct {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16 Type GeoJSONLineStringType `json:"type"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 GeoJSONCoordinate struct {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 Lon float64
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 Lat float64
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 CrossSectionInputProperties struct {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 Bottleneck string `json:"bottleneck"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 Date GeoJSONDate `json:"date"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 CrossSectionInput struct {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 Type GeoJSONFeature `json:"type"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 Geometry GeoJSONLineString `json:"geometry"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 Coordinates []GeoJSONCoordinate `json:"coordinates"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 Properties CrossSectionInputProperties `json:"properties"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 )
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 var (
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 errNoGeoJSONFeature = errors.New("Not a valid GeoJSON feature")
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39 errNoGeoJSONLineStringType = errors.New("Not a valid GeoJSON linestring type")
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
40 )
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 func (d *GeoJSONDate) UnmarshalJSON(data []byte) error {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 var s string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 if err := json.Unmarshal(data, &s); err != nil {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 t, err := time.Parse("2006-01-02", s)
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48 if err != nil {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
51 *d = GeoJSONDate{t}
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 return nil
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 func (c *GeoJSONCoordinate) UnmarshalJSON(data []byte) error {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 pos := make([]float64, 2)
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57 if err := json.Unmarshal(data, &pos); err != nil {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
58 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
59 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
60 *c = GeoJSONCoordinate{Lon: pos[0], Lat: pos[1]}
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 return nil
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
62 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
63
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
64 func (t *GeoJSONFeature) UnmarshalJSON(data []byte) error {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
65 var s string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
66 if err := json.Unmarshal(data, &s); err != nil {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
67 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 if s != "Feature" {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 return errNoGeoJSONFeature
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
72 *t = GeoJSONFeature(s)
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73 return nil
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 func (t *GeoJSONLineStringType) UnmarshalJSON(data []byte) error {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77 var s string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
78 if err := json.Unmarshal(data, &s); err != nil {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
79 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
80 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
81 if s != "LineString" {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
82 return errNoGeoJSONLineStringType
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
83 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
84 *t = GeoJSONLineStringType(s)
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
85 return nil
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
86 }