Mercurial > gemma
annotate pkg/models/cross.go @ 5721:0500d76e074b uploadwg
Fixed eraseObsoleteGaugesSQL by reintroducing matching on users CC.
The condition was removed when introducing file upload, but that leads
to too many gauges being removed.
author | Sascha Wilde <wilde@sha-bang.de> |
---|---|
date | Fri, 19 Apr 2024 16:52:14 +0200 |
parents | 6270951dda28 |
children |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
895
diff
changeset
|
13 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 package models |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
17 "bytes" |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
18 "encoding/binary" |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 "encoding/json" |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 "errors" |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
21 "fmt" |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
22 "math" |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 "time" |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
24 |
3094
a347468ea545
Use common.DateFormat for parsing dates everywhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/common" |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/wkb" |
633
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 type ( |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
30 // GeoJSONFeature is a GeoJSON feature. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
31 GeoJSONFeature string |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
32 // GeoJSONLineStringType is a GeoJSON line string type. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 GeoJSONLineStringType string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
35 // GeoJSONDate is used to represent dates in GeoJSON. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 GeoJSONDate struct{ time.Time } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
38 // GeoJSONLineString is used to represent a linestring |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
39 // as GeoJSON. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
40 GeoJSONLineString struct { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
41 Type GeoJSONLineStringType `json:"type"` |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
43 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
44 // GeoJSONCoordinate is a lat/lon coordinate in GeoJSON. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
45 GeoJSONCoordinate struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
46 Lat float64 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
47 Lon float64 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
49 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
50 // GeoJSONCoordinateZ is a lat/lon coordinate with a z value. |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
51 GeoJSONCoordinateZ struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
52 Lat float64 |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
53 Lon float64 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
54 Z float64 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
55 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
56 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
57 // CrossSectionInputProperties models the input |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
58 // parameters for a cross section. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
59 CrossSectionInputProperties struct { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
60 Bottleneck string `json:"bottleneck"` |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
61 Date GeoJSONDate `json:"date"` |
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 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
64 // GeoJSONLineCoordinates is a list of lat/lon coordinates. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
65 GeoJSONLineCoordinates []GeoJSONCoordinate |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
66 // GeoJSONLineCoordinatesZ is a list of lat/lon/z coordinates. |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
67 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
|
68 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
69 // GeoJSONMultiLineCoordinatesZ is a list of list of lat/lon/z coords. |
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
|
70 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
|
71 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
72 // CrossSectionInputGeometry models the input geometry |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
73 // of a cross section. |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
74 CrossSectionInputGeometry struct { |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
75 Type GeoJSONLineStringType `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
76 Coordinates GeoJSONLineCoordinates `json:"coordinates"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
77 } |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
78 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
79 // CrossSectionInput is combination of geometry and |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
80 // attributes of a cross section input. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
81 CrossSectionInput struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
82 Type GeoJSONFeature `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
83 Geometry CrossSectionInputGeometry `json:"geometry"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
84 Properties CrossSectionInputProperties `json:"properties"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
85 } |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
86 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
87 // CrossSectionOutputGeometry is the geometry part of |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
88 // the cross section output. |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
89 CrossSectionOutputGeometry struct { |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
90 Type string `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
91 Coordinates GeoJSONMultiLineCoordinatesZ `json:"coordinates"` |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
92 } |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
93 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
94 // CrossSectionOutput is the combination of the geometry |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
95 // and the properties of a cross section output. |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
96 CrossSectionOutput struct { |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
97 Type string `json:"type"` |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
98 Geometry CrossSectionOutputGeometry `json:"geometry"` |
5712
6270951dda28
/interface{}/any/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
99 Properties map[string]any `json:"properties"` |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
100 } |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
101 ) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
102 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
103 var ( |
4847
4847ac70103a
Made staticcheck happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3094
diff
changeset
|
104 errNoGeoJSONFeature = errors.New("not a valid GeoJSON feature") |
4847ac70103a
Made staticcheck happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3094
diff
changeset
|
105 errNoGeoJSONLineStringType = errors.New("not a valid GeoJSON linestring type") |
4847ac70103a
Made staticcheck happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3094
diff
changeset
|
106 errTooLessComponents = errors.New("too less components in coordinate") |
4847ac70103a
Made staticcheck happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3094
diff
changeset
|
107 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
|
108 ) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
109 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
110 // UnmarshalJSON implements the json.Unmarshaler interface. |
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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 } |
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
|
116 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
|
117 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
|
118 } |
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
|
119 *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
|
120 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
|
121 } |
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
|
122 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
123 // UnmarshalJSON implements the json.Unmarshaler interface. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
124 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
|
125 var s string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
126 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
|
127 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
3094
a347468ea545
Use common.DateFormat for parsing dates everywhere.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2471
diff
changeset
|
129 t, err := time.Parse(common.DateFormat, s) |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
130 if err != nil { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
131 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
133 *d = GeoJSONDate{t} |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
134 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
136 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
137 // UnmarshalJSON implements the json.Unmarshaler interface. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
138 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
|
139 var pos []float64 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
140 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
|
141 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
142 } |
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
|
143 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
|
144 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
|
145 } |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
146 *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
|
147 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
148 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
149 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
150 // UnmarshalJSON implements the json.Unmarshaler interface. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
151 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
|
152 var s string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
153 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
|
154 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
155 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
156 if s != "Feature" { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
157 return errNoGeoJSONFeature |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
159 *t = GeoJSONFeature(s) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
160 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
161 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
162 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
163 // UnmarshalJSON implements the json.Unmarshaler interface. |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
164 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
|
165 var s string |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
166 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
|
167 return err |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
168 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
169 if s != "LineString" { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
170 return errNoGeoJSONLineStringType |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
171 } |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
172 *t = GeoJSONLineStringType(s) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
173 return nil |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
174 } |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
175 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
176 // AsWKB serializes a line string as WKB. |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
177 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
|
178 |
1683
509e8728e846
Fixed pre-calculated size of 2D WKB line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1324
diff
changeset
|
179 size := 1 + 4 + 4 + len(lc)*(2*8) |
643
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 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
|
182 |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
183 binary.Write(buf, binary.LittleEndian, wkb.NDR) |
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
184 binary.Write(buf, binary.LittleEndian, wkb.LineString) |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
185 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
|
186 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
187 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
|
188 c := &lc[i] |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
189 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
|
190 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
|
191 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
192 |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
193 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
|
194 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
195 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
196 // MarshalJSON implements ths json.Marshaler interface. |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
197 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
|
198 var buf bytes.Buffer |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
652
diff
changeset
|
199 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
|
200 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
|
201 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
202 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
203 // Scan implements sql.Scanner interface. |
5712
6270951dda28
/interface{}/any/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
204 func (lcz *GeoJSONLineCoordinatesZ) Scan(src any) error { |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
205 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
|
206 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
|
207 return errNoByteSlice |
643
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 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
|
210 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
211 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
212 // FromWKB deserializes a line string from WKB. |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
213 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
|
214 |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
215 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
|
216 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
217 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
|
218 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
219 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
|
220 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
221 switch { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
222 case err != nil: |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
223 return err |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
224 case endian == wkb.NDR: |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
225 order = binary.LittleEndian |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
226 case endian == wkb.XDR: |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
227 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
|
228 default: |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
229 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
|
230 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
231 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
232 var geomType uint32 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
233 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
|
234 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
235 switch { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
236 case err != nil: |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
237 return err |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
238 case geomType != wkb.LineStringZ: |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
239 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
|
240 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
241 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
242 var num uint32 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
243 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
|
244 return err |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
245 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
246 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
247 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
|
248 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
249 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
|
250 c := &coords[i] |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
251 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
|
252 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
|
253 return err |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
254 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
255 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
256 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
257 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
258 *lcz = coords |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
259 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
260 return nil |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
636
diff
changeset
|
261 } |
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
|
262 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
263 // Equals checks if two coordinates are equal. |
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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 ) |
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
|
269 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
|
270 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
|
271 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
|
272 } |
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
|
273 |
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
|
274 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
|
275 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
276 // Distance calculates the spherical distance between two coords. |
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
|
277 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
|
278 |
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
|
279 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
|
280 |
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
|
281 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
|
282 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
|
283 |
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
|
284 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
|
285 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
|
286 } |
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
|
287 |
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
|
288 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
|
289 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
|
290 } |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
291 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
292 // FromWKB deserializes a line strinf from WKB. |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
293 func (mls *GeoJSONMultiLineCoordinatesZ) FromWKB(data []byte) error { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
294 r := bytes.NewReader(data) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
295 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
296 var order binary.ByteOrder |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
297 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
298 endian, err := r.ReadByte() |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
299 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
300 switch { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
301 case err != nil: |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
302 return err |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
303 case endian == wkb.NDR: |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
304 order = binary.LittleEndian |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
305 case endian == wkb.XDR: |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
306 order = binary.BigEndian |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
307 default: |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
308 return fmt.Errorf("unknown byte order %x", endian) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
309 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
310 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
311 var geomType uint32 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
312 err = binary.Read(r, order, &geomType) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
313 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
314 switch { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
315 case err != nil: |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
316 return err |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
317 case geomType != wkb.MultiLineStringZ: |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
318 return fmt.Errorf("unknown geometry type %d", geomType) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
319 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
320 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
321 var numLines uint32 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
322 if err = binary.Read(r, order, &numLines); err != nil { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
323 return err |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
324 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
325 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
326 lines := make(GeoJSONMultiLineCoordinatesZ, numLines) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
327 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
328 for i := range lines { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
329 endian, err = r.ReadByte() |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
330 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
331 switch { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
332 case err != nil: |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
333 return err |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
334 case endian == wkb.NDR: |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
335 order = binary.LittleEndian |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
336 case endian == wkb.XDR: |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
337 order = binary.BigEndian |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
338 default: |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
339 return fmt.Errorf("unknown byte order %x", endian) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
340 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
341 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
342 err = binary.Read(r, order, &geomType) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
343 switch { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
344 case err != nil: |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
345 return err |
2471
63475c8e710e
Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1683
diff
changeset
|
346 case geomType != wkb.LineStringZ: |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
347 return fmt.Errorf("unknown geometry type %d", geomType) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
348 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
349 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
350 var numPoints uint32 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
351 if err = binary.Read(r, order, &numPoints); err != nil { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
352 return err |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
353 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
354 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
355 points := make(GeoJSONLineCoordinatesZ, numPoints) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
356 for j := range points { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
357 var lat, lon, z uint64 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
358 if err = binary.Read(r, order, &lat); err != nil { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
359 return err |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
360 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
361 if err = binary.Read(r, order, &lon); err != nil { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
362 return err |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
363 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
364 if err = binary.Read(r, order, &z); err != nil { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
365 return err |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
366 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
367 c := &points[j] |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
368 c.Lat = math.Float64frombits(lat) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
369 c.Lon = math.Float64frombits(lon) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
370 c.Z = math.Float64frombits(z) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
371 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
372 lines[i] = points |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
373 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
374 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
375 *mls = lines |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
376 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
377 return nil |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
378 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
379 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4847
diff
changeset
|
380 // Scan implements the sql.Scanner interface. |
5712
6270951dda28
/interface{}/any/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5601
diff
changeset
|
381 func (mls *GeoJSONMultiLineCoordinatesZ) Scan(src any) error { |
895
3bb275235c89
Let GeoJSONMultiLineCoordinatesZ be nil when scanned from DB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
808
diff
changeset
|
382 if src == nil { |
3bb275235c89
Let GeoJSONMultiLineCoordinatesZ be nil when scanned from DB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
808
diff
changeset
|
383 return nil |
3bb275235c89
Let GeoJSONMultiLineCoordinatesZ be nil when scanned from DB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
808
diff
changeset
|
384 } |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
385 data, ok := src.([]byte) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
386 if !ok { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
387 return errNoByteSlice |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
388 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
389 return mls.FromWKB(data) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
390 } |