Class GrassBinaryRasterReadHandler
- Object
-
- GrassBinaryRasterReadHandler
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class GrassBinaryRasterReadHandler extends Object implements Closeable
Grass binary data input/ouput handler.Reading and writing is supported.
- Since:
- 3.0
- Author:
- Andrea Antonello (www.hydrologis.com)
- See Also:
GrassBinaryImageReader
,GrassBinaryImageReadParam
,GrassBinaryImageMetadata
-
-
Constructor Summary
Constructors Constructor Description GrassBinaryRasterReadHandler(File cellFile)
the constructor to build aGrassBinaryRasterReadHandler
usable for reading grass rasters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
sets the abortrequired flag to true.void
close()
closes the I/O streams.List<String>
getCategories()
Getter for the categories.List<String>
getColorRules(double[] range)
Getter for the colorrules.CoordinateReferenceSystem
getCrs()
Reads the crs definition for the map.JGrassRegion
getNativeRasterRegion()
Getter for nativeRasterRegion.double
getNoData()
Getter for the noData value.double[]
getRange()
int
getRasterMapHeight()
int
getRasterMapWidth()
SampleModel
getSampleModel()
returns theSampleModel
compatible with theWritableRaster
.boolean
isAborting()
Getter for the abortrequired flag.void
parseHeaderAndAccessoryFiles()
Determines the metadata of the raster map.WritableRaster
readRaster(ImageReadParam param)
reads a grass raster, given the read parameters.WritableRaster
readRaster(ImageReadParam param, boolean useSubSamplingAsRequestedRowcols, boolean castDoubleToFloating, ProgressListener monitor)
Reads a grass raster, adding the possibility to override subsampling.void
setNoData(double noData)
Setter for the noData value.
-
-
-
Constructor Detail
-
GrassBinaryRasterReadHandler
public GrassBinaryRasterReadHandler(File cellFile)
the constructor to build aGrassBinaryRasterReadHandler
usable for reading grass rasters.- Parameters:
cellFile
- the file of the raw raster data.
-
-
Method Detail
-
readRaster
public WritableRaster readRaster(ImageReadParam param, boolean useSubSamplingAsRequestedRowcols, boolean castDoubleToFloating, ProgressListener monitor) throws IOException, DataFormatException
Reads a grass raster, adding the possibility to override subsampling.- Parameters:
param
- the read parameters.useSubSamplingAsRequestedRowcols
- a flag that gives the possibility to bypass the imageio subsampling mechanism. With GRASS maps this is often more performing in some boundary situations. In the case this flag is set to true, the subsampling values will be handled as the requested columns and rows.castDoubleToFloating
- a flag that gives the possibility to force the reading of a map as a floating point map. This is necessary right now because of a imageio bug: https://jai-imageio-core.dev.java.net /issues/show_bug.cgi?id=180- Returns:
- the read
raster
- Throws:
IOException
DataFormatException
-
readRaster
public WritableRaster readRaster(ImageReadParam param) throws IOException, DataFormatException
reads a grass raster, given the read parameters.The data are read into a single banded, floating point
WritableRaster
. ARectIter
can be used to access the data afterwards.- Parameters:
param
- the read parameters.- Returns:
- the read raster
- Throws:
IOException
DataFormatException
-
parseHeaderAndAccessoryFiles
public void parseHeaderAndAccessoryFiles() throws IOException
Determines the metadata of the raster map.Reads the map type given a file and its mapset, the information from the header file in the cellhd directory and determines the geographic limits, format of the data, etc from the file. NOTE: for further informations about cell header files, read the package description.
INFO: this is a reader method.
- Throws:
IOException
-
getNativeRasterRegion
public JGrassRegion getNativeRasterRegion()
Getter for nativeRasterRegion.INFO: this is a reader method.
- Returns:
- the nativeRasterRegion.
-
getColorRules
public List<String> getColorRules(double[] range) throws IOException
Getter for the colorrules.INFO: this is a reader method.
- Returns:
- the list of single colorrules.
- Throws:
IOException
-
getCategories
public List<String> getCategories() throws IOException
Getter for the categories.INFO: this is a reader method.
- Returns:
- the attribute table as read in the categories file
- Throws:
IOException
-
close
public void close() throws IOException
closes the I/O streams.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
abort
public void abort()
sets the abortrequired flag to true.As soon as possible that should abort the reader.
-
isAborting
public boolean isAborting()
Getter for the abortrequired flag.- Returns:
- the abortRequired flag.
-
setNoData
public void setNoData(double noData)
Setter for the noData value.- Parameters:
noData
- the nodata value to set.
-
getNoData
public double getNoData()
Getter for the noData value.- Returns:
- the nodata value.
-
getCrs
public CoordinateReferenceSystem getCrs() throws IOException
Reads the crs definition for the map.The definition for grass maps is held in the location. Grass projection definitions are usually in a non parsable internal format. In JGrass we ask the user to choose the CRS. If the user doesn't do so, the CRS will result to be undefined.
- Returns:
- the
CoordinateReferenceSystem
for the map. Null if it is not defined. - Throws:
IOException
- if there were problems in parsing the CRS file.
-
getSampleModel
public SampleModel getSampleModel()
returns theSampleModel
compatible with theWritableRaster
.- Returns:
- the sample model compatible with the created raster
-
getRasterMapWidth
public int getRasterMapWidth()
-
getRasterMapHeight
public int getRasterMapHeight()
-
getRange
public double[] getRange()
-
-