private void maybeCopyIndexCoding(Band sourceBand, Band targetBand) { IndexCoding sourceCoding = sourceBand.getIndexCoding(); if (sourceCoding != null) { IndexCoding targetCoding = getTargetProduct().getIndexCodingGroup().get(sourceCoding.getName()); if (targetCoding == null) { targetCoding = ProductUtils.copyIndexCoding(sourceCoding, getTargetProduct()); } targetBand.setSampleCoding(targetCoding); } }
protected void addIndexCodingAndBitmasks(Band smBand) { final IndexCoding coding = new IndexCoding("SM_coding"); final MetadataAttribute land = coding.addSample("LAND", 0, "Not cloud, shadow or edge AND land"); final MetadataAttribute flooded = coding.addSample("FLOODED", 1, "Not land and not cloud, shadow or edge"); final MetadataAttribute suspect = coding.addSample("SUSPECT", 2, "Cloud shadow or cloud edge"); final MetadataAttribute cloud = coding.addSample("CLOUD", 3, "Cloud"); final MetadataAttribute water = coding.addSample("WATER", 4, "Not land"); final MetadataAttribute snow = coding.addSample("SNOW", 5, "Snow"); final MetadataAttribute invalid = coding.addSample("INVALID", 6, "Invalid"); final Product product = smBand.getProduct(); product.getIndexCodingGroup().add(coding); smBand.setSampleCoding(coding); final ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[] { new ColorPaletteDef.Point(0, Color.GREEN.darker(), "land"), new ColorPaletteDef.Point(1, Color.BLUE, "flooded"), new ColorPaletteDef.Point(2, Color.ORANGE, "suspect"), new ColorPaletteDef.Point(3, Color.GRAY, "cloud"), new ColorPaletteDef.Point(4, Color.BLUE.darker(), "water"), new ColorPaletteDef.Point(5, Color.LIGHT_GRAY, "snow"), new ColorPaletteDef.Point(6, Color.RED, "invalid") }; smBand.setImageInfo(new ImageInfo(new ColorPaletteDef(points))); addMask(land, "SM == 0", Color.GREEN.darker(), product); addMask(flooded, "SM == 1", Color.BLUE, product); addMask(suspect, "SM == 2", Color.ORANGE, product); addMask(cloud, "SM == 3", Color.GRAY, product); addMask(water, "SM == 4", Color.BLUE.darker(), product); addMask(snow, "SM == 5", Color.LIGHT_GRAY, product); addMask(invalid, "SM == 6", Color.RED, product); }
protected void addBandsToProduct(Product product) { Debug.assertNotNull(getSourceProduct()); Debug.assertNotNull(product); for (int i = 0; i < getSourceProduct().getNumBands(); i++) { Band sourceBand = getSourceProduct().getBandAt(i); String bandName = sourceBand.getName(); if (isNodeAccepted(bandName)) { Band destBand; boolean treatVirtualBandsAsRealBands = false; if (getSubsetDef() != null && getSubsetDef().getTreatVirtualBandsAsRealBands()) { treatVirtualBandsAsRealBands = true; } // @todo 1 se/se - extract copy of a band or virtual band to create deep clone of band and // virtual band if (!treatVirtualBandsAsRealBands && sourceBand instanceof VirtualBand) { VirtualBand virtualSource = (VirtualBand) sourceBand; destBand = new VirtualBand( bandName, sourceBand.getDataType(), getSceneRasterWidth(), getSceneRasterHeight(), virtualSource.getExpression()); } else { destBand = new Band( bandName, sourceBand.getDataType(), getSceneRasterWidth(), getSceneRasterHeight()); } if (sourceBand.getUnit() != null) { destBand.setUnit(sourceBand.getUnit()); } if (sourceBand.getDescription() != null) { destBand.setDescription(sourceBand.getDescription()); } destBand.setScalingFactor(sourceBand.getScalingFactor()); destBand.setScalingOffset(sourceBand.getScalingOffset()); destBand.setLog10Scaled(sourceBand.isLog10Scaled()); destBand.setSpectralBandIndex(sourceBand.getSpectralBandIndex()); destBand.setSpectralWavelength(sourceBand.getSpectralWavelength()); destBand.setSpectralBandwidth(sourceBand.getSpectralBandwidth()); destBand.setSolarFlux(sourceBand.getSolarFlux()); if (sourceBand.isNoDataValueSet()) { destBand.setNoDataValue(sourceBand.getNoDataValue()); } destBand.setNoDataValueUsed(sourceBand.isNoDataValueUsed()); destBand.setValidPixelExpression(sourceBand.getValidPixelExpression()); FlagCoding sourceFlagCoding = sourceBand.getFlagCoding(); IndexCoding sourceIndexCoding = sourceBand.getIndexCoding(); if (sourceFlagCoding != null) { String flagCodingName = sourceFlagCoding.getName(); FlagCoding destFlagCoding = product.getFlagCodingGroup().get(flagCodingName); Debug.assertNotNull( destFlagCoding); // should not happen because flag codings should be already in // product destBand.setSampleCoding(destFlagCoding); } else if (sourceIndexCoding != null) { String indexCodingName = sourceIndexCoding.getName(); IndexCoding destIndexCoding = product.getIndexCodingGroup().get(indexCodingName); Debug.assertNotNull( destIndexCoding); // should not happen because index codings should be already in // product destBand.setSampleCoding(destIndexCoding); } else { destBand.setSampleCoding(null); } if (isFullScene(getSubsetDef()) && sourceBand.isStxSet()) { copyStx(sourceBand, destBand); } product.addBand(destBand); bandMap.put(destBand, sourceBand); } } for (final Map.Entry<Band, RasterDataNode> entry : bandMap.entrySet()) { copyImageInfo(entry.getValue(), entry.getKey()); } }