helper_functions/polygonsCenters/polygonsCenters.js
/**
 * For each feature, computes its center and returns a new FeatureCollection \
 * that contains the feature' centers in their properties
 * 
 * @param {FeatureCollection} coords FeatureCollection - without feature' centers 
 * @param {number} precision - round centers to given places after comma
 * @returns {FeatureCollection} FeatureCollection that contains feature' centers in their properties
 */
For each feature, computes its center and returns a new FeatureCollection \
that contains the feature' centers in their properties

@param {FeatureCollection} coords FeatureCollection - without feature' centers
@param {number} precision - round centers to given places after comma
@returns {FeatureCollection} FeatureCollection that contains feature' centers in their properties
For each feature computes its center and returns a new FeatureCollection \ that contains the feature ' centers in their properties @param { FeatureCollection } coords FeatureCollection - without feature ' centers @param { number } precision - round centers to given places after comma @returns { FeatureCollection } FeatureCollection that contains feature ' centers in their properties
function generateFeaturesWithCenters(coords, precision) {
    const newFeatureCollectionArr = [];
    let mainArea;
    featureEach(coords, (curr, idx) => {
        if (curr.geometry.type === "MultiPolygon") {
            const maxAreaIndex = findMaxAreaIndex(curr);
            mainArea = curr.geometry.coordinates[maxAreaIndex];
        }
        else {
            mainArea = curr.geometry.coordinates;
        }
        let mainAreaCenter = centroid(polygon(mainArea)).geometry.coordinates;
        mainAreaCenter = mainAreaCenter.map((coord) => parseFloat(coord.toFixed(precision)));
        curr.properties.center = mainAreaCenter;
        curr.properties.id = idx;
        newFeatureCollectionArr.push(curr);
    })
    return featureCollection(newFeatureCollectionArr);
}
function generateFeaturesWithCenters ( coords , precision ) { const newFeatureCollectionArr = [ ] ; let mainArea ; featureEach ( coords , ( curr , idx ) => { if ( curr . geometry . type === "MultiPolygon" ) { const maxAreaIndex = findMaxAreaIndex ( curr ) ; mainArea = curr . geometry . coordinates [ maxAreaIndex ] ; } else { mainArea = curr . geometry . coordinates ; } let mainAreaCenter = centroid ( polygon ( mainArea ) ) . geometry . coordinates ; mainAreaCenter = mainAreaCenter . map ( ( coord ) => parseFloat ( coord . toFixed ( precision ) ) ) ; curr . properties . center = mainAreaCenter ; curr . properties . id = idx ; newFeatureCollectionArr . push ( curr ) ; } ) return featureCollection ( newFeatureCollectionArr ) ; }
For each feature, computes its center and returns a new FeatureCollection \
 that contains the feature' centers in their properties
For each feature computes its center and returns a new FeatureCollection \ that contains the feature ' centers in their properties
// Ignore empty features  // if (!curr.geometry) {return;} // For MultiPolyon treat the largest area as the main area // Find the center of the feature and round it // Add caululated centeroid to the feature's properties // Update polygon id (fixes incorrect ids in oryginal geojson file)