Mercurial > gemma
annotate client/src/application/lib/geo.js @ 1046:d5d72756645a
additional surveys not implemented infobox
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 25 Oct 2018 10:53:36 +0200 |
parents | 1fdeb9404afb |
children |
rev | line source |
---|---|
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
1 /* |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
2 * This is Free Software under GNU Affero General Public License v >= 3.0 |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
3 * without warranty, see README.md and license for details. |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
4 * |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
5 * SPDX-License-Identifier: AGPL-3.0-or-later |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
6 * License-Filename: LICENSES/AGPL-3.0.txt |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
7 * |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
8 * Copyright (C) 2018 by via donau |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
9 * – Österreichische Wasserstraßen-Gesellschaft mbH |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
10 * Software engineering by Intevation GmbH |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
11 * |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
12 * Author(s): |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
13 * Thomas Junk <thomas.junk@intevation.de> |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
14 */ |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
767
diff
changeset
|
15 |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
16 /** |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
17 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
18 * Distance calculations |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
19 * JS transposition of cross.go functions |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
20 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
21 */ |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
22 |
1020
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
23 import { GeoJSON } from "ol/format.js"; |
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
24 import Feature from "ol/Feature"; |
1029
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
25 import distance from "@turf/distance"; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
26 import { |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
27 lineString as turfLineString, |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
28 polygon as turfPolygon |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
29 } from "@turf/helpers"; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
30 import lineIntersect from "@turf/line-intersect"; |
1020
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
31 |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
32 const EARTHRADIUS = 6378137.0; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
33 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
34 /** |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
35 * Converts to radiant |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
36 * @param {degree} d |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
37 */ |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
38 const deg2rad = d => { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
39 return (d * Math.PI) / 180.0; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
40 }; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
41 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
42 /** |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
43 * Calculates the difference between two points in m |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
44 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
45 * Points are given with {lat: $lat, lon: $lon} |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
46 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
47 * @param {object} P1 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
48 * @param {object} P2 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
49 */ |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
50 const distanceBetween = (P1, P2) => { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
51 const dLat = deg2rad(P2.lat - P1.lat); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
52 let dLng = Math.abs(deg2rad(P2.lon - P1.lon)); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
53 if (dLng > Math.PI) { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
54 dLng = 2 * Math.PI - dLng; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
55 } |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
56 const x = dLng * Math.cos(deg2rad((P1.lat + P2.lat) / 2.0)); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
57 return Math.sqrt(dLat * dLat + x * x) * EARTHRADIUS; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
58 }; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
59 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
60 /** |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
61 * Takes a triple of [lat, long, alt] and generates |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
62 * an object with according attributes |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
63 * { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
64 * lat: $lat, |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
65 * lon: $lon, |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
66 * alt: $alt |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
67 * } |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
68 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
69 * @param {array} coords |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
70 */ |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
71 const Point = coords => { |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
72 return { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
73 lon: coords[0], |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
74 lat: coords[1], |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
75 alt: coords[2] |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
76 }; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
77 }; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
78 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
79 /** |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
80 * Has geoJSON as its input and transforms |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
81 * given coordinates into points representing |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
82 * distance from startpoint / altitude information |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
83 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
84 * a) extracting the minimum altitude |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
85 * b) extracting the maximum altitude |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
86 * c) calculating the total length of the given profile |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
87 * d) transposes the datapoints relative to a given start point |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
88 * |
677
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
89 * The calculation of total equals the sum of partial distances between points |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
90 * |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
91 * The x-value of a point is equal to the total distance up to this point |
677
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
92 * |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
93 * The distance between the last point of the last segment and the end point is added |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
94 * to the total |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
95 * |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
96 * @param {object} geoJSON, startPoint, endPoint |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
97 */ |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
98 const transform = ({ geoJSON, startPoint, endPoint }) => { |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
99 const lineSegments = geoJSON.geometry.coordinates; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
100 let segmentPoints = []; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
101 let lengthPolyLine = 0; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
102 let referencePoint = Point(startPoint); |
767
dedf252b3e01
feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
103 let minAlt = Math.abs(lineSegments[0][0][2]); |
dedf252b3e01
feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
104 let maxAlt = Math.abs(lineSegments[0][0][2]); |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
105 let currentPoint = null; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
106 for (let segment of lineSegments) { |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
107 let points = []; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
108 for (let coordinateTriplet of segment) { |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
109 currentPoint = Point(coordinateTriplet); |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
110 lengthPolyLine += distanceBetween(referencePoint, currentPoint); |
767
dedf252b3e01
feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
111 let y = Math.abs(currentPoint.alt); |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
112 points.push({ |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
113 x: lengthPolyLine, |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
114 y: y |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
115 }); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
116 if (y < minAlt) minAlt = y; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
117 if (y > maxAlt) maxAlt = y; |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
118 referencePoint = currentPoint; |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
119 } |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
120 segmentPoints.push(points); |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
121 } |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
122 lengthPolyLine += distanceBetween(currentPoint, Point(endPoint)); |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
123 return { segmentPoints, lengthPolyLine, minAlt, maxAlt }; |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
124 }; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
125 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
126 /** |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
127 * Prepare profile takes geoJSON data in form of |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
128 * a MultiLineString, e.g. |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
129 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
130 * { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
131 * type: "Feature", |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
132 * geometry: { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
133 * type: "MultiLineString", |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
134 * coordinates: [ |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
135 * [ |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
136 * [16.53593398, 48.14694085, -146.52392755] |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
137 * ... |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
138 * ]] |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
139 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
140 * and transforms it to a structure representing the number of sections |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
141 * where data is present with according lengths and the points |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
142 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
143 * { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
144 * { points: |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
145 * [ |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
146 * [ { x: 0.005798201616417183, y: -146.52419461 }, |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
147 * { x: 0, y: -146.52394016 } |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
148 * ... |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
149 * ] |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
150 * ] |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
151 * lengthPolyLine: 160.06814078495722, |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
152 * minAlt: -146.73122231, |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
153 * maxAlt: -145.65155866 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
154 * } |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
155 * |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
156 * @param {object} geoJSON |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
157 */ |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
158 const prepareProfile = ({ geoJSON, startPoint, endPoint }) => { |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
159 const { segmentPoints, lengthPolyLine, minAlt, maxAlt } = transform({ |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
160 geoJSON, |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
161 startPoint, |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
162 endPoint |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
163 }); |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
164 return { |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
165 points: segmentPoints, |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
166 lengthPolyLine: lengthPolyLine, |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
167 minAlt: minAlt, |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
168 maxAlt: maxAlt |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
169 }; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
170 }; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
171 |
1028
dd67e46366ef
refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents:
1020
diff
changeset
|
172 const generateFeatureRequest = (profileLine, bottleneck_id, date_info) => { |
1020
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
173 const feature = new Feature({ |
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
174 geometry: profileLine, |
1028
dd67e46366ef
refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents:
1020
diff
changeset
|
175 bottleneck: bottleneck_id, |
dd67e46366ef
refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents:
1020
diff
changeset
|
176 date: date_info |
1020
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
177 }); |
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
178 return new GeoJSON({ geometryName: "geometry" }).writeFeature(feature); |
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
179 }; |
e89be4af3a9f
restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents:
1019
diff
changeset
|
180 |
1029
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
181 const calculateFairwayCoordinates = (profileLine, fairwayGeometry, depth) => { |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
182 // both geometries have to be in EPSG:4326 |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
183 // uses turfjs distance() function |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
184 let fairwayCoordinates = []; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
185 var line = turfLineString(profileLine.getCoordinates()); |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
186 var polygon = turfPolygon(fairwayGeometry.getCoordinates()); |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
187 var intersects = lineIntersect(line, polygon); |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
188 var l = intersects.features.length; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
189 if (l % 2 != 0) { |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
190 console.log("Ignoring fairway because profile only intersects once."); |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
191 } else { |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
192 for (let i = 0; i < l; i += 2) { |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
193 let pStartPoint = profileLine.getCoordinates()[0]; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
194 let fStartPoint = intersects.features[i].geometry.coordinates; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
195 let fEndPoint = intersects.features[i + 1].geometry.coordinates; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
196 let opts = { units: "kilometers" }; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
197 |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
198 fairwayCoordinates.push([ |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
199 distance(pStartPoint, fStartPoint, opts) * 1000, |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
200 distance(pStartPoint, fEndPoint, opts) * 1000, |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
201 depth |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
202 ]); |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
203 } |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
204 } |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
205 return fairwayCoordinates; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
206 }; |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
207 |
1fdeb9404afb
refac: extract calculation of fairway coordinates
Thomas Junk <thomas.junk@intevation.de>
parents:
1028
diff
changeset
|
208 export { generateFeatureRequest, prepareProfile, calculateFairwayCoordinates }; |