use of org.geotools.coverage.grid.io.AbstractGridFormat in project polymap4-core by Polymap4.
the class GridCoverageReaderFactory method open.
/**
* Creates a new {@link GridCoverage2DReader} for the given file.
*
* @param f
* @return Newly created reader.
* @throws Exception
*/
public static AbstractGridCoverage2DReader open(File f) throws Exception {
return lock.lockedInterruptibly(() -> {
// Hints hints = new Hints();
// hints.put( Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode( "EPSG:9001" ) );
// hints.put( Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE );
AbstractGridFormat format = GridFormatFinder.findFormat(f);
AbstractGridCoverage2DReader reader = format.getReader(f);
return reader;
});
}
use of org.geotools.coverage.grid.io.AbstractGridFormat 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.io.AbstractGridFormat in project sldeditor by robward-scisys.
the class DetermineRasterFormatTest method testChoose.
/**
* Test method for {@link
* com.sldeditor.datasource.chooseraster.DetermineRasterFormat#choose(java.io.File,
* com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface)}.
*/
@Test
public void testChoose() {
AbstractGridFormat gridFormat = DetermineRasterFormat.choose(null, null);
assertTrue(UnknownFormat.class == gridFormat.getClass());
String testRasterFile = "/raster/sld/sld_cookbook_raster.tif";
InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testRasterFile);
File f = null;
if (inputStream == null) {
assertNotNull(inputStream, "Failed to find raster test file : " + testRasterFile);
} else {
try {
f = SLDTestRunner.stream2file(inputStream, ".tif");
gridFormat = DetermineRasterFormat.choose(f, null);
assertTrue(gridFormat != null);
// Force to WorldImageFormat
gridFormat = DetermineRasterFormat.choose(f, new ChooseRasterFormatInterface() {
@Override
public AbstractGridFormat showPanel(Set<AbstractGridFormat> formatList) {
WorldImageFormat wif = new WorldImageFormat();
return wif;
}
});
assertTrue(WorldImageFormat.class == gridFormat.getClass());
} catch (IOException e1) {
e1.printStackTrace();
} finally {
f.delete();
}
}
}
use of org.geotools.coverage.grid.io.AbstractGridFormat in project sldeditor by robward-scisys.
the class CreateExternalDataSource method connectToRasterDataSource.
/**
* Connect to raster data source.
*
* @param map the map
*/
private void connectToRasterDataSource(Map<String, Object> map) {
Object rasterFilename = map.get(DataSourceConstants.FILE_MAP_KEY);
if (rasterFilename != null) {
File rasterFile = new File(ExternalFilenames.convertURLToFile((String) rasterFilename));
ChooseRasterFormatInterface panel = new ChooseRasterFormatPanel(Controller.getInstance().getFrame());
AbstractGridFormat format = DetermineRasterFormat.choose(rasterFile, panel);
AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
dsInfo.setGridCoverageReader(reader);
} else {
logger.error("No matching datastore");
}
}
use of org.geotools.coverage.grid.io.AbstractGridFormat in project sldeditor by robward-scisys.
the class ChooseRasterFormatPanel method showPanel.
/*
* (non-Javadoc)
*
* @see com.sldeditor.datasource.impl.chooseraster.ChooseRasterFormatInterface#showPanel(java.util.Set)
*/
@Override
public AbstractGridFormat showPanel(Set<AbstractGridFormat> formatList) {
WorldImageFormat wif = new WorldImageFormat();
DefaultListModel<String> listModel = new DefaultListModel<>();
List<AbstractGridFormat> sortedFormatList = new ArrayList<>();
for (AbstractGridFormat format : formatList) {
if (format.getName().compareTo(wif.getName()) != 0) {
sortedFormatList.add(format);
}
}
// Sort formats alphabetically
Collections.sort(sortedFormatList, new Comparator<AbstractGridFormat>() {
@Override
public int compare(final AbstractGridFormat object1, final AbstractGridFormat object2) {
return object1.getName().compareTo(object2.getName());
}
});
// Add WorldImageFormat to top of list
sortedFormatList.add(0, wif);
// Add format names to list component
for (AbstractGridFormat format : sortedFormatList) {
formatMap.put(format.getName(), format);
listModel.addElement(format.getName());
}
formatListComponent.setModel(listModel);
// Select WorldImageFormat
formatListComponent.setSelectedIndex(0);
setVisible(true);
String selectedFormatName = formatListComponent.getSelectedValue();
return formatMap.get(selectedFormatName);
}
Aggregations