import * as turf from '@turf/turf'; /** * 坐标 */ export interface Coordinate { lng: number; lat: number; distanceFromPrevious?: number; distanceFromStart?: number; gcToPrevious?: boolean; speed?: number; sog?: number; hourFromPrevious?: number; bearing?: number; cog?: number; important?: boolean; suspend?: number; velocity?: number; pilot?: boolean; positionTime?: number; utc?: string; name?: string; description?: string; port?: number; stbd?: number; arrRad?: number; rot?: number; turnRad?: number; timeZone?: string; timeZoneDir?: string; } export declare class LaneHelper { private static ecaPolygons; /** * 计算方位角 * @param from 坐标 {lng, lat} * @param to 坐标 {lng, lat} * @param rhumb true 横向方位角,false 大圆方位角 * @param precision * @returns {number} 单位度 */ static calculateBearing(from: Coordinate, to: Coordinate, rhumb?: boolean, precision?: number): number; /** * 计算两点间距离 * @param from 坐标 {lng, lat} * @param to 坐标 {lng, lat} * @param rhumb true 横向距离,false 大圆距离 * @param precision * @param units 单位,默认 nm(海里) * @returns {number} */ static calculateDistance(from: Coordinate, to: Coordinate, rhumb?: boolean, precision?: number, units?: string): number; /** * 计算航线距离 * @param route * @param precision * @param units */ static calculateRouteDistance(route: number[][][], precision?: number, units?: string): number; /** * 计算坐标(基于方位角和距离) * @param from 坐标 {lng, lat} * @param bearing 方位角,单位度 * @param distance 距离 * @param units 单位,默认 nm(海里) * @param rhumb */ static calculateCoordinate(from: Coordinate, bearing: number, distance: number, units?: any, rhumb?: boolean): { lng: number; lat: number; }; /** * 插值大圆坐标(基于两点方位角和间距) * @param from 坐标 {lng, lat} * @param to 坐标 {lng, lat} * @param spacing 间距 * @param includeHead true 包含起点 from * @param includeTail true 包含终点 to * @param units 单位,默认 nm(海里) */ static interpolateCoordinates(from: Coordinate, to: Coordinate, spacing: number, includeHead?: boolean, includeTail?: boolean, units?: string): { lng: number; lat: number; }[]; /** * 分组坐标(如相邻两个坐标经度差超180度,需以180为界将坐标分为两组) * @param coordinates * @param rhumb * @param deduplicate 去重 * @example * coordinates: [{lng: 160,lat: 30}, {lng: 170, lat: 40},{lng: -170, lat: 40},{lng: -160, lat: 30}] * @return [ * [[160, 30],[170,40]], * [[-170,40],[-160,30]] * ] */ static divideAccordingToLng(coordinates: Coordinate[], rhumb?: boolean, deduplicate?: boolean): number[][][]; /** * 去除重复坐标 * @param route */ static deduplicateRoute(route: number[][][]): any; /** * 去除重新坐标 * @param coordinates */ static deduplicateCoordinates(coordinates: Array): Array; /** * 移出坐标 * @param coordinate {lng, lat} * @param route 航线[[[lng, lat],[lng, lat]]] */ static removeCoordinateFromRoute(coordinate: Coordinate, route: number[][][]): number[][][]; /** * 移出坐标 * @param coordinate {lng, lat} * @param waypoints [{lat, lng}, {lat, lng}] */ static removeCoordinateFromWaypoints(coordinate: Coordinate, waypoints: Coordinate[]): Coordinate[]; /** * 合并坐标进航线(基于坐标到线段最短距离边合并) * @param coordinate 待合并的坐标 {lng, lat} * @param route 航线[[[lng, lat],[lng, lat]]] * @example * coordinate {lng: 122, lat: 35} * * route: [[[120, 30], [125,40], [130, 37]], [[-150, 40], [-130, 30]]] * @return * [[[120, 30], [120, 35], [125,40], [130, 37]], [[-150, 40], [-130, 30]]] */ static mergeCoordinateToRoute(coordinate: Coordinate, route: number[][][]): number[][][]; /** * 向Route尾加1个坐标 * @param coordinate * @param route */ static appendCoordinateToRoute(coordinate: Coordinate, route: number[][][]): number[][][]; /** * 向route头加1个坐标 * @param coordinate * @param route */ static unshiftCoordinateToRoute(coordinate: Coordinate, route: number[][][]): number[][][]; /** * 合并多个waypoints进航线 * @param waypoints [{lat, lng}, {lat, lng}] * @param route 航线 [[[lng, lat],[lng, lat]]] */ static mergeWaypointsToRoute(waypoints: Coordinate[], route: number[][][]): number[][][]; /** * 计算区间航线 * @param from {lng, lat} * @param to {lng, lat} * @param route [[[lng, lat]]] * @return [[[lng, lat]]] */ static calculateRangeRoute(from: Coordinate, to: Coordinate, route: number[][][]): number[][][]; /** * 计算from到to之间的航线 * @param from {lng, lat} * @param to {lng, lat} * @param route * @param waypoints * @return [{lng, lat}] */ static calculateRangeWaypoints(from: Coordinate, to: Coordinate, route: number[][][], waypoints?: Coordinate[]): any[]; /** * 计算坐标到航路上的最短距离 * @param from * @param route */ static calculateMinDistanceToRoute(from: Coordinate, route: number[][][]): { minDist: number; segIndex: number; minIndex: number; }; /** * 计算子航线 * @param from {lng, lat} 起始位置 * @param route * @return [[[lng, lat]]] */ static calculateSubRoute(from: Coordinate, route: number[][][]): number[][][]; /** * 计算子途经点 * @param from {lng, lat} 起始位置 * @param waypoints * @return [{lng, lat}] */ static calculateSubWaypoints(from: Coordinate, waypoints: Coordinate[]): Coordinate[]; /** * 计算坐标到以(from, to)横向线上的距离 * @param coordinate { lng, lat } * @param from { lng, lat } * @param to { lng, lat } * @param options */ static calculatePointToLineDistance(coordinate: Coordinate, from: Coordinate, to: Coordinate, options?: { units: any; method: any; }): number; /** * 计算途经点的COG, Distance等属性 * @param waypoints * @param route */ static calculateWaypointsPropInRoute(waypoints: Coordinate[], route: number[][][]): Coordinate[]; /** * @param coordinates [{lng, lat}] * @param waypoints [{lng, lat}] * @param replace true replace the same waypoint with coordinate */ static mergeCoordinatesToWaypoints(coordinates: Coordinate[], waypoints: Coordinate[], replace?: boolean): Coordinate[]; /** * 合并坐标进航路途经点 * @param coordinate 坐标 {lng, lat} * @param waypoints 途经点 [{lng, lat}, {lng, lat}] * * @example * coordinate: { lng: 179, lat: 50 } * waypoints: [{ lng: 160, lat: 30}, { lng: 170, lat: 40}, {lng: -170, lat: 40}, {lng: -160, lat: 30}] * @param replace true replace the same waypoint with coordinate * @return * [{ lng: 160, lat: 30}, { lng: 170, lat: 40}, {lng: 179, lat: 50}, {lng: -170, lat: 40}, {lng: -160, lat: 30}] */ static mergeCoordinateToWaypoints(coordinate: Coordinate, waypoints: Coordinate[], replace?: boolean): Coordinate[]; /** * 生成航线(基于途经点生成大圆/横向航线,并根据是否跨180度分组) * @return [[[lng, lat], [lng, lat]]] * @param waypoints * @param rhumb true 基于横向计算180经度焦点, false 基于大圆计算180经度焦点 * @param deduplicate true 去重 */ static generateRouteAccordingToWaypoints(waypoints: Coordinate[], rhumb?: boolean, deduplicate?: boolean): number[][][]; /** * 最近点(从route中找出距离目标点最近的点) * @param coordinate 目标点 {lng, lat} * @param route */ static nearestCoordinateInRoute(coordinate: Coordinate, route: number[][][]): { lng: number; lat: number; }; /** * 计算经过方向上的最后一个waypoint * @param from * @param waypoints */ static calculatePrevWaypoint(from: Coordinate, waypoints: Coordinate[]): Coordinate; /** * 计算下一个距离单位的坐标及其子航线 * @param from 起点坐标 {lng, lat} * @param distance 航行距离 * @param route [[[lng, lat]]] * @param units * @return { coordinate: {lng, lat}, route: [[[lng, lat]]]} */ static calculateNextCoordinateAlongRoute(from: Coordinate, distance: number, route: number[][][], units?: string): any; /** * 返回最近点及其是否为垂足(最近点不是起点或终点) * @param coordinate { lng, lat } * @param from {lng, lat} * @param to {lng, lat} */ static nearestCoordinateInLine(coordinate: Coordinate, from: Coordinate, to: Coordinate): { lng: number; lat: number; inline: boolean; from: Coordinate; to: Coordinate; }; /** * 将route转coordinate * @param route * @param distance 临近点过虑 */ static convertRouteToCoordinates(route: number[][][], distance?: number): Coordinate[]; /** * 抽稀(基于转向点) * @param route [[lng, lat]] * @param waypoints [{ lng, lat, gcToPrevious }] * @param distance */ static simplifyRouteToCoordinates(route: number[][][], waypoints: Coordinate[], distance?: number): Coordinate[]; /** * 基于大圆标识抽稀 * @param coordinates * @param waypoints */ static simplifyGCCoordinates(coordinates: Coordinate[], waypoints: Coordinate[]): Coordinate[]; /** * 计算轨迹中心点 * @param route */ static calculateCenter(route: number[][][]): { lng: number; lat: number; }; /** * 计算中心点 * @param coords */ static calculateCenter2(coords: Coordinate[]): { lng: number; lat: number; }; /** * 计算BBox * @param route */ static calculateBBox(route: number[][][]): turf.helpers.BBox; /** * 计算BBox * @param coords */ static calculateBBox2(coords: Coordinate[]): turf.helpers.BBox; /** * 抽稀 三点抽稀, 对比A,B,C; 基于三点距离及夹角抽稀 * @param coordinates * @param minDistance * @param minAngle */ static simplifyCoordinates(coordinates: Coordinate[], minDistance?: number, minAngle?: number): Coordinate[]; /** * 在时间轨迹上寻找ts最近的点 * @param ts ts最近的点(向后取), 单位秒 * @param step 时间步长, 前后n小时 * @param waypoints 带时间的轨迹, 单位秒 * @deprecated */ static nearestTSPointInWaypoints(ts: number, step: number, waypoints: Coordinate[]): Coordinate | undefined; /** * 推测船位 * @param ts 目标时间的船位,单位 s * @param positions 带时间(positionTime)的轨迹 */ static deadReckoning(ts: number, positions: Coordinate[]): any; /** * 推测船位时间 * @param coordinate * @param positions 必须要有 positionTime或utc */ static deadReckoningTime(coordinate: Coordinate, positions: Coordinate[]): Coordinate | undefined; /** * 翻转轨迹 * @param route */ static reverseRoute(route: number[][][]): number[][][]; /** * 翻转坐标 * @param coordinates */ static reverseCoordinates(coordinates: Coordinate[]): Coordinate[]; /** * 计算AIRoute * @param from * @param to * @param options */ static calculateAIRoute(from: Coordinate, to: Coordinate, options?: { requestId?: string; open?: string; close?: string; timeout?: number; simplify?: boolean; distance?: number; angle?: number; mock?: boolean; }): Promise; /** * 重新加载AI路由数据 * @param options */ static reloadAIRoute(options: { requestId: string; }): Promise; /** * 用于从 OSS 加载 ECA 区域。 */ private static initEcaZone; /** * 判断路径是否与ECA区域相交 * @param path * @return 返回相交的区域 * [ * { * distance: number, * waypoints: Coordinate[], * name: string * } * ] * 如果没有相交区域,返回空数组。 */ static intersectInECA(path: Coordinate[] | number[][][]): Promise; /** * XML转义 * @param s */ static xmlEscape(s: any): string; /** * 路径转RTZ 1.2 * @param name 路径名称 * @param waypoints 途径点 * @see https://cirm.org/rtz-xml-schemas * @see https://cirm.org/api/documents/download/64?documents/October2022/bWjrTyyfNGseK9ch3TKf.xsd * */ static waypoints2RTZ(name: string, waypoints: Coordinate[]): string; /** * 路径转RTZ 1.0 * @param name 路径名称 * @param waypoints 途径点 * @see https://cirm.org/rtz-xml-schemas */ static waypoints2RTZ10(name: string, waypoints: Coordinate[], withExtensions?: boolean): string; static toRTZWaypoints(waypoints: Coordinate[], precision?: number, withExtensions?: boolean): string[]; /** * 路径导出为 XLSX (Office Open XML 格式,无需第三方依赖) * 兼容 Excel 2007+、LibreOffice、Google Sheets、WPS、macOS Numbers 等所有现代表格软件 * const buf = LaneHelper.waypoints2XLSX('route-name', waypoints, { precision: 6 }) * 浏览器下载 * const blob = new Blob([buf], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) * @param name 工作表名称 * @param waypoints 途径点 * @param options.precision 经纬度小数位数,默认6 * @returns Uint8Array 二进制数据 */ static waypoints2XLSX(name: string, waypoints: Coordinate[], options?: { precision?: number; }): Uint8Array; /** * 路径转通用CSV (纯十进制度数、无厂商头、RFC 4180标准) * 大部分海图设备/导航软件均可导入此格式 * @param name 兼容旧版本 * @param waypoints 途径点 * @param options.precision 经纬度小数位数,默认6 */ static waypoints2CSV(name: string, waypoints: Coordinate[], options?: { precision?: number; }): string; /** * 路径导出为 JRC ECDIS CSV 格式 * 符合 JRC ECDIS 路由表导入/导出规范 * @param name 航线名称 * @param waypoints 途径点 * @param options.precision 经纬度分钟小数位数,默认3 */ static waypoints2JRCCSV(name: string, waypoints: Coordinate[], options?: { precision?: number; }): string; /** * RFC 4180 CSV字段转义:含逗号、双引号、换行时用双引号包裹,内部双引号翻倍 */ static csvEscapeField(value: any): string; /** * 十进制度数转NMEA度分格式 (DDMM.MM / DDDMM.MM) * @param value 十进制度数 * @param isLat true为纬度,false为经度 */ static decimalToNmeaDm(value: number, isLat: boolean): { dm: string; dir: string; }; /** * 计算NMEA 0183校验和 ($与*之间所有字符的异或,两字符十六进制大写) * @param sentence $与*之间的字符串 */ static nmeaChecksum(sentence: string): string; /** * 路径转NMEA 0183 WPL航点语句 * @param waypoints 途径点 * @returns 多条$GPWPL语句,以\r\n分隔 */ static waypoints2NMEA(waypoints: Coordinate[]): string; /** * 路径摘要 * @param coordinates 已排序的坐标 * @param slowSpd 慢速航速,单位节 * @return { * begin: string, // 开始时间 * end: string, // 结束时间 * distance: number, // 航行距离,单位海里 * hours: number, // 航行时间,单位小时 * avgSpeed: number // 平均航速,单位节 * } */ static coordinatesSummary(coordinates: Coordinate[], slowSpd?: number): any; /** * 查询特定时间的船位及航行区间 * @param utc * @param speed * @return { * routes: [], * hour: Coordinate * } */ static pickUTCSampleFromSpeed(utc: string, speed: any): any; /** * 查询特定时间的船位及航行区间 * @param utc 目标时间, UTC格式 * @param from 起点, 包含speed, etd, lat, lng * @param route * @return { * routes: [], * hour: Coordinate * } */ static pickUTCSampleFromRoute(utc: string, from: { lat: number; lng: number; speed: number; etd: string; }, route: any[]): any; /** * 船舶航首向与其它要素的夹角 * @param bearing 航首向 * @param degree 要素角度,如 swell.degree */ static includedAngle(bearing: number, degree: number): number; }