protected List<Mask> createMasksFromFlagCodding(Product product, FlagCoding flagCoding) { String flagCodingName = flagCoding.getName(); ArrayList<Mask> masks = new ArrayList<>(); final int width = product.getSceneRasterWidth(); final int height = product.getSceneRasterHeight(); for (String flagName : flagCoding.getFlagNames()) { MetadataAttribute flag = flagCoding.getFlag(flagName); masks.add(Mask.BandMathsType.create(flagName, flag.getDescription(), width, height, flagCodingName + "." + flagName, ColorIterator.next(), 0.5)); } return masks; }
/** * Creates and adds masks to the product, by using the given flag coding. Each added mask uses the width and the height of the product. * * @param product the product on which the masks are added * @param flagCoding for each flag of this flagCoding parameter, a new mask is added, with the same name as the flag * @return the list of all the masks added to the product */ List<Mask> createMasksFromFlagCodding(Product product, FlagCoding flagCoding) { String flagCodingName = flagCoding.getName(); ArrayList<Mask> masks = new ArrayList<Mask>(); final int width = product.getSceneRasterWidth(); final int height = product.getSceneRasterHeight(); for (String flagName : flagCoding.getFlagNames()) { MetadataAttribute flag = flagCoding.getFlag(flagName); masks.add(Mask.BandMathsType.create(flagName, flag.getDescription(), width, height, flagCodingName + "." + flagName, ColorIterator.next(), 0.5)); } return masks; }
private void copyBands(Product sourceProduct, Product targetProduct) { Guardian.assertNotNull("source", sourceProduct); Guardian.assertNotNull("target", targetProduct); ProductNodeGroup<FlagCoding> targetFCG = targetProduct.getFlagCodingGroup(); for (int iBand = 0; iBand < sourceProduct.getNumBands(); iBand++) { Band sourceBand = sourceProduct.getBandAt(iBand); if (!targetProduct.containsBand(sourceBand.getName())) { Band targetBand = copyBandScl(sourceBand.getName(), sourceProduct, sourceBand.getName(), targetProduct); if (sourceBand.isFlagBand()) { FlagCoding flgCoding = sourceBand.getFlagCoding(); if (!targetFCG.contains(flgCoding.getName())) { ProductUtils.copyFlagCoding(flgCoding, targetProduct); } if (targetBand != null) { targetBand.setSampleCoding(targetFCG.get(flgCoding.getName())); } } } } }
public static void createFlagMasks(Product targetProduct) { Guardian.assertNotNull("targetProduct", targetProduct); int w = targetProduct.getSceneRasterWidth(); int h = targetProduct.getSceneRasterHeight(); MyMaskColor mColor = new MyMaskColor(); ProductNodeGroup<Mask> tarMG = targetProduct.getMaskGroup(); ProductNodeGroup<FlagCoding> tarFCG = targetProduct.getFlagCodingGroup(); for (int node=0; node<tarFCG.getNodeCount(); node++){ FlagCoding fc = tarFCG.get(node); for (int i=0; i<fc.getNumAttributes(); i++){ MetadataAttribute f = fc.getAttributeAt(i); String expr = fc.getName() + "." + f.getName(); Mask m = Mask.BandMathsType.create(f.getName(), f.getDescription(), w, h, expr, mColor.next(), 0.5); tarMG.add(m); } } }
final IndexCoding sourceIndexCoding = sourceBand.getIndexCoding(); if (sourceFlagCoding != null) { final String flagCodingName = sourceFlagCoding.getName(); final FlagCoding destFlagCoding = targetProduct.getFlagCodingGroup().get(flagCodingName); targetBand.setSampleCoding(destFlagCoding);
Band contextBand = contextProduct.addBand(srcBand.getName(), srcBand.getDataType()); if (srcBand.isFlagBand()) { contextBand.setSampleCoding(contextProduct.getFlagCodingGroup().get(srcBand.getFlagCoding().getName()));