Package org.geotools.coverage.grid
Class GridCoverageBuilder
- Object
-
- GridCoverageBuilder
-
public class GridCoverageBuilder extends Object
Helper class for the creation ofGridCoverage2D
instances. The only purpose of this builder is to makeGridCoverage2D
construction a little bit easier for some common cases. This class provides default values for each property which make it convenient for simple cases and testing purpose, but is not generic. Users wanting more control and flexibility should useGridCoverageFactory
directly.Usage example:
GridCoverageBuilder builder = new GridCoverageBuilder(); builder.setCoordinateReferenceSystem("EPSG:4326"); builder.{@linkplain #setEnvelope(double...) setEnvelope}(-60, 40, -50, 50); // Will use sample value in the range 0 inclusive to 20000 exclusive. builder.{@linkplain #setSampleRange(int,int) setSampleRange}(0, 20000); // Defines elevation (m) = sample / 10 Variable elevation = builder.{@linkplain #newVariable newVariable}("Elevation", SI.METRE); elevation.{@linkplain GridCoverageBuilder.Variable#setLinearTransform setLinearTransform}(0.1, 0); elevation.addNodataValue("No data", 32767); // Gets the image, draw anything we want in it. builder.{@linkplain #setImageSize(int,int) setImageSize}(500,500); BufferedImage image = builder.{@linkpalin #getBufferedImage getBufferedImage}(); Graphics2D gr = image.createGraphics(); gr.draw(...); gr.dispose(); // Gets the coverage. GridCoverage2D coverage = builder.{@linkplain #getGridCoverage2D getGridCoverage2D}();
- Since:
- 2.5
- Author:
- Martin Desruisseaux
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
GridCoverageBuilder.Variable
A variable to be mapped to a sample dimension.
-
Field Summary
Fields Modifier and Type Field Description protected List<GridCoverageBuilder.Variable>
variables
The list of variables created.
-
Constructor Summary
Constructors Constructor Description GridCoverageBuilder()
Creates a builder initialized to default values and factory.GridCoverageBuilder(GridCoverageFactory factory)
Creates a builder initialized to default values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BufferedImage
getBufferedImage()
Returns the buffered image to be wrapped byGridCoverage2D
.CoordinateReferenceSystem
getCoordinateReferenceSystem()
Returns the current coordinate reference system.Bounds
getEnvelope()
Returns a copy of current envelope.GridCoverage2D
getGridCoverage2D()
Returns the grid coverage.Dimension
getImageSize()
Returns the image size.NumberRange<? extends Number>
getSampleRange()
Returns the range of sample values.GridCoverageBuilder.Variable
newVariable(CharSequence name, Unit<?> units)
Creates a new variable, which will be mapped to a sample dimension.void
setBufferedImage(BufferedImage image)
Sets the buffered image.void
setBufferedImage(File file)
Sets the buffered image by reading it from the given file.void
setBufferedImage(Random random)
Sets the buffered image to a raster filled with random value using the specified random number generator.void
setCoordinateReferenceSystem(String code)
Sets the coordinate reference system to the specified authority code.void
setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Sets the coordinate reference system to the specified value.void
setEnvelope(double... ordinates)
Sets the envelope to the specified values, which must be the lower corner coordinates followed by upper corner coordinates.void
setEnvelope(Bounds envelope)
Sets the envelope to the specified value.void
setImageSize(int width, int height)
Sets the image size.void
setImageSize(Dimension size)
Sets the image size.void
setSampleRange(int lower, int upper)
Sets the range of sample values.void
setSampleRange(NumberRange<? extends Number> range)
Sets the range of sample values.
-
-
-
Field Detail
-
variables
protected final List<GridCoverageBuilder.Variable> variables
The list of variables created. Each variable will be mapped to a sample dimension.
-
-
Constructor Detail
-
GridCoverageBuilder
public GridCoverageBuilder()
Creates a builder initialized to default values and factory.
-
GridCoverageBuilder
public GridCoverageBuilder(GridCoverageFactory factory)
Creates a builder initialized to default values.
-
-
Method Detail
-
getCoordinateReferenceSystem
public CoordinateReferenceSystem getCoordinateReferenceSystem()
Returns the current coordinate reference system. If no CRS has been explicitly defined, then the default CRS is WGS84.
-
setCoordinateReferenceSystem
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws IllegalArgumentException
Sets the coordinate reference system to the specified value. If an envelope was previously defined, it will be reprojected to the new CRS.- Throws:
IllegalArgumentException
- if the CRS is illegal for the current envelope.
-
setCoordinateReferenceSystem
public void setCoordinateReferenceSystem(String code) throws IllegalArgumentException
Sets the coordinate reference system to the specified authority code. This convenience method gives a preference to axis in (longitude, latitude) order.- Throws:
IllegalArgumentException
- if the given CRS is illegal.
-
getEnvelope
public Bounds getEnvelope()
Returns a copy of current envelope. If no envelope has been explicitly defined, then the default is inferred from the CRS (by default a geographic envelope from 180°W to 180°E and 90°S to 90°N).
-
setEnvelope
public void setEnvelope(Bounds envelope) throws IllegalArgumentException
Sets the envelope to the specified value. If a CRS was previously defined, the envelope will be reprojected to that CRS. If no CRS was previously defined, then the CRS will be set to the envelope CRS.- Throws:
IllegalArgumentException
- if the envelope is illegal for the current CRS.
-
setEnvelope
public void setEnvelope(double... ordinates) throws IllegalArgumentException
Sets the envelope to the specified values, which must be the lower corner coordinates followed by upper corner coordinates. The number of arguments provided shall be twice the envelope dimension, and minimum shall not be greater than maximum.Example: (xmin, ymin, zmin, xmax, ymax, zmax)
- Throws:
IllegalArgumentException
-
getSampleRange
public NumberRange<? extends Number> getSampleRange()
Returns the range of sample values. If no range has been explicitly defined, then the default is a range from 0 inclusive to 256 exclusive.
-
setSampleRange
public void setSampleRange(NumberRange<? extends Number> range)
Sets the range of sample values.
-
setSampleRange
public void setSampleRange(int lower, int upper)
Sets the range of sample values.- Parameters:
lower
- The lower sample value (inclusive), typically 0.upper
- The upper sample value (exclusive), typically 256.
-
getImageSize
public Dimension getImageSize()
Returns the image size. If no size has been explicitly defined, then the default is 256×256 pixels.
-
setImageSize
public void setImageSize(Dimension size)
Sets the image size.
-
setImageSize
public void setImageSize(int width, int height)
Sets the image size.
-
newVariable
public GridCoverageBuilder.Variable newVariable(CharSequence name, Unit<?> units)
Creates a new variable, which will be mapped to a sample dimension. Additional information like scale, offset and nodata values can be provided by invoking setters on the returned variable.- Parameters:
name
- The variable name, ornull
for a default name.units
- The variable units, ornull
if unknown.- Returns:
- A new variable.
-
getBufferedImage
public BufferedImage getBufferedImage()
Returns the buffered image to be wrapped byGridCoverage2D
. If no image has been explicitly defined, a new one is created the first time this method is invoked. Users can write in this image before to create the grid coverage.
-
setBufferedImage
public void setBufferedImage(BufferedImage image)
Sets the buffered image. Invoking this method overwrite the image size with the given image size.
-
setBufferedImage
public void setBufferedImage(File file) throws IOException
Sets the buffered image by reading it from the given file. Invoking this method overwrite the image size with the given image size.- Throws:
IOException
- if the image can't be read.
-
setBufferedImage
public void setBufferedImage(Random random)
Sets the buffered image to a raster filled with random value using the specified random number generator. This method can be used for testing purpose, or for adding noise to a coverage.
-
getGridCoverage2D
public GridCoverage2D getGridCoverage2D()
Returns the grid coverage.
-
-