/*
* Create working band
*/
Band WorkProximityBand = ProximityBand;
Dataset WorkProximityDS = null;
int ProxType = ProximityBand.getDataType();
String tempFilename = null;
if (ProxType == gdalconstConstants.GDT_Byte
|| ProxType == gdalconstConstants.GDT_UInt16
|| ProxType == gdalconstConstants.GDT_UInt32) {
tempFilename = "/vsimem/proximity_" + String.valueOf(System.currentTimeMillis()) + ".tif";
WorkProximityDS = gdal.GetDriverByName("GTiff").Create(tempFilename,
ProximityBand.getXSize(), ProximityBand.getYSize(), 1,
gdalconstConstants.GDT_Float32);
WorkProximityBand = WorkProximityDS.GetRasterBand(1);
}
int xSize = WorkProximityBand.getXSize();
int ySize = WorkProximityBand.getYSize();
/*
* Allocate buffers
*/
short nearXBuffer[] = new short[xSize];
short nearYBuffer[] = new short[xSize];
int scanline[] = new int[xSize];
float proximityBuffer[] = new float[xSize];
/*
* Loop from top to bottom of the image
*/
for (int i = 0; i < xSize; i++) {
nearXBuffer[i] = -1;
nearYBuffer[i] = -1;
}
for (int iLine = 0; iLine < ySize; iLine++) {
SrcBand.ReadRaster(0, iLine, xSize, 1, xSize, 1,
gdalconstConstants.GDT_Int32, scanline);
for (int i = 0; i < xSize; i++) {
proximityBuffer[i] = -1F;
}
/*
* Left to Right
*/
ProcessProximityLine(scanline, nearXBuffer, nearYBuffer,
true, iLine, xSize, MaxDistance, proximityBuffer,
TargetValues);
/*
* Right to Left
*/
ProcessProximityLine(scanline, nearXBuffer, nearYBuffer,
false, iLine, xSize, MaxDistance, proximityBuffer,
TargetValues);
/*
* Write to Proximity Band
*/
WorkProximityBand.WriteRaster(0, iLine, xSize, 1, xSize, 1,
gdalconstConstants.GDT_Float32, proximityBuffer);
}
/*
* Loop from bottom to top of the image
*/
for (int i = 0; i < xSize; i++) {
nearXBuffer[i] = -1;
nearYBuffer[i] = -1;
}
for (int iLine = ySize - 1; iLine >= 0; iLine--) {
WorkProximityBand.ReadRaster(0, iLine, xSize, 1, xSize, 1,
gdalconstConstants.GDT_Float32, proximityBuffer);
SrcBand.ReadRaster(0, iLine, xSize, 1, xSize, 1,
gdalconstConstants.GDT_Int32, scanline);