Mercurial > dive4elements > river
changeset 4639:79827cd334d5
Use moving average algorithm to calculate average values depending on the zoom
level.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 04 Dec 2012 15:41:02 +0100 |
parents | 6122ee2ab67f |
children | e3f28be45103 |
files | flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffEpochFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffYearFacet.java |
diffstat | 2 files changed, 61 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffEpochFacet.java Tue Dec 04 15:39:50 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffEpochFacet.java Tue Dec 04 15:41:02 2012 +0100 @@ -6,8 +6,12 @@ import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.access.RiverAccess; +import de.intevation.flys.artifacts.context.FLYSContext; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.MovingAverage; +import de.intevation.flys.artifacts.model.ZoomScale; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; @@ -32,9 +36,33 @@ CalculationResult res = (CalculationResult) flys.compute(context, hash, stateId, type, false); - Object[] data = + BedDiffEpochResult[] data = (BedDiffEpochResult[]) res.getData(); // TODO CAST TO SPECIFIC CLASS + Double start = (Double)context.getContextValue("startkm"); + Double end = (Double)context.getContextValue("endkm"); + if(start != null && end != null) { + FLYSContext fc = (FLYSContext)context.globalContext(); + ZoomScale scales = (ZoomScale)fc.get("zoomscale"); + RiverAccess access = new RiverAccess((FLYSArtifact)artifact); + String river = access.getRiver(); + + double radius = scales.getRadius(river, start, end); + BedDiffEpochResult oldData = data[index]; + BedDiffEpochResult newData = new BedDiffEpochResult(); + newData.setStart(oldData.getStart()); + newData.setEnd(oldData.getEnd()); + double[][] diffs = MovingAverage.weighted(oldData.getDifferencesData(), radius); + double[][] heights1 = MovingAverage.weighted(oldData.getHeights1Data(), radius); + double[][] heights2 = MovingAverage.weighted(oldData.getHeights2Data(), radius); + for(int j = 0; j < diffs[0].length; j++) { + newData.addKm(diffs[0][j]); + newData.addDifference(diffs[1][j]); + newData.addHeight1(heights1[1][j]); + newData.addHeight2(heights2[1][j]); + } + return newData; + } return data != null && data.length > index ? data[index] : null; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffYearFacet.java Tue Dec 04 15:39:50 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedDiffYearFacet.java Tue Dec 04 15:41:02 2012 +0100 @@ -6,8 +6,12 @@ import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.access.RiverAccess; +import de.intevation.flys.artifacts.context.FLYSContext; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.MovingAverage; +import de.intevation.flys.artifacts.model.ZoomScale; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; @@ -32,9 +36,36 @@ CalculationResult res = (CalculationResult) flys.compute(context, hash, stateId, type, false); - Object[] data = + BedDiffYearResult[] data = (BedDiffYearResult[]) res.getData(); // TODO CAST TO SPECIFIC CLASS + Double start = (Double)context.getContextValue("startkm"); + Double end = (Double)context.getContextValue("endkm"); + if(start != null && end != null) { + FLYSContext fc = (FLYSContext)context.globalContext(); + ZoomScale scales = (ZoomScale)fc.get("zoomscale"); + RiverAccess access = new RiverAccess((FLYSArtifact)artifact); + String river = access.getRiver(); + double radius = scales.getRadius(river, start, end); + BedDiffYearResult oldData = data[index]; + BedDiffYearResult newData = new BedDiffYearResult(); + newData.setStart(oldData.getStart()); + newData.setEnd(oldData.getEnd()); + double[][] diffs = MovingAverage.weighted(oldData.getDifferencesData(), radius); + double[][] heights1 = MovingAverage.weighted(oldData.getHeights1Data(), radius); + double[][] heights2 = MovingAverage.weighted(oldData.getHeights2Data(), radius); + double[][] morph = oldData.getMorphWidthData(); + double[][] year = MovingAverage.weighted(oldData.getHeightPerYearData(), radius); + for(int j = 0; j < diffs[0].length; j++) { + newData.addKm(diffs[0][j]); + newData.addBedHeights(year[1][j]); + newData.addMorphWidth(morph[1][j]); + newData.addDifference(diffs[1][j]); + newData.addHeight1(heights1[1][j]); + newData.addHeight2(heights2[1][j]); + } + return newData; + } return data != null && data.length > index ? data[index] : null; }