annotate pkg/models/cross.go @ 658:288c496eca26

Cross sections: Simplified joining segments code a bit and moved timing into controller.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 14 Sep 2018 18:02:53 +0200
parents 7aeacd7f150b
children bd215c4325ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 package models
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 import (
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"
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
10 "sort"
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 "time"
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
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14 type (
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 GeoJSONFeature string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16 GeoJSONLineStringType string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18 GeoJSONDate struct{ time.Time }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 GeoJSONLineString struct {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 Type GeoJSONLineStringType `json:"type"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 GeoJSONCoordinate struct {
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
25 Lat float64
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 Lon float64
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
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
29 GeoJSONCoordinateZ struct {
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
30 Lat float64
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
31 Lon float64
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
32 Z float64
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
33 }
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
34
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 CrossSectionInputProperties struct {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36 Bottleneck string `json:"bottleneck"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 Date GeoJSONDate `json:"date"`
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
40 GeoJSONLineCoordinates []GeoJSONCoordinate
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
41 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
42
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
43 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
44
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
45 CrossSectionInputGeometry struct {
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
46 Type GeoJSONLineStringType `json:"type"`
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
47 Coordinates GeoJSONLineCoordinates `json:"coordinates"`
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
48 }
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
49
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 CrossSectionInput struct {
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
51 Type GeoJSONFeature `json:"type"`
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
52 Geometry CrossSectionInputGeometry `json:"geometry"`
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
53 Properties CrossSectionInputProperties `json:"properties"`
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
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
56 CrossSectionOutputGeometry struct {
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
57 Type string `json:"type"`
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
58 Coordinates GeoJSONMultiLineCoordinatesZ `json:"coordinates"`
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
59 }
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
60
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
61 CrossSectionOutput struct {
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
62 Type string `json:"type"`
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
63 Geometry CrossSectionOutputGeometry `json:"geometry"`
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
64 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
65 }
633
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
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 var (
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 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
70 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
71 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
72 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
73 )
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74
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
75 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
76 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
77 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
78 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
79 }
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 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
81 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
82 }
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 *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
84 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
85 }
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
86
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
87 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
88 var s string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89 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
90 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 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
93 if err != nil {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96 *d = GeoJSONDate{t}
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97 return nil
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
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100 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
101 var pos []float64
633
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102 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
103 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104 }
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
105 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
106 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
107 }
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
108 *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
109 return nil
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
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 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
113 var s string
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
114 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
115 return err
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
116 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
117 if s != "Feature" {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
118 return errNoGeoJSONFeature
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
119 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
120 *t = GeoJSONFeature(s)
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
121 return nil
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
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
124 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
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 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
129 if s != "LineString" {
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
130 return errNoGeoJSONLineStringType
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
131 }
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
132 *t = GeoJSONLineStringType(s)
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
133 return nil
6093016fac88 Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
134 }
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
135
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
136 const (
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
137 wkbXDR byte = 0
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
138 wkbNDR byte = 1
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
139 wkbPoint uint32 = 1
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
140 wkbPointZ uint32 = 1000 + 1
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
141 wkbLineString uint32 = 2
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
142 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
143 )
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
144
645
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
145 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
146
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
147 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
148
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
149 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
150
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
151 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
152 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
153 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
154
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
155 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
156 c := &lc[i]
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
157 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
158 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
159 }
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
160
645
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
161 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
162 }
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
163
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
164 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
165 var buf bytes.Buffer
653
7aeacd7f150b Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 652
diff changeset
166 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
167 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
168 }
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
169
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
170 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
171 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
172 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
173 return errNoByteSlice
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
174 }
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
175 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
176 }
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
177
645
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
178 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
179
645
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
180 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
181
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
182 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
183
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
184 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
185
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
186 switch {
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
187 case err != nil:
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
188 return err
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
189 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
190 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
191 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
192 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
193 default:
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
194 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
195 }
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 var geomType uint32
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
198 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
199
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
200 switch {
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
201 case err != nil:
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
202 return err
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
203 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
204 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
205 }
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
206
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
207 var num uint32
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
208 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
209 return err
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
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
212 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
213
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
214 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
215 c := &coords[i]
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
216 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
217 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
218 return err
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 }
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
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
223 *lcz = coords
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
224
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
225 return nil
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 636
diff changeset
226 }
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
227
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
228 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
229 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
230 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
231 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
232 )
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
233 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
234 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
235 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
236 }
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
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 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
239 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
240 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
241 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
242 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
243 }
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
244 }
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
245
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
246 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
247
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 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
249
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 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
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 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
253 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
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 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
256 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
257 }
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
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
259 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
260 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
261 }
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
262
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
263 func (cz GeoJSONCoordinateZ) quant() GeoJSONCoordinateZ {
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
264 const (
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
265 xyScale = 1e6
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
266 zScale = 1e5
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
267 )
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
268 return GeoJSONCoordinateZ{
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
269 Lon: math.Round(cz.Lon*xyScale) / xyScale,
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
270 Lat: math.Round(cz.Lat*xyScale) / xyScale,
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
271 Z: math.Round(cz.Z*zScale) / zScale,
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
272 }
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
273 }
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
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 func (lcz GeoJSONLineCoordinatesZ) join(other GeoJSONLineCoordinatesZ) GeoJSONLineCoordinatesZ {
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
276 l1, l2 := len(lcz), len(other)
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 n := make(GeoJSONLineCoordinatesZ, l1+l2-1)
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 copy(n, lcz[:l1-1])
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 n[l1-1] = lcz[l1-1].mid(other[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 copy(n[l1:], other[1:])
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 return n
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 }
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 func (ml GeoJSONMultiLineCoordinatesZ) Join() GeoJSONMultiLineCoordinatesZ {
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
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 if len(ml) < 2 {
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 return ml
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 }
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
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 type value struct {
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
291 coords GeoJSONLineCoordinatesZ
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
292 order int
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
293 }
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
294
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
295 heads := make(map[GeoJSONCoordinateZ]*value)
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
296
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
297 for i, coords := range ml {
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
298 key := coords[len(coords)-1].quant()
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
299 if v := heads[key]; v != nil {
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
300 delete(heads, key)
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
301 v.coords = coords.join(v.coords)
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
302 heads[v.coords[0].quant()] = v
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
303 } else {
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
304 heads[coords[0].quant()] = &value{coords, i}
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
305 }
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
306 }
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
307
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
308 again:
658
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
309 for k, v1 := range heads {
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
310 key := v1.coords[len(v1.coords)-1].quant()
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
311 if k == key { // cycle detected
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
312 continue
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
313 }
658
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
314 if v2 := heads[key]; v2 != nil {
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
315 delete(heads, key)
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
316 v1.coords = v1.coords.join(v2.coords)
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
317 goto again
288c496eca26 Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 653
diff changeset
318 }
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
319 }
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
320
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
321 // To make it deterministic sort in input order.
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
322 tmp := make([]*value, len(heads))
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
323 var i int
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
324 for _, v := range heads {
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
325 tmp[i] = v
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
326 i++
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
327 }
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
328 sort.Slice(tmp, func(i, j int) bool { return tmp[i].order < tmp[j].order })
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
329
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
330 out := make(GeoJSONMultiLineCoordinatesZ, len(tmp))
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
331 for i, v := range tmp {
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
332 out[i] = v.coords
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
333 }
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
334
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
335 return out
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
336 }
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
337
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
338 /*
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
339 func (ml GeoJSONMultiLineCoordinatesZ) Join() GeoJSONMultiLineCoordinatesZ {
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
340
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
341 if len(ml) < 2 {
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
342 return ml
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
343 }
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
344
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
345 lists := make(GeoJSONMultiLineCoordinatesZ, len(ml))
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
346 copy(lists, ml)
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
347
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
348 next:
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
349 for j := 0; j < len(lists); {
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
350 front := lists[j]
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
351 tail := front[len(front)-1]
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
352
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
353 for i := 0; i < len(lists); i++ {
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
354 if i == j {
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
355 continue
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
356 }
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
357 curr := lists[i]
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
358 head := curr[0]
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
359 if tail.Equals(head) {
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
360 n := make(GeoJSONLineCoordinatesZ, len(front)+len(curr)-1)
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
361 copy(n, front[:len(front)-1])
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
362 n[len(front)-1] = head.mid(tail)
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
363 copy(n[len(front):], curr[1:])
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
364 lists[j] = n
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
365 if i < len(lists)-1 {
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
366 copy(lists[i:], lists[i+1:])
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
367 }
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
368 lists[len(lists)-1] = nil
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
369 lists = lists[:len(lists)-1]
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
370 continue next
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
371 }
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
372 }
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
373 j++
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
374 }
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
375
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
376 return lists
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
377 }
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
378 */