|
|
|
|
@ -5,7 +5,7 @@ let mathFunc = require("./mathFunc.js");
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
organisePolygonPoints(polygonPoints) {
|
|
|
|
|
console.log(polygonPoints);
|
|
|
|
|
// console.log(polygonPoints);
|
|
|
|
|
let polygons = []
|
|
|
|
|
let polygonDict = {};
|
|
|
|
|
polygonPoints.map((point) => {
|
|
|
|
|
@ -81,14 +81,16 @@ module.exports = {
|
|
|
|
|
console.log(err);
|
|
|
|
|
res.send(500);
|
|
|
|
|
}
|
|
|
|
|
// console.log("points: %s", JSON.stringify(points));
|
|
|
|
|
let polygonPoints = points;
|
|
|
|
|
let polygons = module.exports.organisePolygonPoints(rows[0]);
|
|
|
|
|
let polygonResult = [];
|
|
|
|
|
let polygonsMerged = [];
|
|
|
|
|
polygons.map((polygon) => {
|
|
|
|
|
console.log(polygon);
|
|
|
|
|
if (polygon.coords[0].lat != polygon.coords[polygon.length - 1].lat &&
|
|
|
|
|
polygon.coords[0].lng != polygon.coords[polygon.length - 1].lng) {
|
|
|
|
|
if (polygon.coords[0].lat != polygon.coords[polygon.coords.length - 1].lat &&
|
|
|
|
|
polygon.coords[0].lng != polygon.coords[polygon.coords.length - 1].lng) {
|
|
|
|
|
console.log("Duplicated");
|
|
|
|
|
polygon.coords.push({lat: polygon.coords[0].lat, lng: polygon.coords[0].lng})
|
|
|
|
|
}
|
|
|
|
|
let intersect = module.exports.checkIntersects(polygonPoints, polygon.coords);
|
|
|
|
|
@ -116,6 +118,8 @@ module.exports = {
|
|
|
|
|
checkIntersects(points1, points2) {
|
|
|
|
|
let arrayPoints1 = [module.exports.convertPointsObjToArray(points1)];
|
|
|
|
|
let arrayPoints2 = [module.exports.convertPointsObjToArray(points2)];
|
|
|
|
|
console.log("apt1: %s", arrayPoints1);
|
|
|
|
|
console.log("apt2: %s", arrayPoints2);
|
|
|
|
|
let poly1 = turf.polygon(arrayPoints1);
|
|
|
|
|
let poly2 = turf.polygon(arrayPoints2);
|
|
|
|
|
return turf.intersect(poly1, poly2);
|
|
|
|
|
@ -132,4 +136,4 @@ module.exports = {
|
|
|
|
|
});
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|