use of org.geotools.coverage.grid.GridGeometry2D in project polymap4-core by Polymap4.
the class PredefinedColorMapEditor method main.
// Test ***********************************************
public static void main(String[] args) throws Exception {
File f = new File("/home/falko/Data/ncrast/elevation_4326.tif");
AbstractGridFormat format = GridFormatFinder.findFormat(f);
AbstractGridCoverage2DReader reader = format.getReader(f);
String[] names = reader.getGridCoverageNames();
GridCoverage2D grid = reader.read(names[0], null);
GridGeometry2D geometry = grid.getGridGeometry();
GridEnvelope gridRange = geometry.getGridRange();
int w = gridRange.getHigh(0);
int h = gridRange.getHigh(1);
// all
Timer timer = new Timer();
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
int c = 0;
double[] buf = new double[1];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
double[] value = grid.evaluate(new GridCoordinates2D(x, y), buf);
min = value[0] < min ? value[0] : min;
max = value[0] > max ? value[0] : max;
c++;
}
}
System.out.println("min/max: " + min + ".." + max + " (" + c + " in " + timer.elapsedTime() + "ms)");
// random
timer.start();
double[] minMax = new PredefinedColorMapEditor().minMax(grid);
System.out.println("min/max: " + minMax[0] + ".." + minMax[1] + " (" + c + " in " + timer.elapsedTime() + "ms)");
// final DefaultProcessor proc = new DefaultProcessor(null);
// for (Operation o : proc.getOperations() ){
// System.out.println(o.getName());
// System.out.println(o.getDescription());
// System.out.println();
// }
}
use of org.geotools.coverage.grid.GridGeometry2D in project OpenTripPlanner by opentripplanner.
the class SyntheticRasterPopulation method createIndividuals.
@Override
public void createIndividuals() {
try {
coverageCRS = CRS.decode(crsCode, true);
} catch (Exception e) {
LOG.error("error decoding coordinate reference system code.", e);
return;
}
if (boundsFromGraph) {
// autowire graph service or pass in
}
gridEnvelope = new GridEnvelope2D(0, 0, cols, rows);
refEnvelope = new ReferencedEnvelope(left, right, bottom, top, coverageCRS);
gridGeometry = new GridGeometry2D(gridEnvelope, refEnvelope);
super.createIndividuals0();
}
use of org.geotools.coverage.grid.GridGeometry2D in project polymap4-core by Polymap4.
the class PredefinedColorMap method minMax.
/**
* Row/col iteration.
*
* @deprecated Slower than {@link #minMax3(GridCoverage2D, IProgressMonitor)} and
* white-locks sometimes for unknown reason.
* @return double[] {min, max, novalue}
*/
protected double[] minMax(GridCoverage2D grid, IProgressMonitor monitor) {
// really, someday I have to learn about all this stuff :/
GridGeometry2D geometry = grid.getGridGeometry();
GridEnvelope gridRange = geometry.getGridRange();
int w = gridRange.getHigh(0);
monitor.beginTask("calculating min/max", w);
@SuppressWarnings("hiding") double // see OmsRasterReader
novalue = -9999.0;
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
// FIXME http://github.com/Polymap4/polymap4-p4/issues/129 does not come to an end
// without the limit
double[] values = new double[1];
int startX = gridRange.getLow(0);
int endX = Math.min(2000, gridRange.getHigh(0));
int startY = gridRange.getLow(1);
int endY = Math.min(2000, gridRange.getHigh(1));
// XXX using an iterator could be faster
for (int x = startX; x < endX; x++) {
for (int y = startY; y < endY; y++) {
grid.evaluate(new GridCoordinates2D(x, y), values);
if (values[0] == novalue) {
continue;
}
if (values[0] < novalue) {
throw new IllegalStateException("XXX value < novalue : " + values[0]);
}
if (values[0] < min) {
min = values[0];
}
if (values[0] > max) {
max = values[0];
}
}
monitor.worked(1);
}
monitor.done();
// XXX check novalue
return new double[] { min, max, novalue };
}
use of org.geotools.coverage.grid.GridGeometry2D in project polymap4-core by Polymap4.
the class PredefinedColorMapEditor method minMax.
protected double[] minMax(GridCoverage2D grid) {
GridGeometry2D geometry = grid.getGridGeometry();
GridEnvelope gridRange = geometry.getGridRange();
int w = gridRange.getHigh(0);
int h = gridRange.getHigh(1);
Timer timer = new Timer();
Random random = new Random();
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
double[] values = new double[1];
for (int i = 0; i < 10000 || timer.elapsedTime() < 1000; i++) {
grid.evaluate(new GridCoordinates2D(random.nextInt(w), random.nextInt(h)), values);
min = values[0] < min ? values[0] : min;
max = values[0] > max ? values[0] : max;
}
return new double[] { min, max };
}
Aggregations