Virtual Deforestation
and Aggregation AMLs
These are the most time consuming parts of the
process. VDF, DESPIKE3 and ELAPSEDTIME are all used by running
VDF. These are the deforestation processes. There are four variable
of interest that can be set in the VDF script. These are DZ1,
DZ2, POINTSLOST TOLERANCE, AND MAXITERATIONS which are all set
in VDF. DZ1 is the distance that a point can be above the local
average tin height before it is removed. DZ2 is the maximum distance
that a point can be below the average tin height before it is
removed, POINTSLOSTTOLERANCE is the percent of points that can
be lost in a round before the program jumps out, used to control
small data sets. The MAXITERATIONS is the number of rounds that
can be run before the program will automatically jump out even
if the POINTSLOSTTOLERANCE is not reached. In the DESPIKE3 script
there is one setting to note and that is the 2' grid sizes in
the tinlattice command.
The TIN2DEM.AML is the final script in the set.
It was created to convert all of the deforested tins in the ground
folder into one single tin which in turn is used to create a
grid and DEM file. The output files are called MASTER_TIN, MASTER_GRD,
and MASTER_DEM. No arguments are needed.
VDF.aml
/* AML vdf
/* 27 July 2000
/* Ralph Haugerud, USGS - Seattle
/* TILENAME is input TIN, presumably the last-return surface
/* Following segment was added by Matthew Walsh
/* 13 March 2003
/* Allowed the automation of many tin files in one directory
&sv file [filelist * tin.list -tin]
/* opens file list
&
sv fileunit [open tin.list openstat -read]
&
if %openstat% ne 0 &then
&return Problem opening file
/* reads file list
&
sv tilename [read %fileunit% readstat]
&
if %readstat% ne 0 &then
&return Problem reading file
&do &while %readstat% = 0
/*
/* This is the beginning of the original file from Ralph for
processing
/*
&
if [null %tilename%] &then &do
&type USAGE &r vdf <tin>, where <tin> is a last-return
&type surface of LIDAR data
&type
&return
&
end
/* units are feet, for data with circa 3' point spacing,
/* and with 2-ft cells in despike3.aml
&s ProximityTolerance = 0.01
&s dz1 = 0.7
&s dZ2 = 100
&s PointsLostTolerance = 0.1
&s MaxIterations = 16
&s NIterations = 1
&s starttime = [date -time]
/* first pass, no pit elimination
&s teststring = spot < MeanZ + %dZ1%
&s itstart = [date -time]
&r despike3 %tilename% 0.01 [quote %teststring%]
&r elapsedtime %itstart%
&type Tile %tilename%, time for iteration %NIterations% = %.ElapsedTime%
/* Now, eliminating pits, iterate to quasi-convergance
&s teststring = spot < meanZ + %dZ1% AND spot > meanZ - %dZ2%
&do &until %.PercentLost% < %PointsLostTolerance% OR %NIterations%
= %MaxIterations%
&s NIterations = [calc %NIterations% + 1]
&s itstart = [date -time]
&type Starting iteration %NIterations% at %itstart%
&r despike3 %tilename% %ProximityTolerance% [quote %teststring%]
&r elapsedtime %itstart%
&type Tile %tilename%, time for iteration %NIterations% = %.ElapsedTime%
&end
&r elapsedtime %starttime%
&type
&type Tile %tilename%
&type Iterations = %NIterations%
&Type Total time = %.ElapsedTime%
/*
/* This is the end of the original file from Ralph for processing
/*
&sv tilename [read %fileunit% readstat]
&
end
/* closes file
&
if [close %fileunit%] ne 0 &then
&return Cannot close file
/* deletes file
&
sv delstat [delete tin.list -file]
&return
DESPIKE3.aml
/* DESPIKE3.AML
/* AML to take spikes off of a TIN
/* version of 27 July 2000
/* Ralph Haugerud, USGS - Seattle
/* rhaugerud@usgs.gov
/*
&
args intin ProximityTolerance teststring
&if [null %intin%] &then &do
&type 'USAGE &R despikeg3 <intin> {ProximityTolerance} {Teststring}
&type default ProximityTolerance is 0.01
&type default Teststring is 'spot <= meanZ + 0.7'
&type
&return
&end
/*** set defaults
&if [null %ProximityTolerance%] &then &s ProximityTolerance = 0.01
&if [null %teststring%] &then &s teststring = 'spot <= meanZ +
0.7'
&s teststring = [translate %teststring%]
&s teststring = [unquote %teststring%]
/*** Turn TIN into point cover
&if [exist xxpoint -cover] &then kill xxpoint all
tinarc %intin% xxpoint POINT
/*** get "mean" value of Z around each point
&if [exist xxmean -grid] &then kill xxmean all
tinlattice %intin% xxmean
[unquote '']
[unquote '']
[unquote '']
2
&if [exist xxmeang -grid] &then kill xxmeang all
grid
xxmeang = focalmean(xxmean)
quit
kill xxmean all
latticespot xxmeang xxpoint meanZ
kill xxmeang all
/*** have had some problems with CREATETIN crashing when it is
/*** presented with NODATA values in meanZ, so get rid of them
&if [exist xxpoint2 -cover] &then kill xxpoint2 all
rename xxpoint xxpoint2
ap
reselect xxpoint2 point meanZ <> -9999
&s trash = [delete x.sl -file]
&s trash = [delete x.sx -file]
writesel x.sl
quit
reselect xxpoint2 xxpoint point x.sl
kill xxpoint2 all
/* create new tin from original points, filtered
/* by criteria in test string
&
if [exist %intin% -tin] &then kill %intin% all
createtin %intin% 0 %ProximityTolerance%
cover xxpoint POINT spot 1 # %teststring%
END
&describe xxpoint
&s np1 = %DSC$POINTS%
&describe %intin%
&s np2 = %TIN$NNODES%
&s .PercentLost = [calc ( %np1% - %np2% ) * 100 / %np1%
]
&type
&type Percent points removed this iteration = %.PercentLost%
&type
kill xxpoint all
&return
ELAPSEDTIME.aml
/* AML elapsedtime
/* note that starttime = [date -TIME]
&
arg starttime
&s endtime = [date -time]
&s sthr = [before %starttime% .]
&s stmin = [after %starttime% .]
&s stsec = [after %stmin% .]
&s stmin = [before %stmin% .]
&s endhr = [before %endtime% .]
&s endmin = [after %endtime% .]
&s endsec = [after %endmin% .]
&s endmin = [before %endmin% .]
&s endtime = [calc %endhr% + ( %endmin% / 60 ) + ( %endsec% / 3600 ) ]
&s starttime = [calc %sthr% + ( %stmin% / 60 ) + ( %stsec% / 3600 ) ]
&s eltime = [calc %endtime% - %starttime% ]
&if %eltime% < 0 &then &s eltime = [calc %eltime% + 24 ]
&s elhr = [trunc %eltime%]
&if %elhr% < 10 &then &s elhr = 0%elhr%
&s eltime = [calc ( %eltime% - %elhr% ) * 60 ]
&s elmin = [trunc %eltime%]
&if %elmin% < 10 &then &s elmin = 0%elmin%
&s elsec = [round [calc ( %eltime% - %elmin% ) * 60 ] ]
&if %elsec% < 10 &then &s elsec = 0%elsec%
&s .ElapsedTime = %elhr%:%elmin%:%elsec%
&return