/** * Returns new RasterGeoReference with the origin set to the given target location. Other values are taken from this * instance. * * @param targetLocation * of the new reference * @return new RasterGeoReference or this if the target location is <code>null</code> or equals this one. */ public RasterGeoReference createRelocatedReference( OriginLocation targetLocation ) { if ( targetLocation == null || location == targetLocation ) { return this; } double[] newOrigin = getOrigin( targetLocation ); return new RasterGeoReference( targetLocation, this.getResolutionX(), this.getResolutionY(), this.getRotationX(), this.getRotationY(), newOrigin[0], newOrigin[1], this.crs ); }
/** * 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] ); }
@Override public void setSubRaster( double x, double y, AbstractRaster source ) { RasterGeoReference srcREnv = source.getRasterReference(); RasterGeoReference dstREnv = new RasterGeoReference( srcREnv.getOriginLocation(), srcREnv.getResolutionX(), srcREnv.getResolutionY(), x, y ); Envelope dstEnv = dstREnv.getEnvelope( source.getColumns(), source.getRows(), source.getCoordinateSystem() ); RasterData srcData = source.getAsSimpleRaster().getRasterData(); SimpleRaster movedRaster = new SimpleRaster( srcData, dstEnv, dstREnv, metadata ); setSubRaster( dstEnv, movedRaster ); }
/** * Returns a list with the highest resolution of every level. The list is sorted ascending (from highest to lowest * resolution). * * @return a list of all resolutions */ public List<Double> getResolutions() { List<Double> res = new ArrayList<Double>( resolutions.size() ); for ( AbstractRaster level : resolutions ) { RasterGeoReference renv = level.getRasterReference(); res.add( min( abs( renv.getResolutionX() ), abs( renv.getResolutionY() ) ) ); } return res; }
/** * * @param id * @param level * @param raster */ public MyTile( int id, int level, SimpleRaster raster ) { super( id, level, raster.getEnvelope(), null, null, (float) raster.getRasterReference().getResolutionX(), (float) raster.getRasterReference().getResolutionY(), raster.getRasterReference().getOriginLocation() ); this.raster = raster; }
double[] max = transformedEnv.getMax().getAsArray(); int[] rasterCoordinate = getRasterCoordinate( min[0], max[1] ); double[] worldCoordinate = getWorldCoordinate( raster0, raster1 ); return new RasterGeoReference( tLoc, this.getResolutionX(), this.getResolutionY(), this.getRotationX(), this.getRotationY(), worldCoordinate[0], worldCoordinate[1], this.crs );
sampleSizeX = rRef.getResolutionX(); sampleSizeY = rRef.getResolutionY(); this.geoReference = new RasterGeoReference( OriginLocation.CENTER, rRef.getResolutionX(), rRef.getResolutionY(), rRef.getRotationX(), rRef.getRotationY(), 0, raster.getEnvelope().getSpan1(), raster.getCoordinateSystem() ); this.outputY = nextPowerOfTwo; Envelope env = raster.getRasterReference().getEnvelope( new RasterRect( 0, 0, outputX, outputY ), null );
out.writeObject( createEnvelope( envelope ) ); out.writeObject( rasterDataInfo ); out.writeObject( rasterGeoReference.getOriginLocation() ); out.writeDouble( rasterGeoReference.getResolutionX() ); out.writeDouble( rasterGeoReference.getResolutionY() ); out.writeDouble( rasterGeoReference.getRotationX() ); out.writeDouble( rasterGeoReference.getRotationY() ); out.writeDouble( rasterGeoReference.getOriginEasting() ); out.writeDouble( rasterGeoReference.getOriginNorthing() ); out.writeObject( rasterGeoReference.getCrs() ); out.writeObject( resolutionInfo ); out.writeObject( options );
RasterData shadeData = RasterDataFactory.createRasterData( cols - 2, rows - 2, DataType.BYTE, false ); RasterGeoReference ref = raster.getRasterReference(); double resx = cols * ref.getResolutionX() / ( cols - 2 ); double resy = rows * ref.getResolutionY() / ( rows - 2 ); ref = new RasterGeoReference( ref.getOriginLocation(), resx, resy, ref.getOrigin()[0], ref.getOrigin()[1] ); SimpleRaster hillShade = new SimpleRaster( shadeData, raster.getEnvelope(), ref, null );
public static Envelope getEnvelope( IIOMetadata metaData, int width, int height, ICRS crs ) { GeoTiffIIOMetadataAdapter geoTIFFMetaData = new GeoTiffIIOMetadataAdapter( metaData ); try { double[] tiePoints = geoTIFFMetaData.getModelTiePoints(); double[] scale = geoTIFFMetaData.getModelPixelScales(); if ( tiePoints != null && scale != null ) { RasterGeoReference rasterReference; if ( Math.abs( scale[0] - 0.5 ) < 0.001 ) { // when first pixel tie point is 0.5 -> center type // rb: this might not always be right, see examples at // http://www.remotesensing.org/geotiff/spec/geotiff3.html#3.2.1. // search for PixelIsArea/PixelIsPoint to determine center/outer rasterReference = new RasterGeoReference( CENTER, scale[0], -scale[1], tiePoints[3], tiePoints[4], crs ); } else { rasterReference = new RasterGeoReference( OUTER, scale[0], -scale[1], tiePoints[3], tiePoints[4], crs ); } return rasterReference.getEnvelope( OUTER, width, height, crs ); } } catch ( UnsupportedOperationException ex ) { LOG.debug( "couldn't read crs information in GeoTIFF" ); } return null; }
crs = options.getCRS(); return new RasterGeoReference( location, resx, resy, values[2], values[1], xmin, ymax, crs );
throws IOException { RasterGeoReference rasterReference = raster.getRasterReference().createRelocatedReference( OriginLocation.OUTER ); Envelope renv = raster.getRasterReference().relocateEnvelope( OriginLocation.OUTER, raster.getEnvelope() ); RasterRect rect = rasterReference.convertEnvelopeToRasterCRS( raster.getEnvelope() ); this.setTileHeight( rasterReference.getEnvelope( new RasterRect( 0, 0, tileWidth, tileHeight ), null ).getSpan1() ); String cD = options.get( RasterIOOptions.RASTER_CACHE_DIR ); File cacheDir = ( cD == null ) ? RasterCache.DEFAULT_CACHE_DIR : new File( cD );
/** * Returns an Envelope for a raster with given size and given x,y raster location. * * The calculation considers the origin and resolution of the this raster. * * @param rasterRect * defining the x,y raster coordinates (as integers) as well as the width and height of the raster. * @param crs * the coordinate system for the envelope * * @return the calculated envelope */ public Envelope getEnvelope( RasterRect rasterRect, ICRS crs ) { return getEnvelope( location, rasterRect, crs ); }
/** * 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; }
/** * 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() ); }
geoReference = new RasterGeoReference( RasterGeoReference.OriginLocation.CENTER, gridExtension.resX, gridExtension.resY, gridExtension.minx, gridExtension.maxy ); int[] size = geoReference.getSize( rasterEnvelope ); width = size[0]; height = size[1]; int[] pos = geoReference.getRasterCoordinate( p.x, p.y ); data.setFloatSample( pos[0], pos[1], 0, p.value );
SimpleRaster simpleRaster = raster.getAsSimpleRaster(); RasterGeoReference rasterReference = simpleRaster.getRasterReference().createRelocatedReference( OriginLocation.OUTER ); String newLine = System.getProperty( "line.separator" ); writer.write( "ncols " + simpleRaster.getColumns() + newLine ); writer.write( "nrows " + simpleRaster.getRows() + newLine ); double[] worldCoordinate = rasterReference.getWorldCoordinate( 0, simpleRaster.getRows() ); ICRS crs = simpleRaster.getCoordinateSystem(); int axis = 0; writer.write( "cellsize " + rasterReference.getResolutionX() + newLine ); writer.write( "nodata_value " + simpleRaster.getRasterDataInfo().getFloatNoDataForBand( 0 ) + newLine );
/** * @return the northing (y) value of the origin. */ public double getOriginNorthing() { return getOrigin()[1 - eastingAxis]; }
rasterDataInfo = (RasterDataInfo) in.readObject(); rasterGeoReference = new RasterGeoReference( (OriginLocation) in.readObject(), in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble(), (CRS) in.readObject() ); envelope.setCoordinateSystem( rasterGeoReference.getCrs() ); resolutionInfo = (ResolutionInfo) in.readObject(); options = (RasterIOOptions) in.readObject();
/** * Returns the size in pixel of a raster that extends within given Envelope. * * @param env * Envelope for the * @return array with width and height of the raster */ public int[] getSize( Envelope env ) { RasterRect rr = convertEnvelopeToRasterCRS( env ); return new int[] { rr.width, rr.height }; }