Mercurial > gemma
annotate pkg/controllers/cross.go @ 792:ce23a4192788
Removed dead code.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 27 Sep 2018 09:55:25 +0200 |
parents | bb0788567609 |
children |
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 controllers |
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 ( |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 "database/sql" |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
5 "log" |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 "net/http" |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
7 "time" |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 "gemma.intevation.de/gemma/pkg/models" |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 ) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
12 const crossSQL = ` |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
13 WITH line AS ( |
717
bb0788567609
Merge output of ST_3DIntersection into a single linestring
Tom Gottfried <tom@intevation.de>
parents:
658
diff
changeset
|
14 SELECT ST_LineMerge(ST_Union(ST_3DIntersection( |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
15 ST_Translate( |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
16 ST_Extrude( |
645
794592cad75a
Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
643
diff
changeset
|
17 ST_GeomFromWKB($1, 4326), |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
18 0, 0, 1000), |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
19 0, 0, -500), |
717
bb0788567609
Merge output of ST_3DIntersection into a single linestring
Tom Gottfried <tom@intevation.de>
parents:
658
diff
changeset
|
20 geom))) AS geom |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
21 FROM waterway.meshes m JOIN waterway.sounding_results sr ON m.sounding_result_id = sr.id |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
22 WHERE ST_Intersects(geom, ST_GeomFromWKB($1, 4326)) AND |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
23 sr.bottleneck_id = $2 AND sr.date_info = $3 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
24 ) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
25 SELECT ST_AsBinary((ST_Dump(ST_Intersection(line.geom, sr.area::geometry))).geom) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
26 FROM line, waterway.sounding_results sr |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
27 WHERE sr.bottleneck_id = $2 AND sr.date_info = $3 |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
28 ` |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
29 |
633
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 func crossSection( |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 input interface{}, |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
32 req *http.Request, |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 db *sql.Conn, |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 ) (jr JSONResult, err error) { |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
35 |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 csi := input.(*models.CrossSectionInput) |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
38 start := time.Now() |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
39 |
658
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
40 var rows *sql.Rows |
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
41 if rows, err = db.QueryContext( |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
42 req.Context(), |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
43 crossSQL, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
44 csi.Geometry.Coordinates.AsWKB(), |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
45 csi.Properties.Bottleneck, |
658
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
46 csi.Properties.Date.Time, |
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
47 ); err != nil { |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
48 return |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
49 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
50 defer rows.Close() |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
51 |
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
|
52 var segments models.GeoJSONMultiLineCoordinatesZ |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
53 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
54 for rows.Next() { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
55 var segment models.GeoJSONLineCoordinatesZ |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
56 if err = rows.Scan(&segment); err != nil { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
57 return |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
58 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
59 segments = append(segments, segment) |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
60 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
61 |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
62 if err = rows.Err(); err != nil { |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
63 return |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
64 } |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
65 |
658
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
66 log.Printf("query took: %v\n", time.Since(start)) |
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
67 |
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
68 start = time.Now() |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
69 |
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
|
70 joined := segments.Join() |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
71 |
658
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
72 log.Printf("joining took: %v\n", time.Since(start)) |
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
73 log.Printf("segments before/after: %d %d\n", len(segments), len(joined)) |
288c496eca26
Cross sections: Simplified joining segments code a bit and moved timing into controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
654
diff
changeset
|
74 |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
75 /* |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
76 if err2 := dumpProfile( |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
77 csi.Geometry.Coordinates[0], |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
78 csi.Geometry.Coordinates[len(csi.Geometry.Coordinates)-1], |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
79 joined, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
80 ); err2 != nil { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
81 log.Printf("error: %v\n", err2) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
82 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
83 */ |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
84 |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
85 jr = JSONResult{ |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
86 Result: &models.CrossSectionOutput{ |
653
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
87 Type: "Feature", |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
88 Geometry: models.CrossSectionOutputGeometry{ |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
89 Type: "MultiLineString", |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
90 Coordinates: joined, |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
91 }, |
7aeacd7f150b
Cross sections: Take and produce valid GeoJSON.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
648
diff
changeset
|
92 Properties: map[string]interface{}{}, |
643
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
93 }, |
756f3fc62da6
Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
94 } |
633
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 return |
6093016fac88
Cross sections: started with implementation of web service (WIP).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
654
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
98 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
99 /* |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
100 func dumpProfile( |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
101 start models.GeoJSONCoordinate, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
102 stop models.GeoJSONCoordinate, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
103 segments models.GeoJSONMultiLineCoordinatesZ, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
104 ) error { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
105 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
106 w, err := os.Create("/tmp/cross.txt") |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
107 if err != nil { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
108 return err |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
109 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
110 defer w.Close() |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
111 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
112 begin := models.GeoJSONCoordinateZ{ |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
113 Lat: start.Lat, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
114 Lon: start.Lon, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
115 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
116 end := models.GeoJSONCoordinateZ{ |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
117 Lat: stop.Lat, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
118 Lon: stop.Lon, |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
119 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
120 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
121 last := begin |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
122 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
123 var total float64 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
124 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
125 minz := 10000.0 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
126 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
127 for _, line := range segments { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
128 for _, coord := range line { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
129 if coord.Z < minz { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
130 minz = coord.Z |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
131 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
132 total += last.Distance(coord) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
133 last = coord |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
134 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
135 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
136 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
137 log.Printf("length: %.3f minz: %f\n", total, minz) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
138 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
139 var pos float64 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
140 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
141 for i, line := range segments { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
142 for j, coord := range line { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
143 if i == 0 && j == 0 { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
144 if !begin.Equals(coord) { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
145 pos = begin.Distance(coord) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
146 fmt.Fprintf(w, "%.3f %f\n", 0.0, 200.0) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
147 fmt.Fprintf(w, "%.3f %f\n", pos-0.0001, 200.0) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
148 fmt.Fprintf(w, "%.3f %f\n", pos, coord.Z-minz) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
149 continue |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
150 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
151 } else if j == 0 { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
152 fmt.Fprintf(w, "%.3f %f\n", pos+0.0001, 200.0) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
153 fmt.Fprintf(w, "%.3f %f\n", pos+last.Distance(coord)-0.0001, 200.0) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
154 continue |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
155 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
156 pos += last.Distance(coord) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
157 fmt.Fprintf(w, "%.3f %f\n", pos, coord.Z-minz) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
158 last = coord |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
159 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
160 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
161 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
162 if !last.Equals(end) { |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
163 fmt.Fprintf(w, "%.3f %f\n", pos+0.0001, 200.0) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
164 fmt.Fprintf(w, "%.3f %f\n", pos+last.Distance(end), 200.0) |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
165 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
166 |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
167 return nil |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
168 } |
baa31814717c
Cross sections: Commit data model for fast cross section calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
653
diff
changeset
|
169 */ |