private void cleanSourceProducts() { for (Map.Entry<Product, List<Band>> entry : addedVariableBands.entrySet()) { for (Band band : entry.getValue()) { entry.getKey().removeBand(band); } } }
void removeAllVariableConfigBands(Product contextProduct) { Band[] bands = contextProduct.getBands(); for (Band band : bands) { if(band instanceof VariableConfigBand) { contextProduct.removeBand(band); } } }
@Override public void visit(VirtualBand virtualBand) { if (!product.isCompatibleBandArithmeticExpression(virtualBand.getExpression())) { product.removeBand(virtualBand); String pattern = "Virtual band ''{0}'' removed from output product because it is not applicable."; /*I18N*/ messages.add(MessageFormat.format(pattern, virtualBand.getName())); } else { checkRaster(virtualBand, "virtual band"); } }
@Override public void setEoVariableSelected(String variableName, boolean selected) { // set in metadata final MetadataElement[] variables = getVariableMetadataElements(); for (MetadataElement elem : variables) { if (elem.getAttributeString(VARIABLE_NAME).equals(variableName)) { elem.setAttributeString(VARIABLE_SELECTION, String.valueOf(selected)); } } // set in product if (selected) { for (Product product : getAllProducts(ProgressMonitor.NULL)) { addSpecifiedBandOfGivenProduct(variableName, product); } } else { final Band[] bands = tsProduct.getBands(); for (Band band : bands) { if (variableName.equals(rasterToVariableName(band.getName()))) { tsProduct.removeBand(band); } } } fireChangeEvent(new TimeSeriesChangeEvent(TimeSeriesChangeEvent.PROPERTY_EO_VARIABLE_SELECTION, null, this)); }
@Override public void removeProductLocation(ProductLocation productLocation) { // remove metadata final MetadataElement timeSeriesRootElement = tsProduct.getMetadataRoot().getElement(TIME_SERIES_ROOT_NAME); MetadataElement productLocationsElement = timeSeriesRootElement.getElement(PRODUCT_LOCATIONS); removeAttributeWithValue(PL_PATH, productLocation.getPath(), productLocationsElement); // remove variables for this productLocation updateAutoGrouping(); // TODO ??? final Band[] bands = tsProduct.getBands(); final MetadataElement sourceProductPaths = timeSeriesRootElement.getElement(SOURCE_PRODUCT_PATHS); for (Map.Entry<String, Product> productEntry : productLocation.getProducts(ProgressMonitor.NULL).entrySet()) { final Product product = productEntry.getValue(); removeAttributeWithValue(PL_PATH, productEntry.getKey(), sourceProductPaths); String timeString = formatTimeString(product); productTimeMap.remove(timeString); for (Band band : bands) { if (band.getName().endsWith(timeString)) { tsProduct.removeBand(band); } } } productLocation.closeProducts(); productLocationList.remove(productLocation); fireChangeEvent(new TimeSeriesChangeEvent(TimeSeriesChangeEvent.PROPERTY_PRODUCT_LOCATIONS, productLocationList, this)); }
@Override public void done() { if (VisatApp.getApp().getPreferences().getPropertyBool(VisatApp.PROPERTY_KEY_AUTO_SHOW_NEW_BANDS, true)) { try { Band[] bands = get(); if (bands == null) { return; } for (Band band : bands) { Band oldBand = product.getBand(band.getName()); if (oldBand != null) { product.removeBand(oldBand); } product.addBand(band); } } catch (Exception e) { VisatApp.getApp().showErrorDialog(DIALOG_TITLE, "An internal Error occurred:\n" + e.getMessage()); Debug.trace(e); } } } };
public static void storeRgbaExpressions(final Product product, final String[] rgbaExpressions) { for (int i = 0; i < RGBImageProfile.RGBA_BAND_NAMES.length; i++) { final String rgbBandName = RGBImageProfile.RGBA_BAND_NAMES[i]; final String rgbaExpression = rgbaExpressions[i]; final Band rgbBand = product.getBand(rgbBandName); final boolean expressionIsEmpty = rgbaExpression.equals(""); final boolean alphaChannel = i == 3; if (rgbBand != null) { // band already exists if (rgbBand instanceof VirtualBand) { VirtualBand virtualBand = (VirtualBand) rgbBand; virtualBand.setExpression(rgbaExpression); } else { product.removeBand(rgbBand); product.addBand(new VirtualBand(rgbBandName, ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), expressionIsEmpty ? "0" : rgbaExpression)); } } else { // band does not exist if (!alphaChannel || !expressionIsEmpty) { // don't add empty alpha channels product.addBand(new VirtualBand(rgbBandName, ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), expressionIsEmpty ? "0" : rgbaExpression)); } } } }
@Override public void customizeProduct(Product product) { product.removeBand(product.getBand("num_passes")); Band const3 = product.addBand("const3", ProductData.TYPE_INT32); int width = product.getSceneRasterWidth(); int height = product.getSceneRasterHeight(); const3.setSourceImage(ConstantDescriptor.create((float) width, (float) height, new Integer[]{3}, null)); } }
@Override public void setTimeCoding(TimeCoding timeCoding) { final ProductData.UTC startTime = timeCoding.getStartTime(); if (tsProduct.getStartTime().getAsCalendar().compareTo(startTime.getAsCalendar()) != 0) { tsProduct.setStartTime(startTime); fireChangeEvent(new TimeSeriesChangeEvent(TimeSeriesChangeEvent.START_TIME_PROPERTY_NAME, startTime, this)); } final ProductData.UTC endTime = timeCoding.getEndTime(); if (tsProduct.getEndTime().getAsCalendar().compareTo(endTime.getAsCalendar()) != 0) { tsProduct.setEndTime(endTime); fireChangeEvent(new TimeSeriesChangeEvent(TimeSeriesChangeEvent.END_TIME_PROPERTY_NAME, endTime, this)); } List<String> variables = getEoVariables(); for (Product product : getAllProducts(ProgressMonitor.NULL)) { for (String variable : variables) { if (isEoVariableSelected(variable)) { addSpecifiedBandOfGivenProduct(variable, product); } } } for (Band band : tsProduct.getBands()) { final TimeCoding bandTimeCoding = getRasterTimeMap().get(band); if (!timeCoding.contains(bandTimeCoding)) { fireChangeEvent(new TimeSeriesChangeEvent(TimeSeriesChangeEvent.BAND_TO_BE_REMOVED, band, this)); tsProduct.removeBand(band); } } }
@Test public void testModifiedFlagAfterBandHasBeenAddedAndRemoved() { Band band = new Band("band1", ProductData.TYPE_FLOAT32, _sceneWidth, _sceneHeight); assertEquals(null, product.getBand("band1")); // product.addBand(band); assertEquals(band, product.getBand("band1")); assertEquals("added band, modified flag should be set", true, product.isModified()); product.setModified(false); product.removeBand(band); assertEquals(null, product.getBand("band1")); assertEquals("removed band, modified flag should be set", true, product.isModified()); }
@Test public void testAddingRemovingProductNodes() { final Product product = createDummyProduct("x1"); productManager.addProduct(product); AbstractTN rootNode = treeModel.getRoot(); ProductTN productTN = (ProductTN) treeModel.getChild(rootNode, 0); assertEquals(0, treeModel.getChildCount(productTN)); final Band band1 = product.addBand("b1", ProductData.TYPE_INT8); assertEquals(1, treeModel.getChildCount(productTN)); final Object bandGroup = treeModel.getChild(productTN, 0); assertNotNull(bandGroup); assertEquals(1, treeModel.getChildCount(bandGroup)); assertSame(band1, ((ProductNodeTN) treeModel.getChild(bandGroup, 0)).getProductNode()); product.addBand("b2", ProductData.TYPE_INT8); assertEquals(2, treeModel.getChildCount(bandGroup)); product.removeBand(product.getBand("b2")); product.removeBand(product.getBand("b1")); assertEquals(0, treeModel.getChildCount(productTN)); }
targetProduct.removeTiePointGrid(targetProduct.getTiePointGrid("latGrid")); targetProduct.removeTiePointGrid(targetProduct.getTiePointGrid("lonGrid")); targetProduct.removeBand(targetProduct.getBand("latBand")); targetProduct.removeBand(targetProduct.getBand("lonBand")); targetProduct.removeBand(targetProduct.getBand("flagomat")); targetProduct.getFlagCodingGroup().removeAll(); sourceProduct.transferGeoCodingTo(targetProduct, def);
public void testSetProductToNullAfterNodeRemoval() { Band band = new Band("b", ProductData.TYPE_INT16, 10, 10); assertNull(band.getOwner()); assertNull(band.getProduct()); final Product p1 = new Product("p1", "t", 10, 10); p1.addBand(band); assertNotNull(band.getOwner()); assertSame(p1, band.getProduct()); p1.removeBand(band); assertNull(band.getOwner()); assertNull(band.getProduct()); final Product p2 = new Product("p2", "t", 10, 10); p2.addBand(band); assertNotNull(band.getOwner()); assertSame(p2, band.getProduct()); p2.removeBand(band); assertNull(band.getOwner()); assertNull(band.getProduct()); }
product.removeBand((Band) raster); } else if (raster instanceof TiePointGrid) { product.removeTiePointGrid((TiePointGrid) raster);
public void testSetOwnerToNullAfterNodeRemoval() { final ProductNode[] owners = new ProductNode[1]; final Product product = new Product("product", "t", 10, 10); product.addBand("band1", ProductData.TYPE_INT16); final Band addedBand = product.getBandAt(0); product.addProductNodeListener(new ProductNodeListenerAdapter() { @Override public void nodeRemoved(ProductNodeEvent event) { ProductNode sourceNode = event.getSourceNode(); assertSame(addedBand, sourceNode); assertNotNull(sourceNode.getOwner()); } }); assertNotNull(addedBand.getOwner()); assertSame(product, addedBand.getOwner().getProduct()); assertSame(product, addedBand.getProduct()); product.removeBand(addedBand); assertNull(addedBand.getProduct()); assertNull(addedBand.getOwner()); }
product.removeBand(b2); testIllegalArgumentExceptionThrownByConstructor(b1, b2, null, 7); product.removeBand(b1); testIllegalArgumentExceptionThrownByConstructor(b1, b2, null, 7);
@Test public void testWriteReadIndexCodingSingle8BitBand() throws IOException { outProduct.removeBand(outProduct.getBandAt(0)); final Band bandUInt8 = outProduct.addBand("uint8", ProductData.TYPE_UINT8); bandUInt8.setDataElems(createByteData(getProductSize(), 23)); ImageManager.getInstance().getSourceImage(bandUInt8, 0); setTiePointGeoCoding(outProduct); final IndexCoding indexCoding = new IndexCoding("color_map"); indexCoding.addIndex("i1", 23, ""); indexCoding.addIndex("i2", 24, ""); indexCoding.addIndex("i3", 27, ""); indexCoding.addIndex("i4", 30, ""); outProduct.getBandAt(0).setSampleCoding(indexCoding); outProduct.getIndexCodingGroup().add(indexCoding); final Product inProduct = writeReadProduct(); assertEquals(1, inProduct.getIndexCodingGroup().getNodeCount()); final Band indexBand = inProduct.getBandAt(0); testIndexCoding(indexBand, 4); }
p.removeBand(p.getBand("b1")); p.removeBand(p.getBand("b2")); p.removeBand(p.getBand("b3"));