utils/geometry/geometry-helpers.js

"use strict";
/**
 * @namespace geoHelpers
 * @description Helper functions for working with geographic data.
 *
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.flattenGeometryRings = flattenGeometryRings;
/**
* Helper function to flatten geometry rings.
* Flattens nested coordinate arrays to simplify processing.
*
* @memberof geoHelpers
* @function flattenGeometryRings
* @param {object} geometry - Geometry object containing coordinates.
* @returns {object} A geometry object with flattened coordinates.
* @example
* const geometry = flattenGeometryRings({
*   coordinates: [[[0, 0], [10, 0]], [[10, 10], [0, 10]]]
* });
* console.log(geometry.coordinates); // [[0, 0], [10, 0], [10, 10], [0, 10]]
*/
function flattenGeometryRings(geometry) {
    const { coordinates } = geometry;
    console.log("Coordinates count:", coordinates.length);
    if (coordinates.length > 1) {
        /** Flatten the nested arrays */
        return {
            coordinates: coordinates.flat()
        };
    }
    // If the format is already valid, return it as is
    return {
        coordinates
    };
}