view 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
line wrap: on
line source

import { prepareProfile } from "../../../src/application/lib/geo";

const geoJSON = {
  type: "Feature",
  geometry: {
    type: "MultiLineString",
    coordinates: [
      [
        [17.216391563415527, 48.0245195664277, 123],
        [17.216777801513672, 48.024720482272315, 124]
      ],
      [
        [17.218494415283203, 48.02540933065123, 125],
        [17.219438552856445, 48.02586855778941, 126],
        [17.220726013183594, 48.02647128719908, 127],
        [17.221627235412598, 48.026987906797494, 128],
        [17.222957611083984, 48.02759062311748, 129],
        [17.223901748657227, 48.0280785311666, 130],
        [17.224159240722656, 48.02819333238926, 131]
      ],
      [
        [17.225961685180664, 48.02891083423718, 132],
        [17.227892875671383, 48.02997271864036, 133]
      ]
    ]
  },
  properties: {}
};

test("prepare diagram", () => {
  const coordinates = geoJSON.geometry.coordinates;
  const firstSegment = coordinates[0];
  const lastSegment = coordinates[coordinates.length - 1];
  const startPoint = firstSegment[0];
  const endPoint = lastSegment[lastSegment.length - 1];
  const result = prepareProfile({ geoJSON, startPoint, endPoint });
  const alts = result.points.reduce((o, n) => {
    let y = n.map(e => {
      return e.y;
    });
    o = o.concat(y);
    return o;
  }, []);
  const growing = values => {
    let first = values[0].x;
    for (let v of values) {
      if (first > v.x) return false;
    }
    return true;
  };
  const minAlt = Math.min(...alts);
  const maxAlt = Math.max(...alts);
  expect(result.minAlt).toBe(minAlt);
  expect(result.maxAlt).toBe(maxAlt);
  expect(growing(result.points[0])).toBe(true);
  expect(result.lengthPolyLine == 1051.5361933142963).toBe(true);
});