@Override public void apply(ImportTask task, ImportData data) throws Exception { boolean inline = isInline(); File executable = getExecutable(); File inputFile = getInputFile(data); Map<String, File> substitutions = new HashMap<>(); substitutions.put("input", inputFile); File outputFile = null; if (!inline) { outputDirectory = getOutputDirectory(data); outputFile = new File(outputDirectory, inputFile.getName()); substitutions.put("output", outputFile); cmd.setSubstitutionMap(substitutions); setupCommandLine(inline, cmd); execute(cmd, null); List<String> names = getReplacementTargetNames(data); File inputParent = inputFile.getParentFile(); for (String name : names) {
protected boolean checkAvailable() throws IOException { try { CommandLine cmd = new CommandLine(getExecutable()); for (String option : getAvailabilityTestOptions()) { cmd.addArgument(option);
@Override protected void setupCommandLine(boolean inline, CommandLine cmd) { super.setupCommandLine(inline, cmd); for (Integer level : levels) { cmd.addArgument(String.valueOf(level)); } }
/** * The directory used for outputs, by default, a subdirectory of the input file parent * * @param data * @throws IOException */ protected File getOutputDirectory(ImportData data) throws IOException { File input = getInputFile(data); File parent = input.getParentFile(); File tempFile = File.createTempFile("tmp", null, parent); tempFile.delete(); if (!tempFile.mkdir()) { throw new IOException("Could not create work directory " + tempFile.getAbsolutePath()); } return tempFile; }
protected void setupCommandLine(boolean inline, CommandLine cmd) { for (String option : options) { cmd.addArgument(option, false); } // setup input and output files if (inline) { cmd.addArgument("${input}", false); } else { if (isOutputAfterInput()) { cmd.addArgument("${input}", false); cmd.addArgument("${output}", false); } else { cmd.addArgument("${output}", false); cmd.addArgument("${input}", false); } } }
@Override public void apply(ImportTask task, ImportData data) throws Exception { // let the transform run super.apply(task, data); // see if we need to update the layer definition, we just changed the CRS after all LayerInfo layer = task.getLayer(); ResourceInfo resource = layer.getResource(); String originalSRS = resource.getSRS(); // do so only if it's a direct import if (layer.getId() != null || resource == null || resource.getCatalog() == null) { return; } DataFormat format = DataFormat.lookup(((FileData) data).getFile()); List<ImportTask> tasks = format.list(data, resource.getCatalog(), new ProgressMonitor()); if (tasks == null || tasks.isEmpty()) { return; } LayerInfo updatedLayer = tasks.get(0).getLayer(); ResourceInfo updatedResource = updatedLayer.getResource(); String updatedSRS = updatedResource.getSRS(); // check if the layer srs is incompatible with the one we just reprojected to, update if // necessary if (originalSRS == null || (!originalSRS.equals(updatedSRS) && updatedSRS != null)) { resource.setSRS(updatedSRS); resource.setNativeCRS(updatedResource.getNativeCRS()); resource.setNativeBoundingBox(updatedResource.getNativeBoundingBox()); resource.setLatLonBoundingBox(updatedResource.getLatLonBoundingBox()); } }