/** * Factory method that creates an instance of this class from a set of minimal patterns to be respected, * and also a set of exclusion patterns. * * @param minimalPatterns The set of patterns to be checked. * @param notAcceptedPatterns The set of exclusion patterns to be checked. Pass <code>null</code> if you * do not want to have such a check. * @return A new <code>ProductContentEnforcer</code> instance. */ public static ProductContentEnforcer create(String[] minimalPatterns, String[] notAcceptedPatterns) { return new ProductContentEnforcer(minimalPatterns, notAcceptedPatterns); }
/** * Returns the list of files in a folder using NIO API. * * @param basePath The parent folder * @return The list of files * @throws IOException */ public static List<Path> listFiles(Path basePath) throws IOException { return listFiles(basePath, 1); }
@Override public SnapFileFilter getProductFileFilter() { return new BaseProductFileFilter(this, folderDepth); }
VirtualDirEx virtualDir; try { virtualDir = getInput(input); if (virtualDir != null) { String[] files = null; if (enforcer.isConsistent(files)) { retVal = DecodeQualification.INTENDED; Pattern[] patternList = enforcer.getMinimalFilePatternList(); File inputFile = getFileInput(input); if (inputFile.isFile() && Arrays.stream(patternList).anyMatch(p -> p.matcher(inputFile.getName()).matches())) { virtualDir.setFolderDepth(folderDepth); files = virtualDir.listAll(patternList); if (files.length >= patternList.length && enforcer.isConsistent(files)) { retVal = DecodeQualification.INTENDED;
private void addGMLMasks(Product target, ImageMetadata metadata) { List<ImageMetadata.MaskInfo> gmlMasks = metadata.getMasks(); final Iterator<Color> colorIterator = ColorIterator.create(); Band refBand = findReferenceBand(target, metadata.getRasterWidth()); boolean isMultiSize = this.metadata.getImageMetadataList().size() > 1; gmlMasks.stream().forEach(mask -> { logger.info(String.format("Parsing mask %s of component %s", mask.name, metadata.getFileName())); VectorDataNode node = GMLReader.parse(mask.name, mask.path); if (node != null && node.getFeatureCollection().size() > 0) { node.setOwner(target); String maskName = mask.name; if (isMultiSize) { String resolution = "_" + new DecimalFormat("#.#").format(metadata.getPixelSize()) + "m"; maskName += resolution.endsWith(".") ? resolution.substring(0, resolution.length() - 1) : resolution; } if (refBand != null) { target.addMask(maskName, node, mask.description, colorIterator.next(), 0.5, refBand); } else { target.addMask(mask.name, node, mask.description, colorIterator.next(), 0.5); } } }); }
public File getFileInput(Object input) { return super.getFileInput(input); }
public BaseProductFileFilter(BaseProductReaderPlugIn plugIn, int folderDepth) { super(plugIn.getFormatNames()[0], plugIn.getDefaultFileExtensions(), plugIn.getDescription(Locale.getDefault())); this.processed = new HashMap<>(); this.depth = folderDepth; }
protected GeoTiffBasedReader(ProductReaderPlugIn readerPlugIn, Path colorPaletteFilePath) { super(readerPlugIn); this.colorPaletteFilePath = colorPaletteFilePath; this.metadataClass = getTypeArgument(); registerMetadataParser(); registerSpi(); bandMap = new HashMap<>(); metadata = new ArrayList<>(); }
@Override public boolean accept(File file) { boolean shouldAccept = super.accept(file); if (shouldAccept && file.isFile() && !VirtualDirEx.isPackedFile(file)) { File folder = file.getParentFile(); if (!processed.containsKey(folder)) { try { List<String> files = listFiles(folder, depth); shouldAccept = enforcer.isConsistent(files); processed.put(folder, shouldAccept); } catch (IOException e) { Logger.getLogger(BaseProductFileFilter.class.getName()).warning(e.getMessage()); } } else { shouldAccept = processed.get(folder); } } return shouldAccept; }
@Override protected void addBands(Product product, DeimosMetadata componentMetadata, int componentIndex) { super.addBands(product, componentMetadata, componentIndex); if (DeimosConstants.PROCESSING_1R.equals(componentMetadata.getProcessingLevel())) { initGeoCoding(product); } }
public static VirtualPath transformToSentinel2VirtualPath (Path path) throws IOException{ VirtualPath virtualPath; if(VirtualDirEx.isPackedFile(path.toFile())) { VirtualDirEx virtualDirEx = VirtualDirEx.create(path.toFile()); if(virtualDirEx == null) { throw new IOException(String.format("Unable to read %s",path.toString())); } String folderName = PathUtils.getFileNameWithoutExtension(path); if(!folderName.endsWith(".SAFE")) { folderName = folderName +".SAFE"; } if(virtualDirEx.exists(folderName)) { virtualPath = new VirtualPath(folderName, virtualDirEx); } else { virtualPath = new VirtualPath(".", virtualDirEx); } } else { virtualPath = new VirtualPath(path); } return virtualPath; } }
/** * Computes the grouping of bands if the product has multiple raster files. * @return the grouping expression or an empty string if there is at most one raster file. */ protected String computeGroupPattern() { String groupPattern = ""; rasterFileNames = getRasterFileNames(); if (rasterFileNames.size() > 1) { for (int idx = 0; idx < rasterFileNames.size(); idx++) { groupPattern += "scene_" + String.valueOf(idx) + ":"; } } return groupPattern.substring(0, groupPattern.length() - 1); }
@Override protected void readBandRasterDataImpl(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { Band sourceBand = bandMap.get(destBand); GeoTiffReaderEx reader = (GeoTiffReaderEx)sourceBand.getProductReader(); if (reader == null) { logger.severe("No reader found for band data"); } else { reader.readBandRasterDataImpl(sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, sourceStepX, sourceStepY, sourceBand, destOffsetX, destOffsetY, destWidth, destHeight, destBuffer, pm); } }
/** * Returns a wrapping VirtualDirEx object over the input product. * * @param input The reader input as received from the caller. * @return An instance of VirtualDirEx * @throws IOException */ protected VirtualDirEx getInput(Object input) throws IOException { File inputFile = getFileInput(input); if (inputFile.isFile() && !VirtualDirEx.isPackedFile(inputFile)) { final File absoluteFile = inputFile.getAbsoluteFile(); inputFile = absoluteFile.getParentFile(); if (inputFile == null) { throw new IOException(String.format("Unable to retrieve parent to file %s.", absoluteFile.getAbsolutePath())); } } return VirtualDirEx.create(inputFile); }
GDALMultiLevelSource(Path sourceFile, int bandIndex, int numBands, int imageWidth, int imageHeight, int tileWidth, int tileHeight, int levels, int dataBufferType, GeoCoding geoCoding) { super(new DefaultMultiLevelModel(levels, Product.findImageToModelTransform(geoCoding), imageWidth, imageHeight)); this.sourceFile = sourceFile; this.dataBufferType = dataBufferType; this.bandIndex = bandIndex; int numTilesX = imageWidth / tileWidth; if (imageWidth % tileWidth != 0) { numTilesX++; } int numTilesY = imageHeight / tileHeight; if (imageHeight % tileHeight != 0) { numTilesY++; } this.tileLayout = new TileLayout(imageWidth, imageHeight, tileWidth, tileHeight, numTilesX, numTilesY, levels); this.tileLayout.numBands = numBands; this.tileManager = new TileImageDisposer(); }
private void addGMLMasks(Product target, ImageMetadata metadata) { List<ImageMetadata.MaskInfo> gmlMasks = metadata.getMasks(); final Iterator<Color> colorIterator = ColorIterator.create(); Band refBand = findReferenceBand(target, metadata.getRasterWidth()); boolean isMultiSize = this.metadata.getImageMetadataList().size() > 1; gmlMasks.stream().forEach(mask -> { logger.info(String.format("Parsing mask %s of component %s", mask.name, metadata.getFileName())); VectorDataNode node = GMLReader.parse(mask.name, mask.path); if (node != null && node.getFeatureCollection().size() > 0) { node.setOwner(target); String maskName = mask.name; if (isMultiSize) { String resolution = "_" + new DecimalFormat("#.#").format(metadata.getPixelSize()) + "m"; maskName += resolution.endsWith(".") ? resolution.substring(0, resolution.length() - 1) : resolution; } if (refBand != null) { target.addMask(maskName, node, mask.description, colorIterator.next(), 0.5, refBand); } else { target.addMask(mask.name, node, mask.description, colorIterator.next(), 0.5); } } }); }
public File getFileInput(Object input) { return super.getFileInput(input); }
@Override public void close() throws IOException { //JAI.getDefaultInstance().getTileCache().flush(); if (product != null) { for (Band band : product.getBands()) { MultiLevelImage sourceImage = band.getSourceImage(); if (sourceImage != null) { sourceImage.reset(); sourceImage.dispose(); sourceImage = null; } } } List<Path> files = PathUtils.listFiles(tmpFolder); tmpFolder.toFile().deleteOnExit(); if (files != null) { for (Path file : files) { file.toFile().deleteOnExit(); } } super.close(); }
/** * Factory method that creates an instance of this class from a set of minimal patterns to be respected. * * @param minimalPatterns The set of patterns to be checked. * @return A new <code>ProductContentEnforcer</code> instance. */ public static ProductContentEnforcer create(String[] minimalPatterns) { return new ProductContentEnforcer(minimalPatterns, null); }
/** * Returns an abstraction of the given input. * If the input is a (not compressed or packed) file, it returns a <code>com.bc.ceres.core.VirtualDir.File</code> object. * If the input is a folder, it returns a <code>com.bc.ceres.core.VirtualDir.Dir</code> object. * If the input is either a tar file or a tgz file, it returns a <code>org.sa.beam.dataio.VirtualDirEx.TarVirtualDir</code> object. * If the input is a compressed file, it returns a wrapper over a <code>com.bc.ceres.core.VirtualDir.Zip</code> object. * @param input The input object * @return An instance of a VirtualDir or VirtualDirEx implementations. * @throws IOException If unable to retrieve the parent of the input. */ public VirtualDirEx getInput(Object input) throws IOException { File inputFile = getFileInput(input); if (inputFile.isFile() && !VirtualDirEx.isPackedFile(inputFile)) { final File absoluteFile = inputFile.getAbsoluteFile(); inputFile = absoluteFile.getParentFile(); if (inputFile == null) { throw new IOException("Unable to retrieve parent to file: " + absoluteFile.getAbsolutePath()); } } return VirtualDirEx.create(inputFile); }