Search in sources :

Example 6 with AbstractGridCoverage2DReader

use of org.geotools.coverage.grid.io.AbstractGridCoverage2DReader in project polymap4-core by Polymap4.

the class GridServiceInfo method main.

// test ***********************************************
public static void main(String[] args) throws Exception {
    // File f = new File( "/home/falko/Data/tiff/bluemarble.tif" );
    File f = new File("/home/falko/Data/ncrast/elevation_4326.tif");
    AbstractGridCoverage2DReader reader = GridCoverageReaderFactory.open(f);
    System.out.println("reader: " + reader);
    System.out.println("reader: " + reader.getInfo().getSource());
    System.out.println("reader: " + reader.getInfo().getTitle());
    System.out.println("reader: " + Arrays.asList(reader.getGridCoverageNames()));
    System.out.println("reader: " + reader.getFormat().getName());
    System.out.println("reader: " + reader.getCoordinateReferenceSystem());
    System.out.println("reader: " + reader.getOriginalEnvelope());
    System.out.println("reader: " + reader.getOriginalGridRange());
    for (String name : reader.getGridCoverageNames()) {
        ResourceInfo info = reader.getInfo(name);
        System.out.println("coverage: " + info.getTitle());
        System.out.println("coverage: " + info.getName());
        System.out.println("coverage: " + info.getDescription());
        System.out.println("coverage: " + info.getBounds());
    }
    reader.dispose();
}
Also used : DefaultResourceInfo(org.polymap.core.catalog.resolve.DefaultResourceInfo) IResourceInfo(org.polymap.core.catalog.resolve.IResourceInfo) ResourceInfo(org.geotools.data.ResourceInfo) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) File(java.io.File)

Example 7 with AbstractGridCoverage2DReader

use of org.geotools.coverage.grid.io.AbstractGridCoverage2DReader in project OpenTripPlanner by opentripplanner.

the class RasterPopulation method createIndividuals.

@Override
public void createIndividuals() {
    LOG.info("Loading population from raster file {}", sourceFilename);
    try {
        File rasterFile = new File(sourceFilename);
        // determine file format and CRS, then load raster
        AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile);
        AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
        GridCoverage2D coverage = reader.read(null);
        this.coverageCRS = coverage.getCoordinateReferenceSystem();
        GridGeometry2D gridGeometry = coverage.getGridGeometry();
        GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D();
        gridGeometry.getGridToCRS();
        // because we may want to produce an empty raster rather than loading one, alongside the coverage we
        // store the row/col dimensions and the referenced envelope in the original coordinate reference system.
        this.cols = gridEnvelope.width;
        this.rows = gridEnvelope.height;
        this.createIndividuals0();
    } catch (Exception ex) {
        throw new IllegalStateException("Error loading population from raster file: ", ex);
    }
    LOG.info("Done loading raster from file.");
}
Also used : AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) File(java.io.File)

Aggregations

AbstractGridCoverage2DReader (org.geotools.coverage.grid.io.AbstractGridCoverage2DReader)7 File (java.io.File)5 AbstractGridFormat (org.geotools.coverage.grid.io.AbstractGridFormat)5 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)1 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1 ChooseRasterFormatInterface (com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface)1 ChooseRasterFormatPanel (com.sldeditor.datasource.chooseraster.ChooseRasterFormatPanel)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 RenderingHints (java.awt.RenderingHints)1 WritableRaster (java.awt.image.WritableRaster)1 HashMap (java.util.HashMap)1 GridCoordinates2D (org.geotools.coverage.grid.GridCoordinates2D)1 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)1