Search in sources :

Example 1 with AbstractGridFormat

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;
    });
}
Also used : AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader)

Example 2 with AbstractGridFormat

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();
// }
}
Also used : GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) GridEnvelope(org.opengis.coverage.grid.GridEnvelope) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) Timer(org.polymap.core.runtime.Timer) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) GridCoordinates2D(org.geotools.coverage.grid.GridCoordinates2D) File(java.io.File)

Example 3 with AbstractGridFormat

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();
        }
    }
}
Also used : WorldImageFormat(org.geotools.gce.image.WorldImageFormat) Set(java.util.Set) UnknownFormat(org.geotools.coverage.grid.io.UnknownFormat) InputStream(java.io.InputStream) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) ChooseRasterFormatInterface(com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface) IOException(java.io.IOException) File(java.io.File) SLDTreeTest(com.sldeditor.test.unit.ui.tree.SLDTreeTest) Test(org.junit.jupiter.api.Test)

Example 4 with AbstractGridFormat

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");
    }
}
Also used : ChooseRasterFormatPanel(com.sldeditor.datasource.chooseraster.ChooseRasterFormatPanel) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) ChooseRasterFormatInterface(com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface) File(java.io.File)

Example 5 with AbstractGridFormat

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);
}
Also used : WorldImageFormat(org.geotools.gce.image.WorldImageFormat) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel)

Aggregations

AbstractGridFormat (org.geotools.coverage.grid.io.AbstractGridFormat)8 File (java.io.File)5 AbstractGridCoverage2DReader (org.geotools.coverage.grid.io.AbstractGridCoverage2DReader)5 ChooseRasterFormatInterface (com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface)2 IOException (java.io.IOException)2 UnknownFormat (org.geotools.coverage.grid.io.UnknownFormat)2 WorldImageFormat (org.geotools.gce.image.WorldImageFormat)2 SLDData (com.sldeditor.common.data.SLDData)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 ChooseRasterFormatPanel (com.sldeditor.datasource.chooseraster.ChooseRasterFormatPanel)1 SLDTreeTest (com.sldeditor.test.unit.ui.tree.SLDTreeTest)1 BufferedImage (java.awt.image.BufferedImage)1 WritableRaster (java.awt.image.WritableRaster)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 DefaultListModel (javax.swing.DefaultListModel)1 GridCoordinates2D (org.geotools.coverage.grid.GridCoordinates2D)1 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)1 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)1