Mercurial > gemma
comparison 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 |
comparison
equal
deleted
inserted
replaced
688:89b497d0ee0f | 692:87ea9d267c2b |
---|---|
1 import { prepareProfile } from "../../../src/application/lib/geo"; | 1 import { prepareProfile } from "../../../src/application/lib/geo"; |
2 | 2 |
3 const demodata = { | 3 const geoJSON = { |
4 type: "Feature", | 4 type: "Feature", |
5 geometry: { | 5 geometry: { |
6 type: "MultiLineString", | 6 type: "MultiLineString", |
7 coordinates: [ | 7 coordinates: [ |
8 [ | 8 [ |
9 [16.53593398, 48.14694085, -146.52392755], | 9 [17.216391563415527, 48.0245195664277, 123], |
10 [16.53593417, 48.14694103, -146.5237491], | 10 [17.216777801513672, 48.024720482272315, 124] |
11 [16.53593457, 48.14694143, -146.52359203], | |
12 [16.53593489, 48.14694174, -146.52171935], | |
13 [16.53593523, 48.14694207, -146.51977101], | |
14 [16.53593887, 48.14694566, -146.49861321], | |
15 [16.53595008, 48.1469567, -146.56072465], | |
16 [16.5359517, 48.1469583, -146.59398689], | |
17 [16.5359565, 48.14696303, -146.52466904], | |
18 [16.53595674, 48.14696326, -146.52175781], | |
19 [16.53595749, 48.14696401, -146.525045], | |
20 [16.53595771, 48.14696422, -146.53622053], | |
21 [16.535959, 48.1469655, -146.56556928], | |
22 [16.53596177, 48.14696823, -146.61177352], | |
23 [16.53596357, 48.14697, -146.61357383], | |
24 [16.53597, 48.14697633, -146.60860496], | |
25 [16.53597247, 48.14697876, -146.60175292], | |
26 [16.53598128, 48.14698744, -146.6], | |
27 [16.53598388, 48.14699, -146.59612416], | |
28 [16.53598696, 48.14699304, -146.58908826], | |
29 [16.53599403, 48.147, -146.57086913], | |
30 [16.53599604, 48.14700198, -146.57093378], | |
31 [16.536, 48.14700588, -146.57135537], | |
32 [16.5360058, 48.1470116, -146.5773355], | |
33 [16.53601143, 48.14701714, -146.586], | |
34 [16.53601287, 48.14701856, -146.58886644], | |
35 [16.53601433, 48.14702, -146.59284396], | |
36 [16.53602222, 48.14702778, -146.60933389], | |
37 [16.53603, 48.14703544, -146.62017521], | |
38 [16.5360323, 48.1470377, -146.62062115], | |
39 [16.53604, 48.14704529, -146.63128926], | |
40 [16.53604237, 48.14704763, -146.63149126], | |
41 [16.53604478, 48.14705, -146.63934732], | |
42 [16.53604741, 48.14705259, -146.65491174], | |
43 [16.53605, 48.14705514, -146.65739339], | |
44 [16.53605749, 48.14706251, -146.672801], | |
45 [16.53606, 48.14706499, -146.6809719], | |
46 [16.53606508, 48.14707, -146.69240772], | |
47 [16.53607, 48.14707484, -146.69232727], | |
48 [16.5360726, 48.1470774, -146.6917652], | |
49 [16.53607523, 48.14708, -146.69224161], | |
50 [16.53608063, 48.14708532, -146.69853152], | |
51 [16.53608539, 48.14709, -146.70246057], | |
52 [16.53608694, 48.14709153, -146.70221369], | |
53 [16.53609, 48.14709455, -146.71036364], | |
54 [16.53609554, 48.1471, -146.72067785], | |
55 [16.53609779, 48.14710221, -146.71622814], | |
56 [16.5361, 48.1471044, -146.71624132], | |
57 [16.53610786, 48.14711214, -146.73122231], | |
58 [16.53611, 48.14711425, -146.72638017], | |
59 [16.53611584, 48.14712, -146.71316779], | |
60 [16.53612, 48.1471241, -146.69596364], | |
61 [16.53612297, 48.14712703, -146.66881099], | |
62 [16.53612599, 48.14713, -146.65981711], | |
63 [16.53613216, 48.14713608, -146.67], | |
64 [16.53613614, 48.14714, -146.66614094], | |
65 [16.53613808, 48.14714192, -146.66425479], | |
66 [16.53614, 48.1471438, -146.67], | |
67 [16.53614816, 48.14715184, -146.67815987], | |
68 [16.53615, 48.14715365, -146.68], | |
69 [16.53615823, 48.14716177, -146.63882598], | |
70 [16.53616, 48.1471635, -146.63350413], | |
71 [16.53616831, 48.14717169, -146.65], | |
72 [16.53617, 48.14717336, -146.64949669], | |
73 [16.53617558, 48.14717885, -146.65424862], | |
74 [16.53618, 48.14718321, -146.62038017], | |
75 [16.53618342, 48.14718658, -146.60855537], | |
76 [16.5361869, 48.14719, -146.61379195], | |
77 [16.53618846, 48.14719154, -146.61845962], | |
78 [16.53619, 48.14719306, -146.62305785], | |
79 [16.53619853, 48.14720147, -146.62975853], | |
80 [16.5362, 48.14720291, -146.62538182], | |
81 [16.53620357, 48.14720643, -146.62185762], | |
82 [16.5362072, 48.14721, -146.62583809], | |
83 [16.53621151, 48.14721425, -146.63035726], | |
84 [16.53621735, 48.14722, -146.63734899], | |
85 [16.53621868, 48.14722132, -146.63802664], | |
86 [16.53622, 48.14722261, -146.63529917], | |
87 [16.53622876, 48.14723124, -146.65217652], | |
88 [16.53623, 48.14723246, -146.6538281], | |
89 [16.5362338, 48.1472362, -146.63837968], | |
90 [16.53623765, 48.14724, -146.62690604], | |
91 [16.53624554, 48.14724777, -146.62013288], | |
92 [16.53624891, 48.14725109, -146.61249126], | |
93 [16.53625, 48.14725217, -146.61326777], | |
94 [16.53625898, 48.14726102, -146.59450791], | |
95 [16.53626, 48.14726202, -146.5974281], | |
96 [16.5362681, 48.14727, -146.58668792], | |
97 [16.53626906, 48.14727094, -146.58335221], | |
98 [16.53627, 48.14727187, -146.5729686], | |
99 [16.53627913, 48.14728087, -146.5443239], | |
100 [16.53628, 48.14728172, -146.54074876], | |
101 [16.53628921, 48.14729079, -146.48338968], | |
102 [16.53629856, 48.1473, -146.38062752], | |
103 [16.53629904, 48.14730048, -146.37768002], | |
104 [16.5363, 48.14730142, -146.37599504], | |
105 [16.53630578, 48.14730711, -146.36669282], | |
106 [16.53630871, 48.14731, -146.35761745], | |
107 [16.5363144, 48.1473156, -146.3226378], | |
108 [16.53631886, 48.14732, -146.31291275], | |
109 [16.53631943, 48.14732057, -146.31279267], | |
110 [16.53632, 48.14732112, -146.31115702], | |
111 [16.53632951, 48.14733049, -146.30270525], | |
112 [16.53633096, 48.14733192, -146.29954072], | |
113 [16.53634462, 48.14734538, -146.27439384], | |
114 [16.53634931, 48.14735, -146.27538087], | |
115 [16.53635, 48.14735068, -146.27589835], | |
116 [16.53635973, 48.14736027, -146.28857369], | |
117 [16.53636, 48.14736053, -146.28857686], | |
118 [16.53636981, 48.14737019, -146.24847877], | |
119 [16.53637, 48.14737038, -146.24739174], | |
120 [16.53637977, 48.14738, -146.22614094], | |
121 [16.53637988, 48.14738012, -146.22580183], | |
122 [16.53638, 48.14738023, -146.22602314], | |
123 [16.53639331, 48.14739334, -146.22267557], | |
124 [16.5364, 48.14739993, -146.2368876], | |
125 [16.53640004, 48.14739998, -146.23699777], | |
126 [16.53640007, 48.1474, -146.23698322], | |
127 [16.53640014, 48.14740007, -146.23727257], | |
128 [16.53641022, 48.14741, -146.26819631], | |
129 [16.53641515, 48.14741485, -146.31195087], | |
130 [16.53642, 48.14741964, -146.37529091], | |
131 [16.53642037, 48.14742, -146.37933221], | |
132 [16.53642682, 48.14742636, -146.38609302], | |
133 [16.53643935, 48.1474387, -146.41230619], | |
134 [16.53644033, 48.14743967, -146.41376686], | |
135 [16.53644067, 48.14744, -146.41634899], | |
136 [16.53645, 48.14744919, -146.47657025], | |
137 [16.53645041, 48.14744959, -146.47965279], | |
138 [16.53645082, 48.14745, -146.48352181], | |
139 [16.53645545, 48.14745455, -146.5094055], | |
140 [16.53646, 48.14745904, -146.49783471], | |
141 [16.53646097, 48.14746, -146.49497315], | |
142 [16.53646552, 48.14746448, -146.50668776], | |
143 [16.53647, 48.14746889, -146.50222149], | |
144 [16.5364756, 48.1474744, -146.48545212], | |
145 [16.53648128, 48.14748, -146.45715436], | |
146 [16.53648421, 48.14748289, -146.4430985], | |
147 [16.53649, 48.1474886, -146.46353719], | |
148 [16.53649143, 48.14749, -146.46572148], | |
149 [16.53649575, 48.14749425, -146.44], | |
150 [16.53650158, 48.1475, -146.41105705], | |
151 [16.53650722, 48.14750556, -146.40139646], | |
152 [16.53651451, 48.14751274, -146.40124819], | |
153 [16.53652, 48.14751815, -146.39814876], | |
154 [16.53652093, 48.14751907, -146.4], | |
155 [16.53652188, 48.14752, -146.39624161], | |
156 [16.53653, 48.147528, -146.3936], | |
157 [16.53653101, 48.14752899, -146.39629475], | |
158 [16.53653203, 48.14753, -146.39628943], | |
159 [16.53653808, 48.14753596, -146.39178798], | |
160 [16.53655, 48.1475477, -146.41301322], | |
161 [16.53655077, 48.14754846, -146.41553821], | |
162 [16.53655233, 48.14755, -146.41693289], | |
163 [16.53656, 48.14755755, -146.40640331], | |
164 [16.53656248, 48.14756, -146.41292617], | |
165 [16.53656627, 48.14756373, -146.43630142], | |
166 [16.53657, 48.1475674, -146.42674711], | |
167 [16.53657131, 48.14756869, -146.42496753], | |
168 [16.53657263, 48.14757, -146.41736577], | |
169 [16.53658, 48.14757726, -146.4172562], | |
170 [16.53658185, 48.14757908, -146.41907624], | |
171 [16.53658279, 48.14758, -146.41721477], | |
172 [16.53659146, 48.14758854, -146.41708576], | |
173 [16.5366, 48.14759696, -146.3923686], | |
174 [16.53660153, 48.14759847, -146.39084679], | |
175 [16.53660309, 48.1476, -146.39238926], | |
176 [16.53660878, 48.14760561, -146.39495159], | |
177 [16.53662, 48.14761666, -146.36917686], | |
178 [16.53662168, 48.14761832, -146.37090508], | |
179 [16.53663, 48.14762651, -146.37284711], | |
180 [16.53663176, 48.14762824, -146.36781099], | |
181 [16.53664, 48.14763636, -146.39327273], | |
182 [16.53664183, 48.14763817, -146.39178684], | |
183 [16.53664369, 48.14764, -146.38843289], | |
184 [16.5366475, 48.14764375, -146.37763543], | |
185 [16.53665384, 48.14765, -146.35038674], | |
186 [16.53665592, 48.14765204, -146.34536617], | |
187 [16.53666, 48.14765607, -146.32334215], | |
188 [16.53666198, 48.14765802, -146.31156703], | |
189 [16.53666399, 48.14766, -146.30001342], | |
190 [16.53667, 48.14766592, -146.24125289], | |
191 [16.53667275, 48.14766863, -146.21284864], | |
192 [16.53667414, 48.14767, -146.20879279], | |
193 [16.53668213, 48.14767787, -146.1938368], | |
194 [16.5366843, 48.14768, -146.17711409], | |
195 [16.53669, 48.14768562, -146.16561983], | |
196 [16.53669445, 48.14769, -146.17], | |
197 [16.53670228, 48.14769772, -146.16228143], | |
198 [16.5367046, 48.1477, -146.16459732], | |
199 [16.53671, 48.14770532, -146.16467769], | |
200 [16.53671475, 48.14771, -146.15525168], | |
201 [16.53671739, 48.14771261, -146.14739384], | |
202 [16.53672, 48.14771517, -146.11895868], | |
203 [16.5367249, 48.14772, -146.09244966], | |
204 [16.53673251, 48.14772749, -146.1], | |
205 [16.53673505, 48.14773, -146.08989933], | |
206 [16.53673754, 48.14773246, -146.08712323], | |
207 [16.53674, 48.14773488, -146.07512397], | |
208 [16.53674258, 48.14773742, -146.07516236], | |
209 [16.53675, 48.14774473, -146.06128182], | |
210 [16.53675266, 48.14774734, -146.05073439], | |
211 [16.53675535, 48.14775, -146.05046477], | |
212 [16.53676, 48.14775458, -146.04725289], | |
213 [16.53676411, 48.14775863, -146.04619306], | |
214 [16.53677118, 48.14776559, -146.05070528], | |
215 [16.53677565, 48.14777, -146.05208893], | |
216 [16.53678, 48.14777428, -146.04444132], | |
217 [16.53678288, 48.14777712, -146.03850708], | |
218 [16.53679, 48.14778413, -146.05210744], | |
219 [16.53679596, 48.14779, -146.04859564], | |
220 [16.5368, 48.14779398, -146.05975537], | |
221 [16.53680303, 48.14779697, -146.0853955], | |
222 [16.53681, 48.14780383, -146.10630826], | |
223 [16.53681311, 48.14780689, -146.11345379], | |
224 [16.53681626, 48.14781, -146.09723826], | |
225 [16.53682318, 48.14781682, -146.10186761], | |
226 [16.53682641, 48.14782, -146.0758255], | |
227 [16.53682822, 48.14782178, -146.06373106], | |
228 [16.53683, 48.14782354, -146.06384298], | |
229 [16.53683829, 48.14783171, -146.0859259], | |
230 [16.53684, 48.14783339, -146.08606612], | |
231 [16.53684837, 48.14784163, -146.10181599], | |
232 [16.53685, 48.14784324, -146.11541653], | |
233 [16.53685844, 48.14785156, -146.1427194], | |
234 [16.53686, 48.14785309, -146.13554545], | |
235 [16.53686701, 48.14786, -146.02888926], | |
236 [16.53687, 48.14786294, -145.9918562], | |
237 [16.53687859, 48.14787141, -146.02322148], | |
238 [16.53688, 48.14787279, -146.01592727], | |
239 [16.53688363, 48.14787637, -146.02106911], | |
240 [16.53688732, 48.14788, -146.02409396], | |
241 [16.53688867, 48.14788133, -146.02680266], | |
242 [16.53689, 48.14788264, -146.0186281], | |
243 [16.53689874, 48.14789126, -145.95798834], | |
244 [16.5369, 48.1478925, -145.95126446], | |
245 [16.53690762, 48.1479, -145.93071309], | |
246 [16.53691386, 48.14790614, -145.92156536], | |
247 [16.53691777, 48.14791, -145.92165268], | |
248 [16.53692, 48.1479122, -145.92390083], | |
249 [16.53692792, 48.14792, -145.96751678], | |
250 [16.53692897, 48.14792103, -145.97731557], | |
251 [16.53693, 48.14792205, -145.97610579], | |
252 [16.536934, 48.147926, -145.97661948], | |
253 [16.53693807, 48.14793, -145.96826342], | |
254 [16.53693904, 48.14793096, -145.96712739], | |
255 [16.53694187, 48.14793375, -145.96906352], | |
256 [16.53695276, 48.14794447, -145.97881506], | |
257 [16.53695837, 48.14795, -146.02779362], | |
258 [16.53696, 48.1479516, -146.04801653], | |
259 [16.53696565, 48.14795717, -146.09565387], | |
260 [16.53696852, 48.14796, -146.13901007], | |
261 [16.53697731, 48.14796865, -146.18606133], | |
262 [16.53697867, 48.14797, -146.19503523], | |
263 [16.53697912, 48.14797044, -146.19941736], | |
264 [16.53697956, 48.14797087, -146.20073754], | |
265 [16.53698922, 48.14798039, -146.22094825], | |
266 [16.53699, 48.14798116, -146.22119008], | |
267 [16.53699898, 48.14799, -146.22397651], | |
268 [16.53699949, 48.14799051, -146.22464446], | |
269 [16.537, 48.14799101, -146.22469752], | |
270 [16.53700957, 48.14800043, -146.24578768], | |
271 [16.53701, 48.14800086, -146.24966446], | |
272 [16.53701964, 48.14801036, -146.29935803], | |
273 [16.53702943, 48.14802, -146.33911577], | |
274 [16.53703, 48.14802056, -146.3365719], | |
275 [16.53703958, 48.14803, -146.36426678], | |
276 [16.53703979, 48.14803021, -146.36691757], | |
277 [16.53704, 48.14803041, -146.36915702], | |
278 [16.53704483, 48.14803517, -146.4162831], | |
279 [16.53704973, 48.14804, -146.42519463], | |
280 [16.53704987, 48.14804013, -146.42607993], | |
281 [16.53705, 48.14804026, -146.42687273], | |
282 [16.53705026, 48.14804052, -146.42800651], | |
283 [16.53706498, 48.14805502, -146.50947294], | |
284 [16.53707, 48.14805997, -146.41383884], | |
285 [16.53707505, 48.14806495, -146.38782265], | |
286 [16.53708018, 48.14807, -146.2549849], | |
287 [16.53709, 48.14807967, -146.17102479], | |
288 [16.53709017, 48.14807983, -146.16886761], | |
289 [16.53709034, 48.14808, -146.16765101], | |
290 [16.5370952, 48.1480848, -146.06978518], | |
291 [16.5371, 48.14808952, -146.07810248], | |
292 [16.53710024, 48.14808976, -146.07856953], | |
293 [16.53710049, 48.14809, -146.07724329], | |
294 [16.53710099, 48.14809049, -146.077], | |
295 [16.53711064, 48.1481, -146.06670134], | |
296 [16.53711535, 48.14810465, -146.07514155], | |
297 [16.53712, 48.14810922, -146.00874876], | |
298 [16.53712039, 48.14810961, -146.0027652], | |
299 [16.53712079, 48.14811, -146.00158054], | |
300 [16.53712389, 48.14811306, -146.00180301], | |
301 [16.53712543, 48.14811457, -145.97387677], | |
302 [16.53712594, 48.14811507, -145.97576373], | |
303 [16.53713047, 48.14811953, -145.88186012], | |
304 [16.53713187, 48.14812092, -145.85101091], | |
305 [16.53713287, 48.1481219, -145.84510153], | |
306 [16.53713971, 48.14812864, -145.67681244], | |
307 [16.53714031, 48.14812923, -145.65155866], | |
308 [16.53714164, 48.14813054, -145.67523479], | |
309 [16.53714216, 48.14813106, -145.68460115] | |
310 ], | 11 ], |
311 [ | 12 [ |
312 [16.53593403, 48.14694089, -146.52419461], | 13 [17.218494415283203, 48.02540933065123, 125], |
313 [16.53593398, 48.14694085, -146.52394016] | 14 [17.219438552856445, 48.02586855778941, 126], |
15 [17.220726013183594, 48.02647128719908, 127], | |
16 [17.221627235412598, 48.026987906797494, 128], | |
17 [17.222957611083984, 48.02759062311748, 129], | |
18 [17.223901748657227, 48.0280785311666, 130], | |
19 [17.224159240722656, 48.02819333238926, 131] | |
314 ], | 20 ], |
315 [ | 21 [ |
316 [16.53593432, 48.14694119, -146.52544823], | 22 [17.225961685180664, 48.02891083423718, 132], |
317 [16.53593403, 48.14694089, -146.52419614] | 23 [17.227892875671383, 48.02997271864036, 133] |
318 ] | 24 ] |
319 ] | 25 ] |
320 }, | 26 }, |
321 properties: {} | 27 properties: {} |
322 }; | 28 }; |
323 | 29 |
324 test("prepare diagram", () => { | 30 test("prepare diagram", () => { |
325 const result = prepareProfile(demodata); | 31 const coordinates = geoJSON.geometry.coordinates; |
32 const firstSegment = coordinates[0]; | |
33 const lastSegment = coordinates[coordinates.length - 1]; | |
34 const startPoint = firstSegment[0]; | |
35 const endPoint = lastSegment[lastSegment.length - 1]; | |
36 const result = prepareProfile({ geoJSON, startPoint, endPoint }); | |
326 const alts = result.points.reduce((o, n) => { | 37 const alts = result.points.reduce((o, n) => { |
327 let y = n.map(e => { | 38 let y = n.map(e => { |
328 return e.y; | 39 return e.y; |
329 }); | 40 }); |
330 o = o.concat(y); | 41 o = o.concat(y); |
337 } | 48 } |
338 return true; | 49 return true; |
339 }; | 50 }; |
340 const minAlt = Math.min(...alts); | 51 const minAlt = Math.min(...alts); |
341 const maxAlt = Math.max(...alts); | 52 const maxAlt = Math.max(...alts); |
342 expect(result.points.length).toBe(3); | |
343 expect(growing(result.points[0])).toBe(true); | |
344 expect(growing(result.points[1])).toBe(true); | |
345 expect(growing([...result.points[0], ...result.points[1]])).toBe(true); | |
346 expect(growing([...result.points[1], ...result.points[2]])).toBe(false); // because of corrupt testdata | |
347 expect(result.totalLength).toBe(160.06814078495722); | |
348 expect(result.minAlt).toBe(minAlt); | 53 expect(result.minAlt).toBe(minAlt); |
349 expect(result.maxAlt).toBe(maxAlt); | 54 expect(result.maxAlt).toBe(maxAlt); |
55 expect(growing(result.points[0])).toBe(true); | |
56 expect(result.lengthPolyLine == 1051.5361933142963).toBe(true); | |
350 }); | 57 }); |