annotate client/tests/unit/geo/geo.spec.js @ 692:87ea9d267c2b

refac: transformation formula for diagram adjusted 1) the length of the segments of a polyline are now summed 2) each point has an x coordinate according to the length of the polyline up to this point 3) testdata were hand crafted and used as basis for plausibility checks
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 20 Sep 2018 15:12:49 +0200
parents 3605af94d1ee
children 1db1ae344087
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
1 import { prepareProfile } from "../../../src/application/lib/geo";
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
2
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
3 const geoJSON = {
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
4 type: "Feature",
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
5 geometry: {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
6 type: "MultiLineString",
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
7 coordinates: [
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
8 [
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
9 [17.216391563415527, 48.0245195664277, 123],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
10 [17.216777801513672, 48.024720482272315, 124]
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
11 ],
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
12 [
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
13 [17.218494415283203, 48.02540933065123, 125],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
14 [17.219438552856445, 48.02586855778941, 126],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
15 [17.220726013183594, 48.02647128719908, 127],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
16 [17.221627235412598, 48.026987906797494, 128],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
17 [17.222957611083984, 48.02759062311748, 129],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
18 [17.223901748657227, 48.0280785311666, 130],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
19 [17.224159240722656, 48.02819333238926, 131]
666
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 [
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
22 [17.225961685180664, 48.02891083423718, 132],
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
23 [17.227892875671383, 48.02997271864036, 133]
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
24 ]
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
25 ]
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
26 },
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
27 properties: {}
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
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
30 test("prepare diagram", () => {
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
31 const coordinates = geoJSON.geometry.coordinates;
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
32 const firstSegment = coordinates[0];
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
33 const lastSegment = coordinates[coordinates.length - 1];
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
34 const startPoint = firstSegment[0];
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
35 const endPoint = lastSegment[lastSegment.length - 1];
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
36 const result = prepareProfile({ geoJSON, startPoint, endPoint });
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
37 const alts = result.points.reduce((o, n) => {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
38 let y = n.map(e => {
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
39 return e.y;
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 o = o.concat(y);
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
42 return o;
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
43 }, []);
677
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
44 const growing = values => {
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
45 let first = values[0].x;
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
46 for (let v of values) {
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
47 if (first > v.x) return false;
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
48 }
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
49 return true;
3605af94d1ee fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 666
diff changeset
50 };
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
51 const minAlt = Math.min(...alts);
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
52 const maxAlt = Math.max(...alts);
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
53 expect(result.minAlt).toBe(minAlt);
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
54 expect(result.maxAlt).toBe(maxAlt);
692
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
55 expect(growing(result.points[0])).toBe(true);
87ea9d267c2b refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents: 677
diff changeset
56 expect(result.lengthPolyLine == 1051.5361933142963).toBe(true);
666
4c36b0e39d78 feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
57 });