类名 common/util/videoMap/VideoPixelCoordTransforms.js
import { VideoRegistrationParam } from "../../base";
import { Point } from '../../index'
import Log from "../Log";
import { GDALApplyGeoTransform, GDALGCPsToGeoTransform, GDALInvGeoTransform } from "./GDALCoordTransform";

/**
 * 像素坐标地理坐标转换类
 * @classdesc 像素坐标地理坐标转换类
 */
class VideoPixelCoordTransforms {
  constructor() {
    this._videoRegistrationParam = null
    this._gdalGCPsData = []
    this._toGeoTransforms = new Float64Array(6)
    this._invToGeoTransforms = new Float64Array(6)
  }
  /**
   * 初始化视频调绘坐标转换工具
   * @param {VideoRegistrationParam} videoRegistrationParam
   */
  init(videoRegistrationParam) {
    this._videoRegistrationParam = new VideoRegistrationParam(videoRegistrationParam)
    if (!this._videoRegistrationParam.calibrationParam || !this._videoRegistrationParam.calibrationParam.groundControlPointList) {
      Log.error('缺少标定配准转换数据')
      return
    }
    const groundControlPointList = this._videoRegistrationParam.calibrationParam.groundControlPointList;
    groundControlPointList.forEach(element => {
      const gdalData = {
        pszId: element.id,
        pszInfo: element.description,
        dfGCPPixel: element.pixelX,
        dfGCPLine: element.pixelY,
        dfGCPX: element.x,
        dfGCPY: element.y,
        dfGCPZ: element.z
      }
      this._gdalGCPsData.push(gdalData)
    });
    const result = GDALGCPsToGeoTransform(this._gdalGCPsData, this._toGeoTransforms, true)
    GDALInvGeoTransform(this._toGeoTransforms, this._invToGeoTransforms)
    // console.log('像素转地理矩阵:', this._toGeoTransforms)
    // console.log('地理转像素矩阵', this._invToGeoTransforms)
  }
  /**
   * 像素坐标转地理坐标
   * @param {Point} pixelCoord 像素坐标 
   * @returns {Point} 地理坐标
   */
  pixelCoordToGeoCoord(pixelCoord) {
    const { pdfGeoX: geox, pdfGeoY: geoy } = GDALApplyGeoTransform(
      this._toGeoTransforms,
      pixelCoord.coordinates[0],
      pixelCoord.coordinates[1]
    )
    const geoPos = new Point({
      coordinates: [geox, geoy]
    })
    // console.log(pixelCoord, ' 像素--->地理 ', geoPos)
    return geoPos
  }
  /**
   * 地理坐标转像素坐标
   * @param {Point} geoCoord 地理坐标
   * @returns {Point} 像素坐标
   */
  geoCoordToPixelCoord(geoCoord) {
    const { pdfGeoX: x, pdfGeoY: y } = GDALApplyGeoTransform(
      this._invToGeoTransforms,
      geoCoord.coordinates[0],
      geoCoord.coordinates[1]
    )
    const pixelCoord = new Point({
      coordinates: [x, y]
    })
    // console.log(geoCoord, ' 地理--->像素', pixelCoord)
    return pixelCoord
  }
}
export default VideoPixelCoordTransforms
构造函数
成员变量
方法
事件