diff --git a/src/ac/ed/lurg/landuse/LandUseItem.java b/src/ac/ed/lurg/landuse/LandUseItem.java index 94c2d60d7038dd83911c718b0c39acc6d0fc9048..3f6b6b05429ba49ca19df97f0aacaa1955afbb2b 100644 --- a/src/ac/ed/lurg/landuse/LandUseItem.java +++ b/src/ac/ed/lurg/landuse/LandUseItem.java @@ -220,22 +220,35 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem> { cropFractions = new HashMap<CropType, Double>(); landCoverAreas = new HashMap<LandCoverType, Double>(); - for (CropType crop : CropType.values()) { - Double from = fromItem.cropFractions.get(crop); - Double to = toItem.cropFractions.get(crop); - Double d = Interpolator.interpolate(from, to, factor); - cropFractions.put(crop, d); - - Intensity fromIntensity = fromItem.intensityMap.get(crop); - Intensity toIntensity = toItem.intensityMap.get(crop); - Intensity interpolateIntensity = toIntensity; // might still be null - - if (fromIntensity != null && toIntensity != null) - interpolateIntensity = new Intensity(fromIntensity, toIntensity, factor); // both non-null really interpolate - else if (fromIntensity != null) - interpolateIntensity = fromIntensity; // just fromIntensity non-null - - intensityMap.put(crop, interpolateIntensity); + Double fromCropCover = fromItem.landCoverAreas.get(LandCoverType.CROPLAND); + Double toCropCover = toItem.landCoverAreas.get(LandCoverType.CROPLAND); + + if (fromCropCover != 0 && toCropCover == 0) { // if start with crop but end with none, take starting crop fractions + cropFractions.putAll(fromItem.cropFractions); + intensityMap.putAll(fromItem.intensityMap); + } + else if (fromCropCover == 0 && toCropCover != 0) { // if start with no crop but end with some, take end crop fractions + cropFractions.putAll(toItem.cropFractions); + intensityMap.putAll(toItem.intensityMap); + } + else { // otherwise we need to interpolate crop fractions + for (CropType crop : CropType.values()) { + Double from = fromItem.cropFractions.get(crop); + Double to = toItem.cropFractions.get(crop); + Double d = Interpolator.interpolate(from, to, factor); + cropFractions.put(crop, d); + + Intensity fromIntensity = fromItem.intensityMap.get(crop); + Intensity toIntensity = toItem.intensityMap.get(crop); + Intensity interpolateIntensity = toIntensity; // might still be null + + if (fromIntensity != null && toIntensity != null) + interpolateIntensity = new Intensity(fromIntensity, toIntensity, factor); // both non-null really interpolate + else if (fromIntensity != null) + interpolateIntensity = fromIntensity; // just fromIntensity non-null + + intensityMap.put(crop, interpolateIntensity); + } } for (LandCoverType landCover : LandCoverType.values()) {