Mercurial > gemma
annotate pkg/models/cross.go @ 801:b6a1779ffb42
Removed old cross section controller.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 27 Sep 2018 13:18:50 +0200 |
parents | ce23a4192788 |
children | e10a8a682297 |
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 ( |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
4 "bytes" |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
5 "encoding/binary" |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 "encoding/json" |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 "errors" |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
8 "fmt" |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
9 "math" |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 "time" |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 ) |
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 type ( |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 GeoJSONFeature string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 GeoJSONLineStringType string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 GeoJSONDate struct{ time.Time } |
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 GeoJSONLineString struct { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 Type GeoJSONLineStringType `json:"type"` |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 } |
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 GeoJSONCoordinate struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
24 Lat float64 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 Lon float64 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
27 |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
28 GeoJSONCoordinateZ struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
29 Lat float64 |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
30 Lon float64 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
31 Z float64 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
32 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
33 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 CrossSectionInputProperties struct { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
35 Bottleneck string `json:"bottleneck"` |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 Date GeoJSONDate `json:"date"` |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
38 |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
39 GeoJSONLineCoordinates []GeoJSONCoordinate |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
40 GeoJSONLineCoordinatesZ []GeoJSONCoordinateZ |
636
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
41 |
648
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
42 GeoJSONMultiLineCoordinatesZ []GeoJSONLineCoordinatesZ |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
43 |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
44 CrossSectionInputGeometry struct { |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
45 Type GeoJSONLineStringType `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
46 Coordinates GeoJSONLineCoordinates `json:"coordinates"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
47 } |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
48 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
49 CrossSectionInput struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
50 Type GeoJSONFeature `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
51 Geometry CrossSectionInputGeometry `json:"geometry"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
52 Properties CrossSectionInputProperties `json:"properties"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
53 } |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
54 |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
55 CrossSectionOutputGeometry struct { |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
56 Type string `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
57 Coordinates GeoJSONMultiLineCoordinatesZ `json:"coordinates"` |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
59 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
60 CrossSectionOutput struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
61 Type string `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
62 Geometry CrossSectionOutputGeometry `json:"geometry"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
63 Properties map[string]interface{} `json:"properties"` |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
64 } |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
65 ) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
66 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
67 var ( |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
68 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
|
69 errNoGeoJSONLineStringType = errors.New("Not a valid GeoJSON linestring type") |
636
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
70 errTooLessComponents = errors.New("Too less components in coordinate") |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
71 errTooLessCoordinates = errors.New("Too less coordinates") |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
72 ) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
73 |
636
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
74 func (lc *GeoJSONLineCoordinates) UnmarshalJSON(data []byte) error { |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
75 var coords []GeoJSONCoordinate |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
76 if err := json.Unmarshal(data, &coords); err != nil { |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
77 return err |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
78 } |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
79 if len(coords) < 2 { |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
80 return errTooLessCoordinates |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
81 } |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
82 *lc = GeoJSONLineCoordinates(coords) |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
83 return nil |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
84 } |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
85 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
86 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
|
87 var s string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
88 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
|
89 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
91 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
|
92 if err != nil { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
93 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
95 *d = GeoJSONDate{t} |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
96 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
98 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
99 func (c *GeoJSONCoordinate) UnmarshalJSON(data []byte) error { |
636
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
100 var pos []float64 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
101 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
|
102 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
103 } |
636
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
104 if len(pos) < 2 { |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
105 return errTooLessComponents |
7a867e48b3c2
Cross sections: Enforce minimal length of coordinates components and coordinates in input linestrings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
106 } |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
107 *c = GeoJSONCoordinate{Lat: pos[0], Lon: pos[1]} |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
108 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
109 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
110 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
111 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
|
112 var s string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
113 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
|
114 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
116 if s != "Feature" { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
117 return errNoGeoJSONFeature |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
119 *t = GeoJSONFeature(s) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
120 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
122 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
123 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
|
124 var s string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
125 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
|
126 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
127 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
128 if s != "LineString" { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
129 return errNoGeoJSONLineStringType |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
130 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
131 *t = GeoJSONLineStringType(s) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
132 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
133 } |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
134 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
135 const ( |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
136 wkbXDR byte = 0 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
137 wkbNDR byte = 1 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
138 wkbLineString uint32 = 2 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
139 wkbLineStringZ uint32 = 1000 + 2 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
140 ) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
141 |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
142 func (lc GeoJSONLineCoordinates) AsWKB() []byte { |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
143 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
144 size := 1 + 4 + 4 + len(lc)*(1+4+2*8) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
145 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
146 buf := bytes.NewBuffer(make([]byte, 0, size)) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
147 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
148 binary.Write(buf, binary.LittleEndian, wkbNDR) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
149 binary.Write(buf, binary.LittleEndian, wkbLineString) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
150 binary.Write(buf, binary.LittleEndian, uint32(len(lc))) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
151 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
152 for i := range lc { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
153 c := &lc[i] |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
154 binary.Write(buf, binary.LittleEndian, math.Float64bits(c.Lat)) |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
155 binary.Write(buf, binary.LittleEndian, math.Float64bits(c.Lon)) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
156 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
157 |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
158 return buf.Bytes() |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
159 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
160 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
161 func (cz GeoJSONCoordinateZ) MarshalJSON() ([]byte, error) { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
162 var buf bytes.Buffer |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
163 fmt.Fprintf(&buf, "[%.8f,%.8f,%.8f]", cz.Lat, cz.Lon, cz.Z) |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
164 return buf.Bytes(), nil |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
165 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
166 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
167 func (lcz *GeoJSONLineCoordinatesZ) Scan(src interface{}) error { |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
168 data, ok := src.([]byte) |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
169 if !ok { |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
170 return errNoByteSlice |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
171 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
172 return lcz.FromWKB(data) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
173 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
174 |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
175 func (lcz *GeoJSONLineCoordinatesZ) FromWKB(data []byte) error { |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
176 |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
177 r := bytes.NewReader(data) |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
178 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
179 endian, err := r.ReadByte() |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
180 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
181 var order binary.ByteOrder |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
182 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
183 switch { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
184 case err != nil: |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
185 return err |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
186 case endian == wkbNDR: |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
187 order = binary.LittleEndian |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
188 case endian == wkbXDR: |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
189 order = binary.BigEndian |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
190 default: |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
191 return fmt.Errorf("unknown byte order %x", endian) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
192 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
193 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
194 var geomType uint32 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
195 err = binary.Read(r, order, &geomType) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
196 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
197 switch { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
198 case err != nil: |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
199 return err |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
200 case geomType != wkbLineStringZ: |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
201 return fmt.Errorf("unknown geometry type %x", geomType) |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
202 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
203 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
204 var num uint32 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
205 if err = binary.Read(r, order, &num); err != nil { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
206 return err |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
207 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
208 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
209 coords := make(GeoJSONLineCoordinatesZ, num) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
210 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
211 for i := range coords { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
212 c := &coords[i] |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
213 for _, addr := range []*float64{&c.Lat, &c.Lon, &c.Z} { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
214 if err = binary.Read(r, order, addr); err != nil { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
215 return err |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
216 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
217 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
218 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
219 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
220 *lcz = coords |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
221 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
222 return nil |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
223 } |
648
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
224 |
651
ce18231825a2
Cross sections: Small details on Equals Method of GeoJSONCoordinateZ (forget to commit).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
225 func (cz GeoJSONCoordinateZ) Equals(other GeoJSONCoordinateZ) bool { |
648
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
226 const ( |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
227 xyEps = 1e-7 |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
228 zEps = 1e-5 |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
229 ) |
651
ce18231825a2
Cross sections: Small details on Equals Method of GeoJSONCoordinateZ (forget to commit).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
230 return math.Abs(cz.Lat-other.Lat) < xyEps && |
648
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
231 math.Abs(cz.Lon-other.Lon) < xyEps && |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
232 math.Abs(cz.Z-other.Z) < zEps |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
233 } |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
234 |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
235 func (cz GeoJSONCoordinateZ) mid(other GeoJSONCoordinateZ) GeoJSONCoordinateZ { |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
236 return GeoJSONCoordinateZ{ |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
237 Lon: (cz.Lon + other.Lon) * 0.5, |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
238 Lat: (cz.Lat + other.Lat) * 0.5, |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
239 Z: (cz.Z + other.Z) * 0.5, |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
240 } |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
241 } |
cf62cb84fa23
Cross sections: Added a naive O(N^2) algorithm to join the neighbored line segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
242 |
652
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
243 func deg2rad(d float64) float64 { return d * math.Pi / 180.0 } |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
244 |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
245 func (cz GeoJSONCoordinateZ) Distance(other GeoJSONCoordinateZ) float64 { |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
246 |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
247 const EarthRadius = 6378137.0 |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
248 |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
249 dLat := deg2rad(other.Lat - cz.Lat) |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
250 dLng := math.Abs(deg2rad(other.Lon - cz.Lon)) |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
251 |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
252 if dLng > math.Pi { |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
253 dLng = 2*math.Pi - dLng |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
254 } |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
255 |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
256 x := dLng * math.Cos(deg2rad((cz.Lat+other.Lat)/2.0)) |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
257 return math.Sqrt(dLat*dLat+x*x) * EarthRadius |
f5ecd1d72a6e
Cross section: Replaced naive O(N^2) segment joining with a more clever one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
651
diff
changeset
|
258 } |