*/
IRunnableWithProgress operation = new IRunnableWithProgress(){
public void run( IProgressMonitor pm ) throws InvocationTargetException, InterruptedException {
IGeoResource geoResource = mainPage.getGeoResource();
String folderPath = mainPage.getFolderPath();
String fileName = mainPage.getFileName();
String newPath = folderPath + File.separator + fileName;
CoordinateReferenceSystem fileCrs = mainPage.getFileCrs();
CoordinateReferenceSystem newCrs = mainPage.getNewCrs();
boolean isAscii = mainPage.isAscii();
boolean isTiff = mainPage.isTiff();
/*
* finally do some processing
*/
pm.beginTask("Exporting map...", IProgressMonitor.UNKNOWN);
try {
// TODO reactivate this as soon as netcdfs are back
// if (geoResource.canResolve(NetcdfMapGeoResource.class)) {
// NetcdfMapGeoResource netcdfGeoResource =
// geoResource.resolve(NetcdfMapGeoResource.class, pm);
// List<DateTime> availableTimeSteps =
// netcdfGeoResource.getAvailableTimeSteps();
// double[] availableElevationLevels =
// netcdfGeoResource.getAvailableElevationLevels();
//
// if (availableTimeSteps.size() == 0) {
// availableTimeSteps = new ArrayList<DateTime>();
// // add a dummy one to make sure it enters the loop
// availableTimeSteps.add(null);
// }
// if (availableElevationLevels == null || availableElevationLevels.length == 0)
// {
// availableElevationLevels = new double[1];
// // add a dummy one to make sure it enters the loop
// availableElevationLevels[0] = Double.NaN;
// }
//
// for( DateTime dateTime : availableTimeSteps ) {
// for( double currentElevationDouble : availableElevationLevels ) {
// CoverageReadRequest readRequest = new DefaultCoverageReadRequest();
//
// if (dateTime != null) {
// SortedSet<TemporalGeometricPrimitive> temporalSubset = new
// TreeSet<TemporalGeometricPrimitive>();
// temporalSubset.add(new DefaultInstant(new
// DefaultPosition(dateTime.toDate())));
// readRequest.setTemporalSubset(temporalSubset);
// }
// if (!Double.isNaN(currentElevationDouble)) {
// Set<NumberRange<Double>> verticalSubset = new TreeSet<NumberRange<Double>>();
// NumberRange<Double> vertical = new NumberRange<Double>(Double.class,
// currentElevationDouble,
// true, currentElevationDouble, true);
// verticalSubset.add(vertical);
// readRequest.setVerticalSubset(verticalSubset);
// }
//
// GridCoverage2D coverage2D = netcdfGeoResource.getGridCoverage(readRequest);
//
// StringBuilder sB = new StringBuilder(newPath);
// if (dateTime != null) {
// sB.append("_");
// sB.append(dateTime.toString(dateTimeFormatter));
// }
// if (!Double.isNaN(currentElevationDouble)) {
// sB.append("_");
// sB.append(currentElevationDouble);
// }
// String mapPath = sB.toString();
// pm.subTask("Exporting map: " + mapPath);
// dumpMap(coverage2D, fileCrs, newCrs, mapPath, isAscii, isTiff);
// }
// }
//
// } else
if (geoResource.canResolve(GridCoverage.class)) {
GridCoverage2D coverage2D = (GridCoverage2D) geoResource.resolve(GridCoverage.class, pm);
dumpMap(coverage2D, fileCrs, newCrs, newPath, isAscii, isTiff);
} else {
throw new IOException("The selected resource doesn't seem to be a coverage layer: " + geoResource.getTitle());
}
} catch (Exception e) {
e.printStackTrace();
String message = "An error occurred while exporting the resource: " + geoResource.getTitle();
ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, JGrassToolsPlugin.PLUGIN_ID, e);
}
pm.done();
}