More scripts: Raster
Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
### fixseam.sml
### Script to fill lines and columns lines of null cells
### at seams in a raster mosaic. Seams of null cells must
### be only one cell wide (one-cell overlap of segments is OK).
### Each null cell in a seam is replaced by the average of the
### non-null cells in a 3 x 3 focal area centered on the cell.
### The script fills vertical seams, then horizontal seams,
### then vertical seams again to account for null cells remaining
### from horizontal seam overlaps.
class RVC_RASTER Mosaic, Fixed;
class RVC_RASTER Temp1, Temp2;
numeric numcols, numlins, nullval;
string rasttype$;
GetInputRaster(Mosaic);
numcols = NumCols(Mosaic);
numlins = NumLins(Mosaic);
string rasttype$ = RastType(Mosaic);
nullval = NullValue(Mosaic);
GetOutputRaster(Fixed, numlins, numcols, rasttype$);
numeric lin, col, val, j, k, m;
proc horiz(class RVC_RASTER Rastin, class RVC_RASTER Rastout) # declare procedure to fix horizontal seams
{
for lin = 1 to numlins {
for col = 1 to numcols {
k = Rastin[lin,col];
if (IsNull(k) == 1) {
j = Rastin[lin-1,col];
m = Rastin[lin+1,col];
if ((IsNull(j) == 0) and (IsNull(m) == 0)) then
val = FocalMean(Rastin,3,3,lin,col);
else val = Rastin[lin,col];
}
else val = Rastin[lin,col];
Rastout[lin,col] = val;
}
}
}
numeric p, q, r;
proc vert(class RVC_RASTER Rastin, class RVC_RASTER Rastout) # declare procedure to fix vertical seams
{
for lin = 1 to numlins {
for col = 1 to numcols {
q = Rastin[lin,col];
if (IsNull(q) == 1) {
p = Rastin[lin,col-1];
r = Rastin[lin,col+1];
if ((IsNull(p) == 0) and (IsNull(r) == 0)) then
val = FocalMean(Rastin,3,3,lin,col);
else val = Rastin[lin,col];
}
else val = Rastin[lin,col];
Rastout[lin,col] = val;
}
}
}
CreateTempRaster(Temp1,numlins,numcols,rasttype$);
SetNull(Temp1,nullval);
vert(Mosaic,Temp1); # process vertical seams
CreateTempRaster(Temp2,numlins,numcols,rasttype$);
SetNull(Temp2,nullval);
horiz(Temp1,Temp2); # process horizontal seams
vert(Temp2,Fixed); # process remaining vertical seams
DeleteTempRaster(Temp1);
DeleteTempRaster(Temp2);
CreateHistogram(Fixed);
CreatePyramid(Fixed);
CopySubobjects(Mosaic,Fixed,"GEOREF");