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;
}
};
}
Aggregations