annotate client/src/application/lib/geo.js @ 1020:e89be4af3a9f

restructure surveyrequest
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 24 Oct 2018 10:56:41 +0200
parents ca628dce90dd
children dd67e46366ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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";
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
25
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
26 const EARTHRADIUS = 6378137.0;
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
27
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
28 /**
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
29 * Converts to radiant
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
30 * @param {degree} d
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
31 */
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
32 const deg2rad = d => {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
33 return (d * Math.PI) / 180.0;
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
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
36 /**
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
37 * 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
38 *
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
39 * 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
40 *
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
41 * @param {object} P1
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
42 * @param {object} P2
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
43 */
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
44 const distanceBetween = (P1, P2) => {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
45 const dLat = deg2rad(P2.lat - P1.lat);
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
46 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
47 if (dLng > Math.PI) {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
48 dLng = 2 * Math.PI - dLng;
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 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
51 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
52 };
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
53
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
54 /**
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
55 * 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
56 * an object with according attributes
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
57 * {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
58 * lat: $lat,
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
59 * lon: $lon,
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
60 * alt: $alt
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
61 * }
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
62 *
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
63 * @param {array} coords
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
64 */
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
65 const Point = coords => {
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
66 return {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
67 lon: coords[0],
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
68 lat: coords[1],
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
69 alt: coords[2]
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
70 };
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
71 };
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
72
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
73 /**
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
74 * 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
75 * given coordinates into points representing
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
76 * distance from startpoint / altitude information
666
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 * a) extracting the minimum altitude
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
79 * b) extracting the maximum altitude
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
80 * 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
81 * 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
82 *
677
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
83 * 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
84 *
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
85 * 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
86 *
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
87 * 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
88 * to the total
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
89 *
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
90 * @param {object} geoJSON, startPoint, endPoint
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
91 */
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
92 const transform = ({ geoJSON, startPoint, endPoint }) => {
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
93 const lineSegments = geoJSON.geometry.coordinates;
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
94 let segmentPoints = [];
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
95 let lengthPolyLine = 0;
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
96 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
97 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
98 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
99 let currentPoint = null;
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
100 for (let segment of lineSegments) {
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
101 let points = [];
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
102 for (let coordinateTriplet of segment) {
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
103 currentPoint = Point(coordinateTriplet);
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
104 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
105 let y = Math.abs(currentPoint.alt);
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
106 points.push({
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
107 x: lengthPolyLine,
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
108 y: y
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
109 });
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
110 if (y < minAlt) minAlt = y;
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
111 if (y > maxAlt) maxAlt = y;
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
112 referencePoint = currentPoint;
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
113 }
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
114 segmentPoints.push(points);
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
115 }
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
116 lengthPolyLine += distanceBetween(currentPoint, Point(endPoint));
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
117 return { segmentPoints, lengthPolyLine, minAlt, maxAlt };
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
118 };
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
119
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
120 /**
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
121 * 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
122 * a MultiLineString, e.g.
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
123 *
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 * type: "Feature",
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
126 * geometry: {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
127 * type: "MultiLineString",
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
128 * coordinates: [
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 * [16.53593398, 48.14694085, -146.52392755]
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
131 * ...
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
132 * ]]
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
133 *
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
134 * 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
135 * 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
136 *
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 * { points:
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 * [ { x: 0.005798201616417183, y: -146.52419461 },
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
141 * { x: 0, y: -146.52394016 }
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 * ]
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
145 * lengthPolyLine: 160.06814078495722,
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
146 * minAlt: -146.73122231,
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
147 * maxAlt: -145.65155866
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 * @param {object} geoJSON
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
151 */
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
152 const prepareProfile = ({ geoJSON, startPoint, endPoint }) => {
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
153 const { segmentPoints, lengthPolyLine, minAlt, maxAlt } = transform({
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
154 geoJSON,
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
155 startPoint,
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
156 endPoint
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
157 });
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
158 return {
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
159 points: segmentPoints,
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
160 lengthPolyLine: lengthPolyLine,
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
161 minAlt: minAlt,
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
162 maxAlt: maxAlt
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
163 };
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
164 };
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
165
1020
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
166 const generateFeatureRequest = (profileLine, survey) => {
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
167 const feature = new Feature({
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
168 geometry: profileLine,
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
169 bottleneck: survey.bottleneck_id,
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
170 date: survey.date_info
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
171 });
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
172 return new GeoJSON({ geometryName: "geometry" }).writeFeature(feature);
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
173 };
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
174
e89be4af3a9f restructure surveyrequest
Thomas Junk <thomas.junk@intevation.de>
parents: 1019
diff changeset
175 export { generateFeatureRequest, prepareProfile };