Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// top_right = { "lat": positionAndBearing[0].lat + tr_lat_displacement, "lng": positionAndBearing[0].lng + tr_lng_displacement };
// bottom_right = { "lat": positionAndBearing[0].lat + br_lat_displacement, "lng": positionAndBearing[0].lng + br_lng_displacement };
// bottom_left = { "lat": positionAndBearing[0].lat + bl_lat_displacement, "lng": positionAndBearing[0].lng + bl_lng_displacement };
// top_left = { "lat": positionAndBearing[0].lat + tl_lat_displacement, "lng": positionAndBearing[0].lng + tl_lng_displacement };
top_right = [ positionAndBearing[0].lng + (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat + (this.defaultFootprint[category].lat_dst/2) ];
bottom_right = [ positionAndBearing[0].lng + (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat - (this.defaultFootprint[category].lat_dst/2) ];
bottom_left = [ positionAndBearing[0].lng - (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat - (this.defaultFootprint[category].lat_dst/2) ];
top_left = [ positionAndBearing[0].lng - (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat + (this.defaultFootprint[category].lat_dst/2) ];
var poly = turfPolygon(
[
[
top_right,
bottom_right,
bottom_left,
top_left,
top_right
]
]
);
// console.log(positionAndBearing[1]);
var rotatedPoly = turfTransformRotate(poly, positionAndBearing[1]);
if (DEMO_MODE) {
private wayToPoint(FeatureCollection) {
let features = FeatureCollection.features;
for (let i = 0; i < features.length; i++) {
let feature = features[i];
// console.log(feature);
if (feature.geometry) {
if (feature.geometry.type !== 'Point') {
// on stocke la géométrie d'origine dans .way_geometry
feature.properties.way_geometry = JSON.parse(JSON.stringify(feature.geometry));
let geom;
switch (feature.geometry.type) {
case 'Polygon':
feature.properties['mesure'] = area(feature.geometry)
geom = polygon(feature.geometry.coordinates);
break;
case 'MultiPolygon':
feature.properties['mesure'] = area(feature.geometry)
geom = multiPolygon(feature.geometry.coordinates);
break;
case 'LineString':
feature.properties['mesure'] = length(feature.geometry)
geom = lineString(feature.geometry.coordinates);
break;
case 'MultiLineString':
feature.properties['mesure'] = length(feature.geometry)
geom = multiLineString(feature.geometry.coordinates);
break;
}
//========
// - turf.merge is deprecated, so...
// - https://github.com/turf-junkyard/turf-merge
// This module is now deprecated in favor of using
// the turf-union module repeatedly on an array.
// - https://gis.stackexchange.com/questions/243460/turf-js-union-with-array-of-features
// console.log('feat collection:', turf.featureCollection(elevationPolys));
let mergedElevationPoly = turf.union.apply(
this, turf.featureCollection(elevationPolys).features);
// trim to desired search area
mergedElevationPoly = turf.intersect(
polygon, mergedElevationPoly);
if (mergedElevationPoly) {
let contourArea = turf.area(mergedElevationPoly.geometry);
// FIXME: ???????? ???????? ???????? ????????
// L.mapbox.featureLayer().setGeoJSON(mergedElevationPoly).addTo(map);
contours.push({
'geometry': mergedElevationPoly,
'ele': currentElevation,
'area': contourArea,
});
}
} catch (error) { // on merge fail, insert the previous contour again and skip
console.log('merge failed at elevation '+currentElevation);
console.log(error.message);
}
}
// remove contour undercuts
//========
// this was being used...
// let mergedElevationPoly = turf.merge(
// turf.featureCollection(elevationPolys));
//========
// - turf.merge is deprecated, so...
// - https://github.com/turf-junkyard/turf-merge
// This module is now deprecated in favor of using
// the turf-union module repeatedly on an array.
// - https://gis.stackexchange.com/questions/243460/turf-js-union-with-array-of-features
// console.log('feat collection:', turf.featureCollection(elevationPolys));
let mergedElevationPoly = turf.union.apply(
this, turf.featureCollection(elevationPolys).features);
// trim to desired search area
mergedElevationPoly = turf.intersect(
polygon, mergedElevationPoly);
if (mergedElevationPoly) {
let contourArea = turf.area(mergedElevationPoly.geometry);
// FIXME: ???????? ???????? ???????? ????????
// L.mapbox.featureLayer().setGeoJSON(mergedElevationPoly).addTo(map);
contours.push({
'geometry': mergedElevationPoly,
'ele': currentElevation,
'area': contourArea,
});
}
} catch (error) { // on merge fail, insert the previous contour again and skip
console.log('merge failed at elevation '+currentElevation);
console.log(error.message);
results.push(final);
};
// Each filter
for (let filterFeature of filter.features) {
try {
let geometry = filterFeature.geometry;
let filter = geometry.type === "Point" ? turf.circle(geometry, geometry.properties.radius) : geometry;
// Each incident
for (let feature of incidents.features) {
let geometry = feature.geometry;
// filter results to overlapping regions
let result = turf.intersect(filter, geometry.type === "Point" ? turf.circle(geometry, radius) : geometry.geometries[1].geometries[0]);
// if match
if (result !== undefined) format(feature);
}
} catch(error) {
res.status(500).send({ ok: false, code: 500, error: "Internal Server Error" });
console.error(error);
break;
}
}
// Sort results by HIGH→LOW warning levels
// then sort by Distance from Home
results.sort((a, b) => {
let home = ["-33.746", "150.7123"];
});
} else {
geoJSON.push(parsePoly(geometry.slice(10, -2)));
}
return geoJSON;
}
const geometry = params.area.geofield[0].geom;
const geomJSON = geoJSONify(geometry);
// Now I'll check whether the point is inside the polygon (isInside)
// OR if the point is within [radius] km of the polygon border (isNear)
const circle = turf.circle(params.point, params.radius, { units: 'kilometers' });
const polygon = turf.polygon(geomJSON);
const isInside = turf.inside(params.point, polygon);
const isNear = turf.intersect(circle, polygon) !== null;
if (isInside || isNear) {
commit('addLocalArea', params.area);
}
},
},
}
for (const feature of filters.filter.features) {
try {
const geometry = feature.geometry;
const filter = geometry.type === 'Point'
? turf.circle(geometry, geometry.properties.radius)
: geometry;
// Each incident
for (const feature of incidents.features) {
const geometry = feature.geometry;
// Filter Results for Overlapping Regions
try {
const result = turf.intersect(filter, geometry.type === 'Point'
? turf.circle(geometry, radius)
: geometry.geometries[1].geometries[0]);
// Match
if (result !== undefined) {
const formatted = this.format(feature);
if (formatted) results.push(formatted); // eslint-disable-line max-depth
}
} catch(error) {
console.log(error.message);
++missing;
continue;
}
}
} catch(error) {
res.status(500).send({ ok: false, error: 'Internal Server Error' });
const segments = mapArray(item.segments, segment => {
length += (distance(last, point(segment), { units: 'kilometers' }) * 10);
const coord = [
segment[0],
segment[1],
length,
];
last = point(segment);
return coord;
});
// maxLength = Math.max(maxLength, length);
.then(results => {
if (!results.hits.hits.length) {
return results.hits.hits;
}
const points = results.hits.hits.map(doc =>
turf.point(doc._source.coordinates)
);
if (lat && lng && !bounds) {
points.push(turf.point([lng, lat]));
}
// create a bounding box for the results
const envelope = turf.bbox(
turf.buffer(turf.envelope(turf.featureCollection(points)), 0.5, {
units: "miles"
})
);
bounds = {
southwest: {
lat: envelope[1],
lng: envelope[0]
},
northeast: {
lat: envelope[3],
findNearestPoint = (targetFeature, allFeatures) => {
if (
!targetFeature ||
!targetFeature.geometry ||
!targetFeature.geometry.coordinates
) {
return;
}
const targetPoint = turf.point(targetFeature.geometry.coordinates);
const uniqueFeatues = allFeatures.filter(a =>
a.geometry.coordinates[0] !==
targetFeature.geometry.coordinates[0] &&
a.geometry.coordinates[1] !==
targetFeature.geometry.coordinates[1]);
const allPoints = uniqueFeatues.map(f =>
turf.point(f.geometry.coordinates));
const points = turf.featureCollection(allPoints);
const nearest = turf.nearestPoint(targetPoint, points);
if (!nearest) {
return;
}
const nearestFeature = uniqueFeatues[nearest.properties.featureIndex];
return [targetFeature, nearestFeature]; // eslint-disable-line consistent-return
};