public class GridCoverageBuilder extends Object
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(String) 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}();
Modifier and Type | Class and Description |
---|---|
class |
GridCoverageBuilder.Variable
A variable to be mapped to a sample dimension.
|
Modifier and Type | Field and Description |
---|---|
protected List<GridCoverageBuilder.Variable> |
variables
The list of variables created.
|
Constructor and Description |
---|
GridCoverageBuilder()
Creates a builder initialized to default values and factory.
|
GridCoverageBuilder(GridCoverageFactory factory)
Creates a builder initialized to default values.
|
Modifier and Type | Method and Description |
---|---|
BufferedImage |
getBufferedImage()
Returns the buffered image to be wrapped by
GridCoverage2D . |
CoordinateReferenceSystem |
getCoordinateReferenceSystem()
Returns the current coordinate reference system.
|
Envelope |
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(CoordinateReferenceSystem crs)
Sets the coordinate reference system to the specified value.
|
void |
setCoordinateReferenceSystem(String code)
Sets the coordinate reference system to the specified authority code.
|
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(Envelope envelope)
Sets the envelope to the specified value.
|
void |
setImageSize(Dimension size)
Sets the image size.
|
void |
setImageSize(int width,
int height)
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.
|
protected final List<GridCoverageBuilder.Variable> variables
public GridCoverageBuilder()
public GridCoverageBuilder(GridCoverageFactory factory)
public CoordinateReferenceSystem getCoordinateReferenceSystem()
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws IllegalArgumentException
IllegalArgumentException
- if the CRS is illegal for the current envelope.public void setCoordinateReferenceSystem(String code) throws IllegalArgumentException
IllegalArgumentException
- if the given CRS is illegal.public Envelope getEnvelope()
public void setEnvelope(Envelope envelope) throws IllegalArgumentException
IllegalArgumentException
- if the envelope is illegal for the current CRS.public void setEnvelope(double... ordinates) throws IllegalArgumentException
Example: (xmin, ymin, zmin, xmax, ymax, zmax)
IllegalArgumentException
public NumberRange<? extends Number> getSampleRange()
public void setSampleRange(NumberRange<? extends Number> range)
public void setSampleRange(int lower, int upper)
lower
- The lower sample value (inclusive), typically 0.upper
- The upper sample value (exclusive), typically 256.public Dimension getImageSize()
public void setImageSize(Dimension size)
public void setImageSize(int width, int height)
public GridCoverageBuilder.Variable newVariable(CharSequence name, Unit<?> units)
name
- The variable name, or null
for a default name.units
- The variable units, or null
if unknown.public BufferedImage getBufferedImage()
GridCoverage2D
. 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.public void setBufferedImage(BufferedImage image)
public void setBufferedImage(File file) throws IOException
IOException
- if the image can't be read.public void setBufferedImage(Random random)
public GridCoverage2D getGridCoverage2D()
Copyright © 1996–2019 Geotools. All rights reserved.