added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
npm-debug.log
node_modules
+27
View File
@@ -0,0 +1,27 @@
Copyright (c) 2014, Maciej Adwent
Based on functions defined by Chris Veness
(c) 2002 - 2012 Chris Veness http://www.movable-type.co.uk/scripts/latlong.html
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+4
View File
@@ -0,0 +1,4 @@
test:
@./node_modules/.bin/mocha --timeout 6000
.PHONY: test
+83
View File
@@ -0,0 +1,83 @@
gps-distance
============
[![NPM](https://nodei.co/npm/gps-distance.png)](https://nodei.co/npm/gps-distance/)
A node module for performing distance calculations between GPS coordinates
Installation
------------
```
npm install gps-distance
```
Examples
========
`gps-distance` supports two syntaxes for convenience. You can measure just between two points and supply in your GPS coordinates as direct arguments to distance in the form `(source_lat, source_lon, destination_lat, destination_lon)`, or you can use an array of points each in `[lat,lon]` format. See the examples below.
Point to Point
--------------
```javascript
var distance = require('gps-distance');
// Measure between two points:
var result = distance(45.527517, -122.718766, 45.373373, -121.693604);
// result is 81.78450202539503
```
Array of GPS points
-------------------
```javascript
// Measure a list of GPS points along a path:
var path = [
[45.527517, -122.718766],
[45.373373, -121.693604],
[45.527517, -122.718766]
];
var result2 = distance(path);
// result2 is 163.56900405079006
```
Measuring Distance From a .GPX File
-----------------------------------
To compute the distance travelled in a tracked GPX file, use `gps-distance` with the `gpx-stream` module ( http://npmjs.org/package/gpx-stream/ ).
```javascript
var GPXstream = require('gpx-stream');
var distance = require('gps-distance');
var points = new GPXstream();
var source = fs.createReadStream('./marathon.gpx');
var path = [];
source.pipe(points);
points.on('readable', function() {
var point;
while(point = points.read()) {
path.push([point.lat, point.lon]);
}
});
points.on('end', function() {
console.log('Distance travelled: ' + distance(path) + ' km');
});
```
Notes
-----
Distances are returned in kilometers and computed using the Haversine formula.
@@ -0,0 +1,38 @@
var RADIUS = 6371;
var toRad = function(n) {
return n * Math.PI / 180;
};
var getDistance = function(from, to) {
var fromLat = from[0];
var fromLon = from[1];
var toLat = to[0];
var toLon = to[1];
var dLat = toRad(toLat - fromLat);
var dLon = toRad(toLon - fromLon);
var fromLat = toRad(fromLat);
var toLat = toRad(toLat);
var a = Math.pow(Math.sin(dLat / 2), 2) +
(Math.pow(Math.sin(dLon / 2), 2) * Math.cos(fromLat) * Math.cos(toLat));
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return RADIUS * c;
};
var measurePath = function(points) {
return points.reduce(function(memo, point) {
var distance = memo.lastPoint === null ? 0 : getDistance(memo.lastPoint, point);
return { lastPoint: point, distance: distance + memo.distance };
}, { lastPoint: null, distance: 0 }).distance;
};
module.exports = function(fromLat, fromLon, toLat, toLon) {
if(typeof fromLat === 'number'){
return getDistance([fromLat, fromLon], [toLat, toLon]);
} else {
return measurePath(fromLat);
}
};
@@ -0,0 +1,61 @@
{
"_from": "gps-distance@0.0.4",
"_id": "gps-distance@0.0.4",
"_inBundle": false,
"_integrity": "sha1-8LSoFyxmj97AZSkaSZm5YfGRbRA=",
"_location": "/gps-distance",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "gps-distance@0.0.4",
"name": "gps-distance",
"escapedName": "gps-distance",
"rawSpec": "0.0.4",
"saveSpec": null,
"fetchSpec": "0.0.4"
},
"_requiredBy": [
"/hafas-client"
],
"_resolved": "https://registry.npmjs.org/gps-distance/-/gps-distance-0.0.4.tgz",
"_shasum": "f0b4a8172c668fdec065291a4999b961f1916d10",
"_spec": "gps-distance@0.0.4",
"_where": "/home/pi/MagicMirror/modules/MMM-PublicTransportHafas/node_modules/hafas-client",
"author": {
"name": "Maciej Adwent",
"url": "http://github.com/Maciek416"
},
"bugs": {
"url": "https://github.com/Maciek416/gps-distance/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "Node module for computing distances between GPS coordinates",
"devDependencies": {
"gpx-stream": "0.0.1",
"mocha": ">= 1.9.0",
"should": ">= 1.2.2"
},
"engines": {
"node": ">= 0.10.x",
"npm": ">= 1.2.x"
},
"homepage": "https://github.com/Maciek416/gps-distance#readme",
"keywords": [
"gps",
"coordinates",
"distance",
"haversine"
],
"license": "BSD",
"main": "lib/distance",
"name": "gps-distance",
"private": false,
"repository": {
"type": "git",
"url": "git://github.com/Maciek416/gps-distance.git"
},
"version": "0.0.4"
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,60 @@
'use strict';
process.env.NODE_ENV = 'test';
var should = require('should');
var distance = require('../lib/distance');
var gpx = require('gpx-stream');
var fs = require('fs');
describe('gps-distance', function() {
describe('distance', function() {
it('should measure a distance correctly', function(done) {
var libResult = distance(45.527517, -122.718766, 45.373373, -121.693604)
libResult.should.be.approximately(81.784, 0.1);
done();
});
it('should measure the distance of a short path correctly', function(done) {
var path = [
[45.527517, -122.718766],
[45.373373, -121.693604]
];
var libResult = distance(path);
libResult.should.be.approximately(81.784, 0.1);
done();
});
it('should measure the distance of a longer path correctly', function(done) {
var points = new gpx();
var source = fs.createReadStream('./test/oregon.gpx');
var path = [];
source.pipe(points);
points.on('readable', function(){
var point;
while(point = points.read()){
path.push([point.lat,point.lon]);
}
});
points.on('end', function(){
distance(path).should.be.approximately(7.7, 0.1);
done();
});
});
});
});