Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// console.log(currentElevation, feats.length, feats);
// feats.forEach(feat => { console.log('type:', feat.geometry.type); }); // 'Polygon'
let mergedElevationPoly = feats.reduce(((accm, feat) => turfUnion(accm, feat)), feats[0]);
// console.log('@@@', mergedElevationPoly, currentElevation);
if (0) { // trim to desired search area
mergedElevationPoly = turfIntersect( // use module version instead
polygon, mergedElevationPoly);
// console.log('@@@', polygon);
}
// console.log('@@@mergedElevationPoly:', mergedElevationPoly);
if (mergedElevationPoly) {
// console.log('@@@merge success', currentElevation);
let contourArea = turfArea(mergedElevationPoly.geometry);
// 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
if (0) {
let turfCoordinates = []
for (let coordinate of featureSorted.geometry.coordinates[0]) {
// console.log('coordinate:', coordinate);
turfCoordinates.push(point(coordinate));
}
let distances = []
for (let i=0; i
ringsCoords.forEach(function (coords) {
// var poly = polygon([points]);
var ringArea = area(polygon([coords]));
// create an array of areas value
areas.push(ringArea);
// associate each lineRing with its area
ringsWithArea.push({ring: coords, area: ringArea});
});
areas.sort(function (a, b) { // bigger --> smaller
createOfflineResource = async () => {
const { fetchOfflineResources, navigation, setNotification, visibleBounds } = this.props
if (visibleBounds == null) {
// no bounds were selected
return
}
const aoi = [
visibleBounds[1][0],
visibleBounds[1][1],
visibleBounds[0][0],
visibleBounds[0][1]
]
const areaSqKm = area(bboxPolygon(aoi)) / (1000 ** 2)
if (areaSqKm > 400) {
setNotification({
level: 'error',
message: `${areaSqKm.toLocaleString()} km² is too large to download.`
})
return
}
navigation.navigate('OfflineAreaList')
const name = (await getPlaceName(aoi)) || 'Unnamed Area'
fetchOfflineResources(name, aoi)
}
// ---------------------------------------------------------------------------------------------------------------------
// GeoJSONUtils
//
// @module
// ---------------------------------------------------------------------------------------------------------------------
const area = require('@turf/area').default;
const _ = require('lodash');
// ---------------------------------------------------------------------------------------------------------------------
class GeoJSONUtils {
constructor() {
}
/**
* Checks to see if the feature is a Polygon formatted as a MultiPolygon.
*
* @param {Polygon} polygon
* @returns {Polygon}
*/
fixMultiPoly(polygon) {
if(polygon.geometry.type === 'MultiPolygon' && polygon.geometry.coordinates[0].length === 1) {
const getAreaKm2 = (glFeature) => {
const areakm2 = (10 ** -6) * area(glFeature.geometry);
const formatted = areakm2.toLocaleString('en-US', { maximumFractionDigits: 0 });
return formatted;
};
function removeEmptyPolygon(geom) {
switch (geom.type) {
case 'Polygon':
if (area(geom) > 1) return geom;
return null;
case 'MultiPolygon':
var coordinates = [];
flattenEach(geom, function (feature) {
if (area(feature) > 1) coordinates.push(feature.geometry.coordinates);
});
if (coordinates.length) return {type: 'MultiPolygon', coordinates: coordinates};
}
}
var properties = options.properties || {};
var units = options.units || 'kilometers';
var features = [];
featureEach(dataset, function (feature) {
features.push(centroid(feature));
});
var n = features.length;
var observedMeanDistance = features.map(function (feature, index) {
var otherFeatures = featureCollection(features.filter(function (f, i) {
return i !== index;
}));
return distance(feature, nearestPoint(feature, otherFeatures), {units: units});
}).reduce(function (sum, value) { return sum + value; }, 0) / n;
var populationDensity = n / convertArea(area(studyArea), 'meters', units);
var expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));
var variance = 0.26136 / (Math.sqrt(n * populationDensity));
studyArea.properties = properties;
studyArea.properties.nearestNeighborAnalysis = {
units: units,
arealUnits: units + '²',
observedMeanDistance: observedMeanDistance,
expectedMeanDistance: expectedMeanDistance,
nearestNeighborIndex: observedMeanDistance / expectedMeanDistance,
numberOfPoints: n,
zScore: (observedMeanDistance - expectedMeanDistance) / variance
};
return studyArea;
}
const getAreaKm2 = (glFeature) => {
const areakm2 = (10 ** -6) * area(glFeature.geometry);
const formatted = areakm2.toLocaleString('en-US', { maximumFractionDigits: 0 });
return formatted;
};
(taskGeojson) => {
let taskArea = 0;
if (taskGeojson) {
taskArea = area(taskGeojson);
}
return taskArea;
});