|
|
|
|
@ -1,3 +1,6 @@
|
|
|
|
|
// import Turf from "turf";
|
|
|
|
|
let turf = require("turf");
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
gpsToMeters: function (lat1, lon1, lat2, lon2){ // generally used geo measurement function
|
|
|
|
|
var R = 6378.137; // Radius of earth in KM
|
|
|
|
|
@ -9,5 +12,48 @@ module.exports = {
|
|
|
|
|
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
|
|
|
var d = R * c;
|
|
|
|
|
return d * 1000; // meters
|
|
|
|
|
},
|
|
|
|
|
calculateArea: function (points) {
|
|
|
|
|
var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);
|
|
|
|
|
var area = turf.area(polygon);
|
|
|
|
|
console.log(area);
|
|
|
|
|
var poly1 = turf.polygon([[
|
|
|
|
|
[-82.574787, 35.594087],
|
|
|
|
|
[-82.574787, 35.615581],
|
|
|
|
|
[-82.545261, 35.615581],
|
|
|
|
|
[-82.545261, 35.594087],
|
|
|
|
|
[-82.574787, 35.594087]
|
|
|
|
|
]], {"fill": "#0f0"});
|
|
|
|
|
var poly2 = turf.polygon([[
|
|
|
|
|
[-82.560024, 35.585153],
|
|
|
|
|
[-82.560024, 35.602602],
|
|
|
|
|
[-82.52964, 35.602602],
|
|
|
|
|
[-82.52964, 35.585153],
|
|
|
|
|
[-82.560024, 35.585153]
|
|
|
|
|
]], {"fill": "#00f"});
|
|
|
|
|
|
|
|
|
|
var union = turf.union(poly1, poly2);
|
|
|
|
|
console.log(union.geometry.coordinates);
|
|
|
|
|
var poly1 = turf.polygon([[
|
|
|
|
|
[-122.801742, 45.48565],
|
|
|
|
|
[-122.801742, 45.60491],
|
|
|
|
|
[-122.584762, 45.60491],
|
|
|
|
|
[-122.584762, 45.48565],
|
|
|
|
|
[-122.801742, 45.48565]
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
var poly2 = turf.polygon([[
|
|
|
|
|
[-122.520217, 45.535693],
|
|
|
|
|
[-122.64038, 45.553967],
|
|
|
|
|
[-122.720031, 45.526554],
|
|
|
|
|
[-122.669906, 45.507309],
|
|
|
|
|
[-122.723464, 45.446643],
|
|
|
|
|
[-122.532577, 45.408574],
|
|
|
|
|
[-122.487258, 45.477466],
|
|
|
|
|
[-122.520217, 45.535693]
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
var intersection = turf.intersect(poly1, poly2);
|
|
|
|
|
console.log(intersection);//null if no intersect
|
|
|
|
|
}
|
|
|
|
|
}
|