Search in sources :

Example 1 with HadoopWritableSerializer

use of org.locationtech.geowave.mapreduce.HadoopWritableSerializer in project geowave by locationtech.

the class RasterDataAdapter method createWritableSerializer.

@Override
public HadoopWritableSerializer<GridCoverage, GridCoverageWritable> createWritableSerializer() {
    return new HadoopWritableSerializer<GridCoverage, GridCoverageWritable>() {

        @Override
        public GridCoverageWritable toWritable(final GridCoverage entry) {
            final Envelope env = entry.getEnvelope();
            final DataBuffer dataBuffer = entry.getRenderedImage().copyData(new InternalWritableRaster(sampleModel.createCompatibleSampleModel(tileSize, tileSize), new Point())).getDataBuffer();
            Persistable metadata = null;
            if (entry instanceof GridCoverage2D) {
                final Object metadataObj = ((GridCoverage2D) entry).getProperty(TILE_METADATA_PROPERTY_KEY);
                if ((metadataObj != null) && (metadataObj instanceof Persistable)) {
                    metadata = (Persistable) metadataObj;
                }
            }
            return new GridCoverageWritable(new RasterTile(dataBuffer, metadata), env.getMinimum(0), env.getMaximum(0), env.getMinimum(1), env.getMaximum(1), env.getCoordinateReferenceSystem());
        }

        @Override
        public GridCoverage fromWritable(final GridCoverageWritable writable) {
            final ReferencedEnvelope mapExtent = new ReferencedEnvelope(writable.getMinX(), writable.getMaxX(), writable.getMinY(), writable.getMaxY(), writable.getCrs());
            try {
                return prepareCoverage(writable.getRasterTile(), tileSize, mapExtent);
            } catch (final IOException e) {
                LOGGER.error("Unable to read raster data", e);
            }
            return null;
        }
    };
}
Also used : GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) Persistable(org.locationtech.geowave.core.index.persist.Persistable) Point(java.awt.Point) IOException(java.io.IOException) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope) Envelope(org.opengis.geometry.Envelope) GridEnvelope(org.opengis.coverage.grid.GridEnvelope) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) HadoopWritableSerializer(org.locationtech.geowave.mapreduce.HadoopWritableSerializer) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) GridCoverage(org.opengis.coverage.grid.GridCoverage) FitToIndexGridCoverage(org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage) DataBuffer(java.awt.image.DataBuffer)

Aggregations

Point (java.awt.Point)1 DataBuffer (java.awt.image.DataBuffer)1 IOException (java.io.IOException)1 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)1 GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 FitToIndexGridCoverage (org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage)1 Persistable (org.locationtech.geowave.core.index.persist.Persistable)1 HadoopWritableSerializer (org.locationtech.geowave.mapreduce.HadoopWritableSerializer)1 GridCoverage (org.opengis.coverage.grid.GridCoverage)1 GridEnvelope (org.opengis.coverage.grid.GridEnvelope)1 Envelope (org.opengis.geometry.Envelope)1