changeset 653:7aeacd7f150b

Cross sections: Take and produce valid GeoJSON.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 14 Sep 2018 12:01:45 +0200
parents f5ecd1d72a6e
children baa31814717c
files pkg/controllers/cross.go pkg/models/cross.go
diffstat 2 files changed, 28 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/cross.go	Fri Sep 14 11:44:27 2018 +0200
+++ b/pkg/controllers/cross.go	Fri Sep 14 12:01:45 2018 +0200
@@ -35,7 +35,7 @@
 	var rows *sql.Rows
 
 	rows, err = db.QueryContext(
-		req.Context(), crossSQL, csi.Coordinates.AsWKB())
+		req.Context(), crossSQL, csi.Geometry.Coordinates.AsWKB())
 	if err != nil {
 		return
 	}
@@ -59,9 +59,12 @@
 
 	jr = JSONResult{
 		Result: &models.CrossSectionOutput{
-			Type:        "Feature",
-			Geometry:    "MultLineString",
-			Coordinates: joined,
+			Type: "Feature",
+			Geometry: models.CrossSectionOutputGeometry{
+				Type:        "MultiLineString",
+				Coordinates: joined,
+			},
+			Properties: map[string]interface{}{},
 		},
 	}
 
--- a/pkg/models/cross.go	Fri Sep 14 11:44:27 2018 +0200
+++ b/pkg/models/cross.go	Fri Sep 14 12:01:45 2018 +0200
@@ -23,13 +23,13 @@
 	}
 
 	GeoJSONCoordinate struct {
+		Lat float64
 		Lon float64
-		Lat float64
 	}
 
 	GeoJSONCoordinateZ struct {
+		Lat float64
 		Lon float64
-		Lat float64
 		Z   float64
 	}
 
@@ -43,17 +43,26 @@
 
 	GeoJSONMultiLineCoordinatesZ []GeoJSONLineCoordinatesZ
 
+	CrossSectionInputGeometry struct {
+		Type        GeoJSONLineStringType  `json:"type"`
+		Coordinates GeoJSONLineCoordinates `json:"coordinates"`
+	}
+
 	CrossSectionInput struct {
-		Type        GeoJSONFeature              `json:"type"`
-		Geometry    GeoJSONLineStringType       `json:"geometry"`
-		Coordinates GeoJSONLineCoordinates      `json:"coordinates"`
-		Properties  CrossSectionInputProperties `json:"properties"`
+		Type       GeoJSONFeature              `json:"type"`
+		Geometry   CrossSectionInputGeometry   `json:"geometry"`
+		Properties CrossSectionInputProperties `json:"properties"`
+	}
+
+	CrossSectionOutputGeometry struct {
+		Type        string                       `json:"type"`
+		Coordinates GeoJSONMultiLineCoordinatesZ `json:"coordinates"`
 	}
 
 	CrossSectionOutput struct {
-		Type        string                       `json:"type"`
-		Geometry    string                       `json:"geometry"`
-		Coordinates GeoJSONMultiLineCoordinatesZ `json:"coordinates"`
+		Type       string                     `json:"type"`
+		Geometry   CrossSectionOutputGeometry `json:"geometry"`
+		Properties map[string]interface{}     `json:"properties"`
 	}
 )
 
@@ -97,7 +106,7 @@
 	if len(pos) < 2 {
 		return errTooLessComponents
 	}
-	*c = GeoJSONCoordinate{Lon: pos[0], Lat: pos[1]}
+	*c = GeoJSONCoordinate{Lat: pos[0], Lon: pos[1]}
 	return nil
 }
 
@@ -146,8 +155,8 @@
 
 	for i := range lc {
 		c := &lc[i]
+		binary.Write(buf, binary.LittleEndian, math.Float64bits(c.Lat))
 		binary.Write(buf, binary.LittleEndian, math.Float64bits(c.Lon))
-		binary.Write(buf, binary.LittleEndian, math.Float64bits(c.Lat))
 	}
 
 	return buf.Bytes()
@@ -155,7 +164,7 @@
 
 func (cz GeoJSONCoordinateZ) MarshalJSON() ([]byte, error) {
 	var buf bytes.Buffer
-	fmt.Fprintf(&buf, "[%.8f,%.8f,%.8f]", cz.Lon, cz.Lat, cz.Z)
+	fmt.Fprintf(&buf, "[%.8f,%.8f,%.8f]", cz.Lat, cz.Lon, cz.Z)
 	return buf.Bytes(), nil
 }