Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("sharedstreets -- bearing & distance", (t:any) => {
const line = lineString([[-74.006449, 40.739405000000005], [-74.00790070000001, 40.7393884], [-74.00805100000001, 40.7393804]]);
const lineLength = length(line);
const inboundBearing = sharedstreets.inboundBearing(line, lineLength, lineLength);
const outboundBearing = sharedstreets.outboundBearing(line, lineLength, 0);
const distanceToNextRef = sharedstreets.distanceToNextRef(line);
t.equal(outboundBearing, 269); // => 269 Java Implementation
t.equal(inboundBearing, 269); // => 267 Java Implementation
t.equal(distanceToNextRef, 13502); // => 13502 Java Implementation
t.end();
});
function getLengthOfLineString(line: Feature, isPlanar: boolean) {
if (isPlanar) {
return segmentReduce(line, (previousValue?: number, segment?: Feature): number => {
const coords = segment.geometry.coordinates; // the signatrue of segmentReduce has problem ?
return previousValue + euclideanDistance(coords);
}, 0);
} else {
return length(line, {
units: "meters",
});
}
}
}
// TODO add error handling for failed string-to-gpx and gpx-to-geojson parsing
const gpxAsXml = new DOMParser().parseFromString(
action.payload.trackGpx,
'text/xml',
);
const trackGeojson = assertType(toGeoJSON.gpx(gpxAsXml));
const startPoints: TrackPoint[] = []; // TODO
const finishPoints: TrackPoint[] = []; // TODO
for (const feature of trackGeojson.features) {
if (feature.geometry.type === 'LineString') {
const lengthInKm = turfLength(feature);
const coords = feature.geometry.coordinates;
const startLonlat = coords[0];
let startTime: Date | undefined;
let finishTime: Date | undefined;
const times = assertType(
feature.properties && feature.properties.coordTimes,
);
if (times) {
startTime = new Date(times[0]);
finishTime = new Date(times[times.length - 1]);
}
startPoints.push({
lat: startLonlat[1],
lon: startLonlat[0],
lengthInKm: 0,
startTime,
async function resolveElevationProfilePointsViaApi(
getState,
trackGeojson,
dispatch: Dispatch,
) {
const totalDistanceInKm = turfLength(trackGeojson);
const delta = Math.min(0.1, totalDistanceInKm / (window.innerWidth / 2));
const elevationProfilePoints: {
lat: number;
lon: number;
ele: number;
distance: number;
}[] = [];
for (let dist = 0; dist <= totalDistanceInKm; dist += delta) {
const [lon, lat] = getCoord(turfAlong(trackGeojson, dist));
elevationProfilePoints.push({
lat,
lon,
distance: dist * 1000,
ele: Number.NaN, // will be filled later
});
// NB using indices here so we get an object even if fromStop or toStop is null
// stops in pattern are in fact objects but they only have stop ID.
const fromStop = feed.stopsById[pattern.stops[fromStopIndex].stop_id]
const toStop = feed.stopsById[pattern.stops[toStopIndex].stop_id]
const geometry = lineSlice(
point([fromStop.stop_lon, fromStop.stop_lat]),
point([toStop.stop_lon, toStop.stop_lat]),
{
type: 'Feature',
geometry: pattern.geometry,
properties: {}
}
)
const removedLengthThisPattern = turfLength(geometry)
return (
<table>
<tbody>
<tr>
<th>{message('report.patternName')}</th>
<td>{pattern.name}</td>
</tr>
<tr>
<th>{message('report.reroute.originalLength')}</th>
<td>
</td></tr></tbody></table>
function Pattern(props) {
const {modification, feedsById, pattern} = props
const feed = feedsById[modification.feed]
// all calculations below are in kilometers
const patternLength = turfLength(pattern.geometry)
const stops = getStops(modification.segments)
const segmentLength = stops.slice(-1)[0].distanceFromStart / 1000
const segmentDistances = modification.segments.map(seg =>
turfLength(seg.geometry)
)
const {segmentSpeeds} = modification
const totalDistance = sum(segmentDistances)
const weightedSpeeds = segmentSpeeds.map((s, i) => s * segmentDistances[i])
const speed =
weightedSpeeds.reduce((total, speed) => total + speed, 0) / totalDistance
// figure out removed segment length
const fromStopIndex =
modification.fromStop != null
? pattern.stops.findIndex(s => s.stop_id === modification.fromStop)
export function getTraceLength (traceGeoJSON) {
return turfLength(traceGeoJSON, { units: 'kilometers' }) * 1000
}
const segmentDistances = segments.map(seg => turfLength(seg.geometry))