pm.beginTask("Collecting stats...", IProgressMonitor.UNKNOWN);
StringBuilder regionString = new StringBuilder();
GridCoverage2D geodata = null;
if (object instanceof AbstractRasterGeoResource) {
AbstractRasterGeoResource rGeo = (AbstractRasterGeoResource) object;
AbstractGridCoverage2DReader gridCoverage2DReader = rGeo.resolve(
AbstractGridCoverage2DReader.class, pm);
geodata = ((GridCoverage2D) gridCoverage2DReader.read(null));
geodata = geodata.view(ViewType.GEOPHYSICS);
Envelope envelope = geodata.getEnvelope();
DirectPosition lowerCorner = envelope.getLowerCorner();
double[] westSouth = lowerCorner.getCoordinate();
DirectPosition upperCorner = envelope.getUpperCorner();
double[] eastNorth = upperCorner.getCoordinate();
GridGeometry2D gridGeometry = geodata.getGridGeometry();
GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
int rows = gridRange.height;
int cols = gridRange.width;
AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
double we_res = XAffineTransform.getScaleX0(gridToCRS);
double ns_res = XAffineTransform.getScaleY0(gridToCRS);
double north = eastNorth[1];
double south = westSouth[1];
double east = eastNorth[0];
double west = westSouth[0];
regionString.append("region:\nwest=");
regionString.append(west);
regionString.append("\neast=");
regionString.append(east);
regionString.append("\nsouth=");
regionString.append(south);
regionString.append("\nnorth=");
regionString.append(north);
regionString.append("\nwe_res=");
regionString.append(we_res);
regionString.append("\nns_res=");
regionString.append(ns_res);
regionString.append("\nrows=");
regionString.append(rows);
regionString.append("\ncols=");
regionString.append(cols);
} else if (object instanceof JGrassMapGeoResource) {
JGrassMapGeoResource mr = (JGrassMapGeoResource) object;
File mapFile = mr.getMapFile();
JGrassMapEnvironment mapEnvironment = new JGrassMapEnvironment(mapFile);
JGrassRegion jGrassRegion = mapEnvironment.getActiveRegion();
int cols = jGrassRegion.getCols();
int rows = jGrassRegion.getRows();
double north = jGrassRegion.getNorth();
double south = jGrassRegion.getSouth();
double east = jGrassRegion.getEast();
double west = jGrassRegion.getWest();
double we_res = jGrassRegion.getWEResolution();
double ns_res = jGrassRegion.getNSResolution();
regionString.append("region:\nwest=");
regionString.append(west);
regionString.append("\neast=");
regionString.append(east);
regionString.append("\nsouth=");
regionString.append(south);
regionString.append("\nnorth=");
regionString.append(north);
regionString.append("\nwe_res=");
regionString.append(we_res);
regionString.append("\nns_res=");
regionString.append(ns_res);
regionString.append("\nrows=");
regionString.append(rows);
regionString.append("\ncols=");
regionString.append(cols);
GeneralParameterValue[] readParams = createGridGeometryGeneralParameter(cols, rows, north, south,
east, west, mapEnvironment.getCoordinateReferenceSystem());
AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory().createFormat();
AbstractGridCoverage2DReader reader = format.getReader(mapEnvironment.getCELL());
geodata = ((GridCoverage2D) reader.read(readParams));
geodata = geodata.view(ViewType.GEOPHYSICS);
} else {
MessageDialog.openInformation(shell, "WARNING", "Unable to read format");
return;
}