/** * Create a raster reference for the given envelope from this resolution. * * @param location * of the origin of the raster reference, if <code>null</code> center will be assumed. * @param envelope * the envelope to create a raster reference for. * * @return the raster reference with sample resolutions and the origin fitting the given envelope, if no resolutions * were known, <code>null</code> will be returned; */ public RasterGeoReference createGeoReference( OriginLocation location, Envelope envelope ) { if ( resolutions == null ) { return null; } return RasterGeoReference.create( location == null ? OriginLocation.CENTER : location, envelope, resolutions[0], resolutions[1] ); }
/** * Read a raster from the grid file at location (row,column). * * @param columnId * * @param rowId * * @return the read raster or null if it could not be read. * @throws IOException */ public AbstractRaster getTile( int columnId, int rowId ) throws IOException { Envelope tileEnvelope = getTileEnvelope( columnId, rowId ); RasterGeoReference tileRasterReference = RasterGeoReference.create( OriginLocation.OUTER, tileEnvelope, infoFile.getTileRasterWidth(), infoFile.getTileRasterHeight() ); RasterRect tileRect = getGeoReference().createRelocatedReference( OriginLocation.OUTER ).convertEnvelopeToRasterCRS( tileEnvelope ); TileOffsetReader tReader = new TileOffsetReader( this, tileRect ); ByteBufferRasterData tileData = RasterDataFactory.createRasterData( infoFile.getTileRasterWidth(), infoFile.getTileRasterHeight(), getRasterDataInfo(), tReader, false ); SimpleRaster tile = new SimpleRaster( tileData, tileEnvelope, tileRasterReference, null ); return tile; }
@Override public void serialize( RenderingInfo rinfo, BufferedImage img, OutputStream out ) throws IOException { if ( rinfo != null && rinfo.getEnvelope() != null ) { long ts, te; RasterGeoReference geoRef = create( OriginLocation.OUTER, rinfo.getEnvelope(), img.getWidth(), img.getHeight() ); ts = System.currentTimeMillis(); GeoTiffWriter.save( img, geoRef, out ); te = System.currentTimeMillis(); LOG.debug( "Encoding into {} duration {} ms", formatName, te - ts ); } else { LOG.debug( "Rendering without spatial information, because no envelope is availible. Using ImageIO" ); write( img, formatName, out ); } } }
RasterGeoReference renv = RasterGeoReference.create( originLocation, env, columns * tileWidth, rows
private static Pair<SimpleRaster, String> getMapAsSimpleRaster( WMSClient client, List<String> layers, int width, int height, Envelope bbox, ICRS srs, String format, boolean transparent, boolean errorsInImage, int timeout ) throws IOException { GetMap gm = new GetMap( layers, width, height, bbox, srs, format, transparent ); Pair<BufferedImage, String> imageResponse = client.getMap( gm, null, timeout, errorsInImage ); Pair<SimpleRaster, String> response = new Pair<SimpleRaster, String>(); if ( imageResponse.first != null ) { BufferedImage img = imageResponse.first; RasterData rasterData = RasterFactory.rasterDataFromImage( img ); RasterGeoReference rasterEnv = RasterGeoReference.create( OriginLocation.OUTER, bbox, img.getWidth(), img.getHeight() ); SimpleRaster raster = new SimpleRaster( rasterData, bbox, rasterEnv, null ); response.first = raster; } else { response.second = imageResponse.second; } return response; }
RasterGeoReference rasterEnv = RasterGeoReference.create( OriginLocation.OUTER, bbox, width, height );
RasterGeoReference.OriginLocation originLocation, RasterIOOptions options ) { RasterGeoReference ref = RasterGeoReference.create( originLocation, envelope, image.getWidth(), image.getHeight() ); RasterIOOptions opts = options;
RasterGeoReference env = RasterGeoReference.create( OUTER, reqEnv, reqWidth, reqHeight ); RasterData data = rasterDataFromImage( res.first ); SimpleRaster raster = new SimpleRaster( data, reqEnv, env, null );
this.tileWidth = envelopeWidth / columns; this.tileHeight = envelopeHeight / rows; this.rasterReference = RasterGeoReference.create( location, envelope, tileSamplesX * columns, tileSamplesY
public void run() { Envelope cellWorldEnvelope = geomFactory.createEnvelope( cellMinX, cellMinY, cellMaxX, cellMaxY, null ); RasterGeoReference cellRasterReference = RasterGeoReference.create( originLocation, cellWorldEnvelope, tileWidth, tileHeight ); // rb: TODO should the following raster data be added to the cache. ByteBufferRasterData cellRasterData = RasterDataFactory.createRasterData( tileWidth, tileHeight, BandType.RGB, DataType.BYTE, InterleaveType.PIXEL, false ); SimpleRaster cellRaster = new SimpleRaster( cellRasterData, cellWorldEnvelope, cellRasterReference, null ); double croppedMinX = minX < cellMinX ? cellMinX : minX; double croppedMinY = minY < cellMinY ? cellMinY : minY; double croppedMaxX = maxX > cellMaxX ? cellMaxX : maxX; double croppedMaxY = maxY > cellMaxY ? cellMaxY : maxY; Set<TileFile> tileFiles = tileIndex.getTiles( geomFactory.createEnvelope( croppedMinX, croppedMinY, croppedMaxX, croppedMaxY, null ), metersPerPixel ); for ( TileFile tileFile : tileFiles ) { AbstractRaster raster = tileIdToRaster.get( tileFile.getId() ); if ( raster == null ) { try { raster = tileFile.loadRaster( rtbBaseDir ); } catch ( IOException e ) { e.printStackTrace(); } tileIdToRaster.put( tileFile.getId(), raster ); } setSubsetWithAlphaHack( cellRaster, raster ); } writer.add( cellId, cellRasterData.getByteBuffer() ); }
/** * Interpolates the given raster to retrieve a raster with the given width and height. * * @param sourceRaster * the raster to get an interpolation version from * @param dstWidth * the width (columns) of the resulting raster * @param dstHeight * the height (rows) of the resulting raster * @return the interpolated raster */ public AbstractRaster interPolate( AbstractRaster sourceRaster, int dstWidth, int dstHeight ) { SimpleRaster simpleSourceRaster = sourceRaster.getAsSimpleRaster(); RasterData srcData = simpleSourceRaster.getReadOnlyRasterData(); RasterGeoReference srcREnv = simpleSourceRaster.getRasterReference(); // interpolation is needed. Interpolation interpolation = InterpolationFactory.getInterpolation( interpolationType, srcData ); RasterRect rr = new RasterRect( 0, 0, dstWidth, dstHeight ); RasterData dstData = srcData.createCompatibleWritableRasterData( rr, null ); RasterGeoReference dstREnv = RasterGeoReference.create( sourceRaster.getRasterReference().getOriginLocation(), sourceRaster.getEnvelope(), dstWidth, dstHeight ); // use warp to calculate the correct sample positions in the source raster. // the warp is a cubic polynomial function created of 100 points in the dstEnvelope. This function will map // points from the source crs to the target crs very accurate. WarpPolynomial warp = createWarp( dstWidth, dstHeight, srcREnv, dstREnv ); warpTransform( warp, interpolation, dstData ); return new SimpleRaster( dstData, sourceRaster.getEnvelope(), dstREnv, (ResourceMetadata) sourceRaster.getMetadata() ); }
RasterGeoReference dstREnv = RasterGeoReference.create( sourceRaster.getRasterReference().getOriginLocation(), dstEnvelope, dstWidth, dstHeight );