protected void writeTile(Raster raster,int column,int row,int kernelSize,String filePath,LayerType layerType) throws IOException {
  int tWidth=tileWidth + 1;
  int tLength=tileLength + 1;
  int tSize=tLength * tWidth * bytesPerPixel;
  int tileTop=0;
  int tileLeft=0;
  int rasterLeft=leftInset + column;
  int rasterTop=topInset + row;
  int rasterTWidth=tWidth * kernelSize;
  int rasterTLength=tLength * kernelSize;
  byte[] bbArray=new byte[tSize];
  ByteBuffer bbuf=ByteBuffer.wrap(bbArray);
switch (layerType) {
case none:
case footprint:
case viewshed:
case derivative:
    break;
case elevation:
case field:
case grayimage:
  raster.get(rasterTop,rasterLeft,rasterTWidth,rasterTLength,bbuf,tileTop,tileLeft,tWidth,kernelSize);
break;
case colorimage:
bbuf.order(ByteOrder.nativeOrder());
bbuf.rewind();
raster.getRGBA(rasterTop,rasterLeft,rasterTWidth,rasterTLength,bbuf,tileTop,tileLeft,tWidth,kernelSize);
break;
}
if (isEmpty(bbuf)) {
bbuf.limit(0);
}
writeTile(filePath,bbArray,tWidth,tLength,layerType);
}

protected void writeTile ( Raster raster , int column , int row , int kernelSize , String filePath , LayerType layerType ) throws IOException { int tWidth = tileWidth + 1 ; int tLength = tileLength + 1 ; int tSize = tLength * tWidth * bytesPerPixel ; int tileTop = 0 ; int tileLeft = 0 ; int rasterLeft = leftInset + column ; int rasterTop = topInset + row ; int rasterTWidth = tWidth * kernelSize ; int rasterTLength = tLength * kernelSize ; byte [ ] bbArray = new byte [ tSize ] ; ByteBuffer bbuf = ByteBuffer . wrap ( bbArray ) ; switch ( layerType ) { case none : case footprint : case viewshed : case derivative : break ; case elevation : case field : case grayimage : raster . get ( rasterTop , rasterLeft , rasterTWidth , rasterTLength , bbuf , tileTop , tileLeft , tWidth , kernelSize ) ; break ; case colorimage : bbuf . order ( ByteOrder . nativeOrder ( ) ) ; bbuf . rewind ( ) ; raster . getRGBA ( rasterTop , rasterLeft , rasterTWidth , rasterTLength , bbuf , tileTop , tileLeft , tWidth , kernelSize ) ; break ; } if ( isEmpty ( bbuf ) ) { bbuf . limit ( 0 ) ; } writeTile ( filePath , bbArray , tWidth , tLength , layerType ) ; }
write out a tile .
