it.geosolutions.imageio.plugins.arcgrid.raster
Class AsciiGridRaster

Object
  extended by AsciiGridRaster

public abstract class AsciiGridRaster
extends Object

Abstract base class to handle ASCII ArcGrid/GRASS formats

Author:
Daniele Romagnoli, GeoSolutions., Simone Giannecchini, GeoSolutions.

Nested Class Summary
static class AsciiGridRaster.AsciiGridRasterType
           
 
Field Summary
protected  boolean abortRequired
           
protected  double cellSizeX
          The size of a single cell of the grid along X
protected  double cellSizeY
          The size of a single cell of the grid along Y
protected  boolean compress
          true if the file related to this raster is compressed
protected  long dataStartAt
          A kind of Bookmark that point at the first byte in the stream after the header
protected  ImageInputStream imageIS
          ImageInputStream used to read the source that contain data
protected  ImageOutputStream imageOS
          ImageOutputStream used to write the raster to the device (file,stream,...)
protected  boolean isCorner
          If isCorner is true then xllCellCoordinate is the coordinate of the lower-left corner of the grid.
protected static Logger LOGGER
           
protected  double maxValue
          max value found in the file
protected  double minValue
          min value found in the file
protected  int nCols
          The number of columns of the raster
static String newline
          The OS-dependent line separator
protected  double noData
          the value used to represent noData for an element of the raster
protected  int nRows
          The number of rows of the raster
protected  AsciiGridsImageReader reader
          the AsciiGridsImageReader to be used for read operations
protected  int sourceXSubsampling
          horizontal subsampling
protected  int sourceYSubsampling
          vertical subsampling
protected  int tileHeight
          the height of a tile
protected  TreeMap<Long,Long> tileMarker
          A TreeMap used to Skip spaces-count operation when the image is tiled.
protected  int[] tileTreeMutex
           
protected  int tileWidth
          the width of a tile
protected  AsciiGridsImageWriter writer
          the AsciiGridsImageWriter to be used for write operations
protected  double xllCellCoordinate
          x coordinate of the grid origin (the lower left corner) in compliance with the isCorner value
protected  double yllCellCoordinate
          y coordinate of the grid origin (the lower left corner) in compliance with the isCorner value
 
Constructor Summary
protected AsciiGridRaster(ImageInputStream iis)
          A constructor b
protected AsciiGridRaster(ImageInputStream iis, AsciiGridsImageReader reader)
          A constructor to build an AsciiGridRaster given an ImageInputStream and an AsciiGridsImageReader
protected AsciiGridRaster(ImageOutputStream ios)
          A base constructor to write AsciiGridRasters.
protected AsciiGridRaster(ImageOutputStream ios, AsciiGridsImageWriter writer)
          A constructor to build an AsciiGridRaster given an ImageOutputStream and an AsciiGridsImageWriter
 
Method Summary
 void abort()
           
 void clearAbort()
           
 double getCellSizeX()
          Cell Size X value
 double getCellSizeY()
          Cell Size Y value
 double getMaxValue()
          Max value.
 double getMinValue()
          Min value.
 int getNCols()
          Number of columns.
 double getNoData()
          NoData value.
abstract  String getNoDataMarker()
          Return the String representing noData.
 int getNRows()
          Number of rows.
abstract  AsciiGridRaster.AsciiGridRasterType getRasterType()
          Retrieves the type of raster we are serving, GRASS or ESRI.
 int getSourceXSubsampling()
          XSubSampling factor
 int getSourceYSubsampling()
          YSubSampling factor
 int getTileHeight()
          TileHeight value
 int getTileWidth()
          TileWidth value
 double getXllCellCoordinate()
          Lower-Left Cell: X coordinate
 double getYllCellCoordinate()
          Lower-Left Cell: Y coordinate
 boolean isAborting()
           
 boolean isCorner()
          Returns the isCorner field.
abstract  void parseHeader()
          The header structure of an ASCII GRASS file is different from the one of an ASCII ArcGrid file.
 WritableRaster readRaster(ImageReadParam param)
          This method reads data values from the ImageInputStream and returns a raster having these data values as samples.
 void setTilesSize(int tileWidth, int tileHeight)
          Initializes tile sizes
abstract  void writeHeader(String columns, String rows, String xll, String yll, String cellsizeX, String cellsizeY, String rasterSpaceType, String noDataValue)
          As stated for parseHeader, the differences betweens the structure of the header of an ASCII ArcGrid and the one of an ASCII GRASS require a different management also during the writing process.
 void writeRaster(RectIter iterator, Double noDataDouble, String noDataMarker)
          Writes the raster
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final Logger LOGGER

newline

public static final String newline
The OS-dependent line separator


tileTreeMutex

protected final int[] tileTreeMutex

abortRequired

protected volatile boolean abortRequired

maxValue

protected double maxValue
max value found in the file


minValue

protected double minValue
min value found in the file


xllCellCoordinate

protected double xllCellCoordinate
x coordinate of the grid origin (the lower left corner) in compliance with the isCorner value


yllCellCoordinate

protected double yllCellCoordinate
y coordinate of the grid origin (the lower left corner) in compliance with the isCorner value


sourceXSubsampling

protected int sourceXSubsampling
horizontal subsampling


sourceYSubsampling

protected int sourceYSubsampling
vertical subsampling


isCorner

protected boolean isCorner
If isCorner is true then xllCellCoordinate is the coordinate of the lower-left corner of the grid. If isCorner is false then xllCellCoordinate is the coordinate of the center of the lower-left gridcell of the grid.


cellSizeX

protected double cellSizeX
The size of a single cell of the grid along X


cellSizeY

protected double cellSizeY
The size of a single cell of the grid along Y


nCols

protected int nCols
The number of columns of the raster


nRows

protected int nRows
The number of rows of the raster


compress

protected boolean compress
true if the file related to this raster is compressed


dataStartAt

protected long dataStartAt
A kind of Bookmark that point at the first byte in the stream after the header


tileMarker

protected TreeMap<Long,Long> tileMarker
A TreeMap used to Skip spaces-count operation when the image is tiled. If I need to load data values to fill the last tile, I need to skip a lot of samples before finding useful data values. This TreeMap couples 'number of spaces' to 'positions in the stream'. Thus, this search operation is accelerated.


tileWidth

protected int tileWidth
the width of a tile


tileHeight

protected int tileHeight
the height of a tile


imageIS

protected ImageInputStream imageIS
ImageInputStream used to read the source that contain data


imageOS

protected ImageOutputStream imageOS
ImageOutputStream used to write the raster to the device (file,stream,...)


noData

protected double noData
the value used to represent noData for an element of the raster


reader

protected AsciiGridsImageReader reader
the AsciiGridsImageReader to be used for read operations


writer

protected AsciiGridsImageWriter writer
the AsciiGridsImageWriter to be used for write operations

Constructor Detail

AsciiGridRaster

protected AsciiGridRaster(ImageInputStream iis)
A constructor b


AsciiGridRaster

protected AsciiGridRaster(ImageInputStream iis,
                          AsciiGridsImageReader reader)
A constructor to build an AsciiGridRaster given an ImageInputStream and an AsciiGridsImageReader

Parameters:
iis - ImageInputStream needed to read the raster.
reader - AsciiGridsImageReader used to read the raster.

AsciiGridRaster

protected AsciiGridRaster(ImageOutputStream ios)
A base constructor to write AsciiGridRasters.

Parameters:
ios - ImageOutputStream needed to write the raster.

AsciiGridRaster

protected AsciiGridRaster(ImageOutputStream ios,
                          AsciiGridsImageWriter writer)
A constructor to build an AsciiGridRaster given an ImageOutputStream and an AsciiGridsImageWriter

Parameters:
iis - ImageOutputStream needed to read the raster.
writer - AsciiGridsImageWriter used to read the raster.
Method Detail

parseHeader

public abstract void parseHeader()
                          throws IOException
The header structure of an ASCII GRASS file is different from the one of an ASCII ArcGrid file.
         A GRASS Header has the following form:
         ---------------------------------------
         NORTH: XX
         SOUTH: XX
         EAST: XX
         WEST: XX
         ROWS: XX
         COLS: XX
                                  
                                  
         An ArcGrid header has the following form:
         -----------------------------------------
         nrows XX
         ncols XX
         xllcorner (OR xllcenter) XX
         yllcorner (OR yllcenter) XX
         cellsize XX
         NODATA_value XX (Optional)     
         
                                 
         (note: XX represents the value of the specific field)
 
For this reason, a specific implementation is required.

Throws:
IOException

writeHeader

public abstract void writeHeader(String columns,
                                 String rows,
                                 String xll,
                                 String yll,
                                 String cellsizeX,
                                 String cellsizeY,
                                 String rasterSpaceType,
                                 String noDataValue)
                          throws IOException
As stated for parseHeader, the differences betweens the structure of the header of an ASCII ArcGrid and the one of an ASCII GRASS require a different management also during the writing process. For this reason, a specific implementation is required.

Throws:
IOException

getNoDataMarker

public abstract String getNoDataMarker()
Return the String representing noData.
GRASS use the '*' sign to represent noData, while ArcGrid use a numeric representation (A commonly used value is -9999 which is also used as default value)


getMaxValue

public final double getMaxValue()
Max value.

Returns:
the max value contained in the data file

getMinValue

public final double getMinValue()
Min value.

Returns:
the min value contained in the data file

getNoData

public final double getNoData()
NoData value.

Returns:
the value representing noData

getNRows

public final int getNRows()
Number of rows.

Returns:
the number of rows contained in the file.

getRasterType

public abstract AsciiGridRaster.AsciiGridRasterType getRasterType()
Retrieves the type of raster we are serving, GRASS or ESRI.


getNCols

public final int getNCols()
Number of columns.

Returns:
the number of columns contained in the file.

getSourceXSubsampling

public int getSourceXSubsampling()
XSubSampling factor

Returns:
the subSampling factor along X

getSourceYSubsampling

public int getSourceYSubsampling()
YSubSampling factor

Returns:
the subSampling factor along Y

getCellSizeX

public final double getCellSizeX()
Cell Size X value

Returns:
the size of a single cell of the grid along X

getCellSizeY

public final double getCellSizeY()
Cell Size Y value

Returns:
the size of a single cell of the grid along X

getXllCellCoordinate

public final double getXllCellCoordinate()
Lower-Left Cell: X coordinate

Returns:
the X coordinate of the lower left grid cell.
See Also:
isCorner

getYllCellCoordinate

public final double getYllCellCoordinate()
Lower-Left Cell: Y coordinate

Returns:
the Y coordinate of the lower left grid cell.
See Also:
isCorner

getTileHeight

public final int getTileHeight()
TileHeight value

Returns:
the height of the tile

getTileWidth

public final int getTileWidth()
TileWidth value

Returns:
the width of the tile

setTilesSize

public final void setTilesSize(int tileWidth,
                               int tileHeight)
Initializes tile sizes

Parameters:
tileWidth - the width of the tile
tileHeight - the height of the tile

isCorner

public final boolean isCorner()
Returns the isCorner field.
It is true if xllCellCoordinate and yllCellCoordinate represent the coordinates of the lower-left corner of the lower-left cell of the grid. It is false if they represent the coordinates of the center of the lower-left cell of the grid.

Returns:
isCorner.

readRaster

public WritableRaster readRaster(ImageReadParam param)
                          throws IOException
This method reads data values from the ImageInputStream and returns a raster having these data values as samples. When image is tiled or reading is executed only on a specific part of the ASCII source, I need to determine which values must be loaded and which must be skipped. Within an ASCII source, I can't know how many digits compose a value. Thus, I need to scan and check every byte stored on the input source and retrieve the value as well as I need to skip values if they are useless.

Parameters:
param - an ImageReadParam which specifies source region properties as width, height, x and y offsets.
Returns:
WritableRaster the Raster composed by reading data values
Throws:
IOException
NumberFormatException - TODO we ignore destination region, destinationOffset etc...

writeRaster

public void writeRaster(RectIter iterator,
                        Double noDataDouble,
                        String noDataMarker)
                 throws IOException
Writes the raster

Parameters:
iterator - A RectIterator built on Lines and Pixels of the Raster which need to be written.
noDataDouble - the value representing noData.
noDataMarker - a String which need to be printed when founding a noData value
Throws:
IOException

abort

public void abort()

isAborting

public boolean isAborting()

clearAbort

public void clearAbort()


Copyright © 2006-2010 GeoSolutions. All Rights Reserved.