@Override public Envelope getEnvelope() { return raster.getEnvelope(); }
@Override public Envelope getEnvelope() { // return envelope of highest resolution. // envelopes of other resolutions can be larger due to padding of tiles if ( !resolutions.isEmpty() && resolutions.get( 0 ) != null ) { return resolutions.get( 0 ).getEnvelope(); } return null; }
public List<AbstractRaster> getTiles( Envelope env ) { List<AbstractRaster> result = new ArrayList<AbstractRaster>(); for ( AbstractRaster r : tiles ) { if ( env.intersects( r.getEnvelope() ) ) { result.add( r ); } } return result; }
/** * Checks if the coverage contains the <code>envelope</code>. * * @param envelope * The envelope to check for. */ protected void checkBounds( Envelope envelope ) { // rb: following checks are unnecessary because the creation of envelopes should check it. // assert ( envelope.getMin().x < envelope.getMax().x ); // assert ( envelope.getMin().y < envelope.getMax().y ); // assert ( getEnvelope().getMin().x < getEnvelope().getMax().x ); // assert ( getEnvelope().getMin().y < getEnvelope().getMax().y ); if ( !getEnvelope().contains( envelope ) ) { throw new IndexOutOfBoundsException(); } }
/** * @return string representation of the envelope */ protected String envelopeString() { String epsg = ""; if ( getEnvelope().getCoordinateSystem() != null ) { epsg = getEnvelope().getCoordinateSystem().getAlias(); } return epsg + " " + getEnvelope().getMin().get0() + " " + getEnvelope().getMin().get1() + " " + getEnvelope().getMax().get0() + " " + getEnvelope().getMax().get1(); }
/** * Returns columns of the raster. * * @return width in pixel */ public int getColumns() { return getRasterReference().getSize( getEnvelope() )[0]; }
/** * Returns rows of the raster. * * @return height in pixel */ public int getRows() { return getRasterReference().getSize( getEnvelope() )[1]; }
/** * Adds an AbstractRaster to the MultiRangedRaster * * @param raster */ public void addRaster( AbstractRaster raster ) { extendEnvelope( raster.getEnvelope() ); extendRasterReference( raster.getRasterReference() ); multiRange.add( raster ); }
private void render( final AbstractRaster raster ) { render( RasterFactory.imageFromRaster( raster ), raster.getEnvelope() ); }
/** * @param info * @param files * @param rasters * @param options */ public DiskBasedTileContainer( QTreeInfo info, List<File> files, List<AbstractRaster> rasters, RasterIOOptions options ) { qtree = new QTree<File>( createEnvelope( info.envelope ), info.numberOfObjects ); envelope = info.envelope; AbstractRaster raster = rasters.iterator().next(); rasterDataInfo = raster.getRasterDataInfo(); rasterGeoReference = info.rasterGeoReference; resolutionInfo = raster.getResolutionInfo(); this.options = options; Iterator<File> iter = files.iterator(); for ( AbstractRaster r : rasters ) { File f = iter.next(); qtree.insert( createEnvelope( r.getEnvelope() ), f ); cache.put( f, new SoftReference<AbstractRaster>( r ) ); } initialized = true; }
/** * Adds a new tile to the container. * * @param raster * new tile */ public synchronized void addTile( AbstractRaster raster ) { if ( raster != null ) { if ( this.envelope == null ) { this.envelope = raster.getEnvelope(); } else { this.envelope = this.envelope.merge( raster.getEnvelope() ); } if ( this.rasterReference == null ) { this.rasterReference = raster.getRasterReference(); } else { this.rasterReference = RasterGeoReference.merger( this.rasterReference, raster.getRasterReference() ); } if ( this.rdi == null ) { this.rdi = raster.getRasterDataInfo(); } if ( this.resolutionInfo == null ) { this.resolutionInfo = raster.getResolutionInfo(); } tiles.add( raster ); } }
@Override public void setSubRaster( Envelope envelope, AbstractRaster source ) { List<AbstractRaster> interSectingTiles = getTileContainer().getTiles( envelope ); if ( !interSectingTiles.isEmpty() ) { for ( AbstractRaster r : interSectingTiles ) { if ( r != null ) { Geometry intersection = r.getEnvelope().getIntersection( envelope ); if ( intersection != null ) { Envelope subsetEnv = intersection.getEnvelope(); r.setSubRaster( subsetEnv, source ); } } } } }
@Override public AbstractRaster apply( RangeSet sourceRangeSet, RangeSet targetRangeset ) { AbstractRaster result = raster(); if ( rangeSetsAreApplicable( sourceRangeSet, targetRangeset ) ) { List<AxisSubset> requestedAxis = targetRangeset.getAxisDescriptions(); if ( requestedAxis != null && !requestedAxis.isEmpty() ) { // create a copy so that the original rangeset will not be modified. List<AxisSubset> copyRA = new ArrayList<AxisSubset>( requestedAxis ); Map<BandType, AxisSubset> referencedBands = getReferencedBands( copyRA ); BandType[] bands = null; if ( referencedBands != null ) { bands = referencedBands.keySet().toArray( new BandType[referencedBands.keySet().size()] ); // filter the bands. result = raster().getSubRaster( raster().getEnvelope(), bands ); boolean applyData = false; for ( AxisSubset ass : referencedBands.values() ) { applyData = ass.hasAxisConstraints(); if ( applyData ) { break; } } if ( applyData ) { result = applyDataFilter( result, requestedAxis, referencedBands ); } } } } return result; }
/** * Adds a new tile to the container. * * @param raster * new tile */ public void addTile( AbstractRaster raster ) { if ( raster != null ) { if ( this.rdi == null ) { this.rdi = raster.getRasterDataInfo(); } if ( this.resolutionInfo == null ) { this.resolutionInfo = raster.getResolutionInfo(); } index.insert( createEnvelope( raster.getEnvelope() ), raster ); } }
private void handleStyling( RasterStyling styling, AbstractRaster raster ) { BufferedImage img = null; if ( styling.channelSelection != null ) { // Compute channel selection indexes on current raster styling.channelSelection.evaluate( raster.getRasterDataInfo().bandInfo ); } // TODO maybe reorder this a bit if ( styling.shaded != null ) { raster = performHillShading( raster, styling ); } if ( styling.channelSelection != null ) { raster = evaluateChannelSelections( styling.channelSelection, raster ); } if ( styling.contrastEnhancement != null ) { raster = performContrastEnhancement( raster, styling.contrastEnhancement ); } if ( styling.opacity != 1 ) { LOG.trace( "Using opacity: {}", styling.opacity ); graphics.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, (float) styling.opacity ) ); } img = handleFunctions( styling, raster ); LOG.trace( "Rendering raster..." ); if ( img != null ) { render( img, raster.getEnvelope() ); } else { render( raster ); } LOG.trace( "Done rendering raster." ); handleOutline( styling, raster ); }
Envelope dataEnvelope = sourceRaster.getEnvelope();
/** * Performs contrast enhancement on all bands of a raster and returns the modified raster. * * @param raster * initial raster * @param contrastEnhancement * @return the enhanced raster */ private AbstractRaster performContrastEnhancement( AbstractRaster raster, ContrastEnhancement contrastEnhancement ) { if ( contrastEnhancement == null ) return raster; LOG.trace( "Enhancing contrast for overall raster..." ); RasterData data = raster.getAsSimpleRaster().getRasterData(), newData = data; RasterDataUtility rasutil = new RasterDataUtility( raster ); rasutil.setContrastEnhancement( contrastEnhancement ); rasutil.precomputeContrastEnhancements( -1, contrastEnhancement ); for ( int band = 0; band < data.getBands(); band++ ) newData = setEnhancedChannelData( newData, rasutil, band, band, contrastEnhancement ); AbstractRaster newRaster = new SimpleRaster( newData, raster.getEnvelope(), raster.getRasterReference(), null ); return newRaster; }
private void setSubsetWithAlphaHack( SimpleRaster target, AbstractRaster source ) { if ( target != null && source != null ) { // rb: todo the intersection of two envelopes should be an envelope, but the cast will be wrong. Envelope tEnv = target.getEnvelope(); Envelope sEnv = source.getEnvelope(); if ( tEnv != null && sEnv != null ) { Geometry geom = tEnv.getIntersection( sEnv ); if ( geom != null ) { Envelope intersectEnv = geom.getEnvelope(); if ( intersectEnv != null ) { RasterRect rect = target.getRasterReference().convertEnvelopeToRasterCRS( intersectEnv ); SimpleRaster src = source.getSubRaster( intersectEnv ).getAsSimpleRaster(); PixelInterleavedRasterData targetData = (PixelInterleavedRasterData) target.getRasterData(); setSubset( targetData, rect.x, rect.y, rect.width, rect.height, src.getRasterData() ); } } } } else { LOG.debug( "Ignoring rasters because of null reference." ); } }
/** * 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() ); }
/** * Return the bounding geometry of a raster as a polygon (but is actually a rectangle). * * @param raster * @return bounding polygon */ public static Polygon createPolygonGeometry( AbstractRaster raster ) { ICRS crs = raster.getCoordinateSystem(); GeometryFactory fac = new GeometryFactory(); Envelope env = raster.getEnvelope(); env = raster.getRasterReference().relocateEnvelope( OriginLocation.OUTER, env ); Point pmin = env.getMin(); Point pmax = env.getMax(); Point p1 = fac.createPoint( null, pmin.get0(), pmin.get1(), crs ); Point p3 = fac.createPoint( null, pmax.get0(), pmax.get1(), crs ); Point p2 = fac.createPoint( null, p1.get0(), p3.get1(), crs ); Point p4 = fac.createPoint( null, p3.get0(), p1.get1(), crs ); Point p5 = fac.createPoint( null, p1.get0(), p1.get1(), crs ); Point[] points = { p1, p2, p3, p4, p5 }; // (asList(points)); LinearRing ring = fac.createLinearRing( null, crs, new PointsList( asList( points ) ) ); Polygon poly = fac.createPolygon( null, crs, ring, null ); return poly; }