Mercurial > gemma
comparison pkg/controllers/octreecross.go @ 766:afc635ab9f5b
Project the result data of the cross sections which are calculated in UTM back to WGS84.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 25 Sep 2018 16:35:38 +0200 |
parents | d05bc3e34338 |
children | 3d927e06b92c |
comparison
equal
deleted
inserted
replaced
765:c1baaff348b0 | 766:afc635ab9f5b |
---|---|
8 "time" | 8 "time" |
9 | 9 |
10 "gemma.intevation.de/gemma/pkg/models" | 10 "gemma.intevation.de/gemma/pkg/models" |
11 "gemma.intevation.de/gemma/pkg/octree" | 11 "gemma.intevation.de/gemma/pkg/octree" |
12 ) | 12 ) |
13 | |
14 const WGS84 = 4326 | |
13 | 15 |
14 func reproject( | 16 func reproject( |
15 rp *models.Reprojector, | 17 rp *models.Reprojector, |
16 src models.GeoJSONLineCoordinates, | 18 src models.GeoJSONLineCoordinates, |
17 ctx context.Context, | 19 ctx context.Context, |
32 func projectBack( | 34 func projectBack( |
33 rp *models.Reprojector, | 35 rp *models.Reprojector, |
34 lines octree.MultiLineStringZ, | 36 lines octree.MultiLineStringZ, |
35 ctx context.Context, | 37 ctx context.Context, |
36 ) (models.GeoJSONMultiLineCoordinatesZ, error) { | 38 ) (models.GeoJSONMultiLineCoordinatesZ, error) { |
37 // TODO: Implement me! | 39 |
38 log.Println("projectBack is not implemented, yet!") | 40 out := make(models.GeoJSONMultiLineCoordinatesZ, len(lines)) |
39 return nil, nil | 41 |
42 for i, segment := range lines { | |
43 | |
44 coords := make(models.GeoJSONLineCoordinatesZ, len(segment)) | |
45 out[i] = coords | |
46 for j, v := range segment { | |
47 lat, lon, err := rp.Reproject(v.X, v.Y, ctx) | |
48 if err != nil { | |
49 return nil, err | |
50 } | |
51 coords[j] = models.GeoJSONCoordinateZ{Lat: lat, Lon: lon, Z: v.Z} | |
52 } | |
53 } | |
54 return out, nil | |
40 } | 55 } |
41 | 56 |
42 func octreeCrossSection( | 57 func octreeCrossSection( |
43 input interface{}, | 58 input interface{}, |
44 req *http.Request, | 59 req *http.Request, |
65 start = time.Now() | 80 start = time.Now() |
66 | 81 |
67 var rp *models.Reprojector | 82 var rp *models.Reprojector |
68 if rp, err = models.NewReprojector( | 83 if rp, err = models.NewReprojector( |
69 conn, req.Context(), | 84 conn, req.Context(), |
70 4326, tree.EPSG, | 85 WGS84, tree.EPSG, |
71 ); err != nil { | 86 ); err != nil { |
72 return | 87 return |
73 } | 88 } |
74 defer rp.Close() | 89 defer rp.Close() |
75 | 90 |
102 segments = append(segments, line.JoinOnLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon)...) | 117 segments = append(segments, line.JoinOnLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon)...) |
103 } | 118 } |
104 | 119 |
105 } | 120 } |
106 log.Printf("octree traversal took: %s\n", time.Since(start)) | 121 log.Printf("octree traversal took: %s\n", time.Since(start)) |
122 | |
123 // The result have to be WGS84. So project the result back. | |
107 start = time.Now() | 124 start = time.Now() |
125 | |
126 rp.FromEPSG, rp.ToEPSG = tree.EPSG, WGS84 | |
108 | 127 |
109 var joined models.GeoJSONMultiLineCoordinatesZ | 128 var joined models.GeoJSONMultiLineCoordinatesZ |
110 joined, err = projectBack(rp, segments, req.Context()) | 129 joined, err = projectBack(rp, segments, req.Context()) |
111 | 130 |
112 log.Printf("projecting back took: %s\n", time.Since(start)) | 131 log.Printf("projecting back took: %s\n", time.Since(start)) |