Kettle 使用Json输入

时间:2022-10-30 14:52:31
 import java.math.BigDecimal;
 private static final String JD="jd";
 private static final String WD="wd";

 public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException{
        if(first) {
            first = false;
        }
        Object[] r = getRow();
        if (r == null) {
            setOutputDone();
            return false;
        }

        //维度
        String wdstr = get(Fields.In, WD).getString(r);
        //经度
        String jdstr = get(Fields.In, JD).getString(r);
        if(!isArray(wdstr)||!isArray(jdstr)){
           return true;
        }
        get(Fields.Out, WD).setValue(r, getCovNewVlaue(wdstr));
        get(Fields.Out, JD).setValue(r, getCovNewVlaue(jdstr));

        putRow(data.outputRowMeta, r);
        return true;
  }

 private double getCovNewVlaue(String dustr) {
        String replace =  dustr.replace("N", "").replace("E", "");
        String[] duArray = replace.split(" ");
        double duValue = Double.parseDouble(duArray[0]);
        double minuteValue = Double.parseDouble(duArray[1]);
        double secondValue = Double.parseDouble(duArray[2]);

        BigDecimal minute = BigDecimal.valueOf(minuteValue).divide(BigDecimal.valueOf(60), 10,
                BigDecimal.ROUND_HALF_DOWN);
        BigDecimal second = BigDecimal.valueOf(secondValue).divide(BigDecimal.valueOf(3600), 10,
                BigDecimal.ROUND_HALF_DOWN);
        BigDecimal newVlaue = BigDecimal.valueOf(duValue).add(minute).add(second);
        return newVlaue.doubleValue();
    }

 private boolean isArray(String dustr){
        return dustr.split(" ").length==1?false:true;
 }

Kettle 使用Json输入