changeset 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 c1baaff348b0
children dedf252b3e01
files pkg/controllers/octreecross.go
diffstat 1 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/octreecross.go	Tue Sep 25 16:25:42 2018 +0200
+++ b/pkg/controllers/octreecross.go	Tue Sep 25 16:35:38 2018 +0200
@@ -11,6 +11,8 @@
 	"gemma.intevation.de/gemma/pkg/octree"
 )
 
+const WGS84 = 4326
+
 func reproject(
 	rp *models.Reprojector,
 	src models.GeoJSONLineCoordinates,
@@ -34,9 +36,22 @@
 	lines octree.MultiLineStringZ,
 	ctx context.Context,
 ) (models.GeoJSONMultiLineCoordinatesZ, error) {
-	// TODO: Implement me!
-	log.Println("projectBack is not implemented, yet!")
-	return nil, nil
+
+	out := make(models.GeoJSONMultiLineCoordinatesZ, len(lines))
+
+	for i, segment := range lines {
+
+		coords := make(models.GeoJSONLineCoordinatesZ, len(segment))
+		out[i] = coords
+		for j, v := range segment {
+			lat, lon, err := rp.Reproject(v.X, v.Y, ctx)
+			if err != nil {
+				return nil, err
+			}
+			coords[j] = models.GeoJSONCoordinateZ{Lat: lat, Lon: lon, Z: v.Z}
+		}
+	}
+	return out, nil
 }
 
 func octreeCrossSection(
@@ -67,7 +82,7 @@
 	var rp *models.Reprojector
 	if rp, err = models.NewReprojector(
 		conn, req.Context(),
-		4326, tree.EPSG,
+		WGS84, tree.EPSG,
 	); err != nil {
 		return
 	}
@@ -104,8 +119,12 @@
 
 	}
 	log.Printf("octree traversal took: %s\n", time.Since(start))
+
+	// The result have to be WGS84. So project the result back.
 	start = time.Now()
 
+	rp.FromEPSG, rp.ToEPSG = tree.EPSG, WGS84
+
 	var joined models.GeoJSONMultiLineCoordinatesZ
 	joined, err = projectBack(rp, segments, req.Context())