private static boolean hasIndexCoding(Product product) { return product.getIndexCodingGroup().getNodeCount() > 0; }
protected void writeIndexCoding(int indent) { SampleCoding[] a = product.getIndexCodingGroup().toArray(new IndexCoding[0]); writeSampleCodings(indent, a, DimapProductConstants.TAG_INDEX_CODING, DimapProductConstants.TAG_INDEX, DimapProductConstants.TAG_INDEX_NAME, DimapProductConstants.TAG_INDEX_VALUE, DimapProductConstants.TAG_INDEX_DESCRIPTION); }
private static void setIndexCoding(Band band, IndexCoding indexCoding, boolean rename, String pattern) { if (indexCoding != null) { String indexCodingName = indexCoding.getName(); if (rename) { indexCodingName = pattern.replace(SOURCE_NAME_REFERENCE, indexCodingName); } final Product product = band.getProduct(); if (!product.getIndexCodingGroup().contains(indexCodingName)) { addIndexCoding(product, indexCoding, indexCodingName); } band.setSampleCoding(product.getIndexCodingGroup().get(indexCodingName)); } }
/** * Copies the index codings from the source product to the target. * * @param source the source product * @param target the target product */ public static void copyIndexCodings(Product source, Product target) { Guardian.assertNotNull("source", source); Guardian.assertNotNull("target", target); int numCodings = source.getIndexCodingGroup().getNodeCount(); for (int n = 0; n < numCodings; n++) { IndexCoding sourceFlagCoding = source.getIndexCodingGroup().get(n); copyIndexCoding(sourceFlagCoding, target); } }
private void copyIndexCoding() { final ProductNodeGroup<IndexCoding> indexCodingGroup = sourceProduct.getIndexCodingGroup(); for (int i = 0; i < indexCodingGroup.getNodeCount(); i++) { IndexCoding sourceIndexCoding = indexCodingGroup.get(i); ProductUtils.copyIndexCoding(sourceIndexCoding, targetProduct); } }
private static void setIndexCoding(Element element, Band band, Product product) { final String codingName = element.getChildTextTrim(DimapProductConstants.TAG_INDEX_CODING_NAME); if (codingName != null) { final IndexCoding indexCoding = product.getIndexCodingGroup().get(codingName); if (indexCoding != null) { band.setSampleCoding(indexCoding); } } }
protected void addIndexCodingsToProduct(Product product) { final ProductNodeGroup<IndexCoding> indexCodingGroup = getSourceProduct().getIndexCodingGroup(); for (int i = 0; i < indexCodingGroup.getNodeCount(); i++) { IndexCoding sourceIndexCoding = indexCodingGroup.get(i); IndexCoding destIndexCoding = new IndexCoding(sourceIndexCoding.getName()); destIndexCoding.setDescription(sourceIndexCoding.getDescription()); cloneIndexes(sourceIndexCoding, destIndexCoding); product.getIndexCodingGroup().add(destIndexCoding); } }
private static ImageInfo createIndexedImageInfo(Product product, Band band, IndexColorModel colorModel) { final IndexCoding indexCoding = new IndexCoding("color_map"); final int colorCount = colorModel.getMapSize(); final ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[colorCount]; for (int j = 0; j < colorCount; j++) { final String name = String.format("I%3d", j); indexCoding.addIndex(name, j, ""); points[j] = new ColorPaletteDef.Point(j, new Color(colorModel.getRGB(j)), name); } product.getIndexCodingGroup().add(indexCoding); band.setSampleCoding(indexCoding); return new ImageInfo(new ColorPaletteDef(points, points.length)); }
/** * Copies the given source index coding to the target product * If it exists already, the method simply returns the existing instance. * * @param sourceIndexCoding the source index coding * @param target the target product * * @return The index coding. */ public static IndexCoding copyIndexCoding(IndexCoding sourceIndexCoding, Product target) { IndexCoding indexCoding = target.getIndexCodingGroup().get(sourceIndexCoding.getName()); if (indexCoding == null) { indexCoding = new IndexCoding(sourceIndexCoding.getName()); indexCoding.setDescription(sourceIndexCoding.getDescription()); target.getIndexCodingGroup().add(indexCoding); copyMetadata(sourceIndexCoding, indexCoding); } return indexCoding; }
private static void addIndexCoding(Product product, IndexCoding indexCoding, String indexCodingName) { final IndexCoding targetIndexCoding = new IndexCoding(indexCodingName); targetIndexCoding.setDescription(indexCoding.getDescription()); ProductUtils.copyMetadata(indexCoding, targetIndexCoding); product.getIndexCodingGroup().add(targetIndexCoding); }
private static ImageInfo createIndexedImageInfo(Product product, TIFFRenderedImage baseImage, Band band) { final IndexColorModel colorModel = (IndexColorModel) baseImage.getColorModel(); final IndexCoding indexCoding = new IndexCoding("color_map"); final int colorCount = colorModel.getMapSize(); final ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[colorCount]; for (int j = 0; j < colorCount; j++) { final String name = String.format("I%3d", j); indexCoding.addIndex(name, j, ""); points[j] = new ColorPaletteDef.Point(j, new Color(colorModel.getRGB(j)), name); } product.getIndexCodingGroup().add(indexCoding); band.setSampleCoding(indexCoding); return new ImageInfo(new ColorPaletteDef(points, points.length)); }
private void handleIndexCoding(Band sourceBand, Band targetBand, boolean renameComponents, String renamePattern) { if(sourceBand.getIndexCoding() != null) { targetBand.getProduct().getIndexCodingGroup().remove(targetBand.getIndexCoding()); targetBand.setSampleCoding(null); } setIndexCoding(targetBand, sourceBand.getIndexCoding(), renameComponents, renamePattern); }
private static void addIndexCoding(Product product) { final IndexCoding indexCoding = new IndexCoding("Indexes"); indexCoding.addIndex("land", 12, "Land Index"); indexCoding.addIndex("bright", 13, "Bright Index"); product.getIndexCodingGroup().add(indexCoding); }
@Override public void decode(ProfileReadContext ctx, Product p) throws IOException { final Band[] bands = p.getBands(); for (Band band : bands) { String varName = EscapeStrings.backslashEscape(band.getName(), NetcdfFile.reservedSectionSpec); Variable variable = ctx.getNetcdfFile().findVariable(varName); final IndexCoding indexCoding = readIndexCoding(variable, band.getName()); if (indexCoding != null) { p.getIndexCodingGroup().add(indexCoding); band.setSampleCoding(indexCoding); } } }
@Override public void decode(ProfileReadContext ctx, Product p) throws IOException { final Band[] bands = p.getBands(); for (Band band : bands) { NetcdfFile netcdfFile = ctx.getNetcdfFile(); String variableName = ReaderUtils.getVariableName(netcdfFile, band); final Variable variable = netcdfFile.getRootGroup().findVariable(variableName); final IndexCoding indexCoding = readIndexCoding(variable, band.getName() + "_index_coding"); if (indexCoding != null) { p.getIndexCodingGroup().add(indexCoding); band.setSampleCoding(indexCoding); } } }
public ExpectedContent(Product product, Random random) { this(); this.sceneWidth = product.getSceneRasterWidth(); this.sceneHeight = product.getSceneRasterHeight(); final ProductData.UTC endTime = product.getEndTime(); if (endTime != null) { this.endTime = endTime.format(); } final ProductData.UTC startTime = product.getStartTime(); if (startTime != null) { this.startTime = startTime.format(); } this.geoCoding = createExpectedGeoCoding(product, random); this.flagCodings = createExpectedSampleCodings(product.getFlagCodingGroup()); this.indexCodings = createExpectedSampleCodings(product.getIndexCodingGroup()); this.tiePointGrids = createExpectedTiePointGrids(product, random); this.bands = createExpectedBands(product, random); this.masks = createExpectedMasks(product); this.metadata = createExpectedMetadata(product, random); }
@Test public void testSampleCodingRemovedInSubset() throws IOException { final ProductSubsetDef subsetDef = new ProductSubsetDef(); subsetDef.setNodeNames(new String[]{COLORED_BAND_NAME}); final Product subset = ProductSubsetBuilder.createProductSubset(product, subsetDef, "subset", ""); assertFalse(subset.getBandGroup().contains(INDEX_CODED_BAND_NAME)); assertTrue(subset.getBandGroup().contains(COLORED_BAND_NAME)); assertFalse(subset.getIndexCodingGroup().contains(INDEX_CODING_NAME)); }
@Test public void testSampleCodingPreservedInSubset() throws IOException { final ProductSubsetDef subsetDef = new ProductSubsetDef(); subsetDef.setNodeNames(new String[]{INDEX_CODED_BAND_NAME}); final Product subset = ProductSubsetBuilder.createProductSubset(product, subsetDef, "subset", ""); assertTrue(subset.getBandGroup().contains(INDEX_CODED_BAND_NAME)); assertFalse(subset.getBandGroup().contains(COLORED_BAND_NAME)); assertTrue(subset.getIndexCodingGroup().contains(INDEX_CODING_NAME)); }
private void attachIndexCodedBand() { final Band band = createDataBand(0, 1, INDEX_CODED_BAND_NAME); final IndexCoding indexCoding = new IndexCoding(INDEX_CODING_NAME); indexCoding.addIndex("i0", 0, "i0"); indexCoding.addIndex("i1", 1, "i1"); band.setSampleCoding(indexCoding); ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[2]; points[0] = new ColorPaletteDef.Point(0, Color.RED); points[1] = new ColorPaletteDef.Point(1, Color.GREEN); ColorPaletteDef colors = new ColorPaletteDef(points); band.setImageInfo(new ImageInfo(colors)); product.getIndexCodingGroup().add(indexCoding); product.addBand(band); }
@Test public void testCopyIndexCoding() { final IndexCoding originalIndexCoding = new IndexCoding("sesame street characters"); originalIndexCoding.addIndex("erni", 0, "erni character"); originalIndexCoding.addIndex("bert", 1, "bert character"); final Product product = new Product("S", "S", 0, 0); ProductUtils.copyIndexCoding(originalIndexCoding, product); final ProductNodeGroup<IndexCoding> indexCodingGroup = product.getIndexCodingGroup(); assertNotNull(indexCodingGroup); assertEquals(1, indexCodingGroup.getNodeCount()); final IndexCoding actualIndexCoding = indexCodingGroup.get("sesame street characters"); assertNotNull(actualIndexCoding); assertNotSame(originalIndexCoding, actualIndexCoding); assertMetadataAttributeEqualityInt(originalIndexCoding.getIndex("erni"), actualIndexCoding.getIndex("erni")); assertMetadataAttributeEqualityInt(originalIndexCoding.getIndex("bert"), actualIndexCoding.getIndex("bert")); // try to copy the same coding a second time ProductUtils.copyIndexCoding(originalIndexCoding, product); assertEquals(1, indexCodingGroup.getNodeCount()); }