Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
.sort((matchA, matchB) => turf.area(matchB.intersection) - turf.area(matchA.intersection))
.map(({region, intersection}) => region.properties.name);
function populateArea(feature: any){
let area = turf.area(feature);
if(!feature.properties){
feature.properties = {};
}
feature.properties['xyz_area_sqm'] = area;
feature.properties['xyz_area_sqkm'] = (area / 1000000).toFixed(2);
feature.properties['xyz_area_sqmiles'] = (area * 0.00000038610215855).toFixed(2);
return feature;
}
results.sort((a, b) => turf.area(b) - turf.area(a));
}
const setDataGeom = geom => {
const area = turf.area(geom) / 1e6;
const zoomLevel = mapObj.map.getZoom() + 4;
const grid = makeGrid(geom, zoomLevel, {});
mapObj.map.fitBounds(turf.bbox(geom), { padding: 20 });
updateMetadata({
...metadata,
geom: geom,
area: area.toFixed(2),
zoomLevel: zoomLevel,
taskGrid: grid,
tempTaskGrid: grid,
});
if (mapObj.map.getLayer(layer_name)) {
mapObj.map.removeLayer(layer_name);
}
if (mapObj.map.getSource(layer_name)) {
var buildingTraceTree = rbush(bboxes.length);
buildingTraceTree.load(bboxes);
for (var j = 0; j < bboxes.length; j++) {
var bbox = bboxes[j];
var buildingA = buildings[bbox.id];
var areabuildingA = turf.area(buildingA);
var overlaps = buildingTraceTree.search(bbox);
for (var k = 0; k < overlaps.length; k++) {
var overlap = overlaps[k];
var buildingB = buildings[overlap.id];
if (overlap.id !== bbox.id) {
var difference = turf.difference(
buildingA, buildingB
);
//detecting buildings that have > 90% overlap
if (difference && (areabuildingA - turf.area(difference)) > (areabuildingA * 0.9)) {
var points = turf.explode(buildingA);
var multiPoint = turf.combine(points).features[0];
multiPoint.properties = {
_fromWay: buildingA.properties['@id'],
_toWay: buildingB.properties['@id'],
_osmlint: osmlint
};
//save detection
output[overlap.id] = buildingA;
output[bbox.id] = buildingB;
output[overlap.id + bbox.id + 'M'] = multiPoint;
}
}
}
}