@Override public void rollback() { // Remove the transformed image from temporary storage if (target.deleteIfExists()) { log.trace("Deleted {}", target); } }
@Override public void finalise() { if (isCleanupSource()) { // Remove the source images from upload or temporary storage for (GraphicsFile sourceImage : source) { // Delete source image if (sourceImage.deleteIfExists()) { log.trace("Deleted {}", sourceImage); } } } if (isCleanupTarget()) { // Remove the transformed image from temporary storage if (target.deleteIfExists()) { log.trace("Deleted {}", target); } } }
@Override public void execute() throws TaskException { if (isCheckSource()) { if (getSource().isEmpty()) { // During import if no input images then throws exception throw new TaskException(getDescription(), Constant.ERR_NO_INPUT_IMAGES); } } else { if (getSource().isEmpty()) { // During export if no input images, still allow transformation task to finish. // As there is no input images, gdalwarp won't be performed and // therefore the target image won't exist. // An example: when timeslice contains no tiles during export. log.debug("Source is empty; will not transform."); return; } } // Initialize command parameter list command = new ArrayList<String>(); command.add("gdalwarp"); // Set the target projection (SRS) when applicable if (target.getEpsgId() > -1) { command.add("-t_srs"); command.add("EPSG:" + target.getEpsgId()); } else { if (target.getSrs() != null && !target.getSrs().isEmpty()) { command.add("-t_srs"); command.add(target.getSrs()); } } // Override the target extents when applicable if (getExtents() != null) { command.add("-te"); command.add(Double.toString(getExtents().getXMin())); command.add(Double.toString(getExtents().getYMin())); command.add(Double.toString(getExtents().getXMax())); command.add(Double.toString(getExtents().getYMax())); } else { // Target extents if (getTarget().getBounds() != null) { command.add("-te"); command.add(Double.toString(getTarget().getBounds().getXMin())); command.add(Double.toString(getTarget().getBounds().getYMin())); command.add(Double.toString(getTarget().getBounds().getXMax())); command.add(Double.toString(getTarget().getBounds().getYMax())); } } // Set the target resolution when applicable if (getTarget().getResolution() != null) { command.add("-tr"); command.add(Double.toString(getTarget().getResolution().toDouble())); command.add(Double.toString(getTarget().getResolution().toDouble())); } // Sampling method command.add("-r"); if (useBilinearInterpolation) command.add("bilinear"); else command.add("near"); // Output format (e.g. netCDF, GTiff) command.add("-of"); command.add(target.getFormat().toGdalString()); if (datatype != null) { command.add("-ot"); command.add(datatype.getGdalDataType()); } // Override srcnodata metadata (or lack thereof) if (srcnodata != null && !srcnodata.isEmpty()) { command.add("-srcnodata"); command.add(srcnodata); } // Override dstnodata metadata (or lack thereof) if (dstnodata != null && !dstnodata.isEmpty()) { command.add("-dstnodata"); command.add(dstnodata); } // Add extra options such as Mosaicking options, Memory management options addExtraOptions(command); // Creation options (e.g. compression) for (String co : target.getFormat().getCreationOptions()) { command.add("-co"); command.add(co); } // Input files boolean sourceExist = false; for (GraphicsFile gf : source) { // If graphic file not found, don't add it into gdalwarp sourcefiles if (!gf.exists()) { continue; } sourceExist = true; command.add(gf.getFileLocation().toString()); } // Extra check here to capture missing parameter earlier if (!sourceExist) { String strSource = StringUtils.join(source, "\n"); throw new TaskException(getDescription(), "Source file not exist:\n" + strSource); } // Output file command.add(target.getFileLocation().toString()); try { // If source is raster dataset // If source is vector dataset commandUtil.start(command); } catch (ProcessException | InterruptedException | IOException e) { throw new TaskException(getDescription(), e); } }