import org.esa.snap.core.datamodel.Band; //导入方法依赖的package包/类
@Override
protected void addBands(Product product, SpotDimapMetadata componentMetadata, int componentIndex) {
String[] bandNames = componentMetadata.getBandNames();
String[] bandUnits = componentMetadata.getBandUnits();
int width, height, currentW, currentH;
width = product.getSceneRasterWidth();
height = product.getSceneRasterHeight();
currentW = componentMetadata.getRasterWidth();
currentH = componentMetadata.getRasterHeight();
if (width == currentW && height == currentH) {
try {
if (SpotConstants.DIMAP.equals(componentMetadata.getFormatName())) {
String[] fileNames = componentMetadata.getRasterFileNames();
if (fileNames == null || fileNames.length == 0) {
throw new InvalidMetadataException("No raster file found in metadata");
}
String rasterFileName = componentMetadata.getPath().toLowerCase().replace(componentMetadata.getFileName().toLowerCase(), fileNames[0].toLowerCase());
File rasterFile = productDirectory.getFile(rasterFileName);
GeoTiffProductReader tiffReader = new GeoTiffReaderEx(getReaderPlugIn());
logger.info("Read product nodes");
Product tiffProduct = tiffReader.readProductNodes(rasterFile, null);
if (tiffProduct != null) {
if (product == null) {
product = createProduct(tiffProduct.getSceneRasterWidth(), tiffProduct.getSceneRasterHeight(), wrappingMetadata.getComponentMetadata(0));
}
MetadataElement tiffMetadata = tiffProduct.getMetadataRoot();
if (tiffMetadata != null) {
XmlMetadata.CopyChildElements(tiffMetadata, product.getMetadataRoot());
}
tiffProduct.transferGeoCodingTo(product, null);
product.setPreferredTileSize(tiffProduct.getPreferredTileSize());
int numBands = tiffProduct.getNumBands();
String bandPrefix = "";
logger.info("Read bands");
if (wrappingMetadata.hasMultipleComponents()) {
bandPrefix = "scene_" + String.valueOf(componentIndex) + "_";
String groupPattern = "";
for (int idx = 0; idx groupPattern += "scene_" + String.valueOf(idx) + ":";
}
groupPattern = groupPattern.substring(0, groupPattern.length() - 1);
product.setAutoGrouping(groupPattern);
}
for (int idx = 0; idx Band srcBand = tiffProduct.getBandAt(idx);
String bandName = bandPrefix + (idx Band targetBand = new ColorPaletteBand(bandName, srcBand.getDataType(), product.getSceneRasterWidth(), product.getSceneRasterHeight(), this.colorPaletteFilePath);
targetBand.setNoDataValue(componentMetadata.getNoDataValue() > -1 ? componentMetadata.getNoDataValue() : srcBand.getNoDataValue());
targetBand.setNoDataValueUsed((componentMetadata.getNoDataValue() > -1));
targetBand.setSpectralWavelength(componentMetadata.getWavelength(idx) > 0 ? componentMetadata.getWavelength(idx) : srcBand.getSpectralWavelength());
targetBand.setSpectralBandwidth(componentMetadata.getBandwidth(idx) > 0 ? componentMetadata.getBandwidth(idx) : srcBand.getSpectralBandwidth());
targetBand.setScalingFactor(srcBand.getScalingFactor());
targetBand.setScalingOffset(srcBand.getScalingOffset());
targetBand.setSolarFlux(srcBand.getSolarFlux());
targetBand.setUnit(srcBand.getUnit() != null ? srcBand.getUnit() : bandUnits[idx]);
targetBand.setSampleCoding(srcBand.getSampleCoding());
targetBand.setImageInfo(srcBand.getImageInfo());
targetBand.setSpectralBandIndex(srcBand.getSpectralBandIndex());
targetBand.setDescription(bandName);
product.addBand(targetBand);
readBandStatistics(targetBand, idx, componentMetadata);
bandMap.put(targetBand, srcBand);
}
}
} else {
logger.warning(String.format("Component product %s is not in DIMAP format!", componentMetadata.getProductName()));
}
} catch (IOException ioEx) {
logger.severe("Error while reading component: " + ioEx.getMessage());
}
} else {
logger.warning(String.format("Cannot add component product %s due to raster size [Found: %d x %d pixels, Expected: %d x %d pixels]",
componentMetadata.getProductName(), currentW, currentH, width, height));
}
}