Package org.geotools.coverage.grid
Class GridCoverageBuilder
Object
GridCoverageBuilder
Helper class for the creation of
GridCoverage2D
instances. The only purpose of this
builder is to make GridCoverage2D
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
use GridCoverageFactory
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}(); </pre></blockquote>
- Since:
- 2.5
- Author:
- Martin Desruisseaux
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<GridCoverageBuilder.Variable>
The list of variables created. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a builder initialized to default values and factory.GridCoverageBuilder
(GridCoverageFactory factory) Creates a builder initialized to default values. -
Method Summary
Modifier and TypeMethodDescriptionReturns the buffered image to be wrapped byGridCoverage2D
.Returns the current coordinate reference system.Returns a copy of current envelope.Returns the grid coverage.Returns the image size.NumberRange<? extends Number>
Returns the range of sample values.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
Sets the coordinate reference system to the specified authority code.void
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 Details
-
variables
The list of variables created. Each variable will be mapped to a sample dimension.
-
-
Constructor Details
-
GridCoverageBuilder
public GridCoverageBuilder()Creates a builder initialized to default values and factory. -
GridCoverageBuilder
Creates a builder initialized to default values.
-
-
Method Details
-
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
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
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
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
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
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
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
Returns the image size. If no size has been explicitly defined, then the default is 256×256 pixels. -
setImageSize
Sets the image size. -
setImageSize
public void setImageSize(int width, int height) Sets the image size. -
newVariable
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
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
Sets the buffered image. Invoking this method overwrite the image size with the given image size. -
setBufferedImage
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
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
Returns the grid coverage.
-