gunshi-project-ss/src/main/java/com/gunshi/project/xyt/grb/RainGrib2Layer.java

156 lines
4.1 KiB
Java

package com.gunshi.project.xyt.grb;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
* Description:
* Created by wanyan on 2024/2/23
*
* @author wanyan
* @version 1.0
*/
@Data
public class RainGrib2Layer {
@Schema(description = "tmRange")
private TmRange tmRange;
@Schema(description = "data")
public BigDecimal[][] data;
@Schema(description = "图片base64数据")
private String base64;
@Schema(description = "x1")
private BigDecimal x1;
@Schema(description = "x2")
private BigDecimal x2;
@Schema(description = "y1")
private BigDecimal y1;
@Schema(description = "y2")
private BigDecimal y2;
@Schema(description = "dw")
private BigDecimal dw;
@Schema(description = "dh")
private BigDecimal dh;
@Schema(description = "nw")
private int nw;
@Schema(description = "nh")
private int nh;
// public RainGrib2Layer createSubset(Double bx1, Double by1, Double bx2, Double by2) {
// int ix1 = 0, ix2 = nw - 1, iy1 = 0, iy2 = nh - 1;
// if (bx1 != null && bx1 > x1) {
// ix1 = (int)((nw - 1) * (bx1 - x1) / (x2 - x1));
// }
// if (by1 != null && by1 > y1) {
// iy1 = (int)((nh - 1) * (by1 - y1) / (y2 - y1));
// }
// if (bx2 != null && bx2 < x2) {
// ix2 = (int)Math.ceil((nw - 1) * (bx2 - x1) / (x2 - x1));
// }
// if (by2 != null && by2 < y2) {
// iy2 = (int)Math.ceil((nh - 1) * (by2 - y1) / (y2 - y1));
// }
//
// RainGrib2Layer ret = new RainGrib2Layer();
//
// ret.tmRange = (TmRange) tmRange.clone();
// ret.x1 = x1 + ix1 * dw;
// ret.y1 = y1 + iy1 * dh;
// ret.x2 = x1 + ix2 * dw;
// ret.y2 = y1 + iy2 * dh;
// ret.nw = ix2 - ix1 + 1;
// ret.nh = iy2 - iy1 + 1;
// ret.dw = dw;
// ret.dh = dh;
// ret.data = new float[ret.nh][ret.nw];
// for (int iy = iy1; iy <= iy2; iy += 1) {
// for (int ix = ix1; ix <= ix2; ix += 1) {
// ret.data[iy - iy1][ix - ix1] = data[iy][ix];
// }
// }
//
// return ret;
// }
//
// boolean setContent(Grib2FrameParams frame, Grib2LayerParams layer, byte[] bin) {
// if (layer.calDataLen() != bin.length) {
// return false;
// }
//
// x1 = frame.x1;
// x2 = frame.x2;
// y1 = frame.y1;
// y2 = frame.y2;
// nw = frame.nw;
// nh = frame.nh;
// dw = frame.dw;
// dh = frame.dh;
// tmRange = (TmRange) layer.tmRange.clone();
// data = new float[nh][nw];
//
// float decimalScale = layer.getDecimalScale();
// float binaryScale = layer.getBinaryScale();
//
// boolean constValue = layer.numBits == 0;
// float RValue = layer.R;
//
// try {
// BitInputStream bis = new BitInputStream(new ByteArrayInputStream(bin),null);
// for (int iy = 0; iy < nh; iy++) {
// for (int ix = 0; ix < nw; ix++) {
// if (constValue) {
// data[iy][ix] = RValue;
// } else {
// long v = bis.readBits(layer.numBits);
// double value = decimalScale * (layer.R + v * binaryScale);
//
// data[iy][ix] = (float)value;
// }
// }
// }
// bis.close();
// return true;
// } catch (Exception e) {
// e.printStackTrace();
// return false;
// }
// }
//
// @Override
// public Object clone() {
// RainGrib2Layer ret = new RainGrib2Layer();
//
// ret.tmRange = (TmRange) tmRange.clone();
// ret.x1 = x1;
// ret.y1 = y1;
// ret.x2 = x2;
// ret.y2 = y2;
// ret.nw = nw;
// ret.nh = nh;
// ret.dw = dw;
// ret.dh = dh;
// ret.data = new float[nh][nw];
// for (int iy = 0; iy < nh; iy += 1) {
// for (int ix = 0; ix < nw; ix += 1) {
// ret.data[iy][ix] = data[iy][ix];
// }
// }
//
// return ret;
// }
}