# HG changeset patch # User Sascha L. Teichmann # Date 1537873893 -7200 # Node ID d05bc3e3433884c291ffdf411a12cd7b8e018f4c # Parent 01ba06da8f462622f0b31686540a75aae3d56a7e More infrastructure for the octree driven cross section endpoint. diff -r 01ba06da8f46 -r d05bc3e34338 pkg/controllers/octreecross.go --- a/pkg/controllers/octreecross.go Tue Sep 25 10:35:17 2018 +0200 +++ b/pkg/controllers/octreecross.go Tue Sep 25 13:11:33 2018 +0200 @@ -29,6 +29,16 @@ return dst, nil } +func projectBack( + rp *models.Reprojector, + lines octree.MultiLineStringZ, + ctx context.Context, +) (models.GeoJSONMultiLineCoordinatesZ, error) { + // TODO: Implement me! + log.Println("projectBack is not implemented, yet!") + return nil, nil +} + func octreeCrossSection( input interface{}, req *http.Request, @@ -70,17 +80,49 @@ return } + start = time.Now() + + var segments octree.MultiLineStringZ + for i := 0; i < len(coords)-1; i++ { - start = time.Now() - var count int c1 := &coords[i] c2 := &coords[i+1] - tree.Vertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon, func(*octree.Triangle) { - // TODO: Do real intersection. - count++ + + var line octree.MultiLineStringZ + tree.Vertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon, func(t *octree.Triangle) { + + if ls := t.IntersectVertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon); len(ls) > 0 { + line = append(line) + } }) - log.Printf("octree traversal took: %s\n", time.Since(start)) - log.Printf("triangles to intersect: %d\n", count) + + if len(line) > 0 { + // They are all on the segment (c1.Lat, c1.Lon) - (c2.Lat, c2.Lon). + // Sort them by project them on this line. + segments = append(segments, line.JoinOnLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon)...) + } + + } + log.Printf("octree traversal took: %s\n", time.Since(start)) + start = time.Now() + + var joined models.GeoJSONMultiLineCoordinatesZ + joined, err = projectBack(rp, segments, req.Context()) + + log.Printf("projecting back took: %s\n", time.Since(start)) + if err != nil { + return + } + + jr = JSONResult{ + Result: &models.CrossSectionOutput{ + Type: "Feature", + Geometry: models.CrossSectionOutputGeometry{ + Type: "MultiLineString", + Coordinates: joined, + }, + Properties: map[string]interface{}{}, + }, } return diff -r 01ba06da8f46 -r d05bc3e34338 pkg/octree/vertex.go --- a/pkg/octree/vertex.go Tue Sep 25 10:35:17 2018 +0200 +++ b/pkg/octree/vertex.go Tue Sep 25 13:11:33 2018 +0200 @@ -4,6 +4,7 @@ "bytes" "encoding/binary" "io" + "log" "math" ) @@ -154,6 +155,18 @@ return points } +func (t *Triangle) IntersectVertical(x1, y1, x2, y2 float64) LineStringZ { + // TODO: Implement me! + log.Println("Triangle.IntersectVertical is not implemented, yet!") + return nil +} + +func (mls MultiLineStringZ) JoinOnLine(x1, y1, x2, y2 float64) MultiLineStringZ { + // TODO: Implement me! + log.Println("MultiLineStringZ.JoinOnLine is not implemented, yet!") + return mls +} + func (v *Vertex) Write(w io.Writer) error { if err := binary.Write( w, binary.LittleEndian, math.Float64bits(v.X)); err != nil {