/** * 将普通经纬度数组转换为标准的 MULTIPOLYGON WKT 格式 * @param {Array>} coordinates - 经纬度数组,每个元素是一个 [经度, 纬度] 的点 * @returns {string} 标准化的 WKT 格式字符串 */ export function convertToWKT(coordinates) { // 检查输入是否为非空数组 if (!Array.isArray(coordinates) || coordinates.length === 0) { throw new Error("Invalid input: 'coordinates' must be a non-empty array of [longitude, latitude] points."); } // 检查每个点是否是有效的 [经度, 纬度] 数组 for (const point of coordinates) { if (!Array.isArray(point) || point.length !== 2 || typeof point[0] !== "number" || typeof point[1] !== "number") { throw new Error("Invalid input: Each coordinate must be an array of two numbers [longitude, latitude]."); } } // 将经纬度数组转换为 WKT 格式的坐标字符串 const wktCoordinates = coordinates .map(([longitude, latitude]) => `${longitude} ${latitude}`) .join(","); // 构建标准的 MULTIPOLYGON WKT 格式 return `MULTIPOLYGON(((${wktCoordinates})))`; }