Grid Generation
This page presents some basic concepts on the generation of rectangular and triangular
grids and their interpolators, from samples (points and contour
lines) and other grids used by SPRING.
The rectangular grids are generally used in qualitative
applications for surface visualization. On the other hand, the
irregular grid model is used when more precision on the quantitative
data analysis is required.
The rectangular and triangular grid interpolators, used in
SPRING for generating digital terrain models, have been specified
according to the input data types, i.e., samples (points and contour
lines), rectangular or triangular grids.
See also:
How to generate a
Rectangular Grid
How to generate a triangular grid
DTM products in SPRING
Modeling Processes
A rectangular or regular grid is a digital model that
approximates surfaces using a polyhedron of
rectangular faces (see figure below). The vertices of these
polyhedrons may be the sample points themselves, in case they have been
acquired on the same (x,y) locations that define the desired grid.

Surface Model generated by a rectangular grid.
The generation of rectangular or regular grid
must be done when the sample data on the surface are not obtained with
regular spacing. Therefore, the grid is generated based on the
information contained in the contour lines or sample points, according to the surface. The initial values
to be determined are the spaces in x and y directions so they can
represent the values close to the grid points in regions with great
variation. At the same time, they must reduce the redundancies in
regions almost planes.
The grid spacing, i.e., the x
or y resolution, ideally must be
less than or equal to the smaller distance between two samples with
different heights (elevation). When we generate a grid that is too thin
(dense), with a very small distance between the points, we will have
more information about the surface to be analyzed. On the other hand,
it will take longer to generate it. If on the contrary, the points are
too far apart, the generated grid will be thick and we will lose
information. There should be a balance between the time it takes to
generate the
grid and the data precision.
Once the resolution and coordinates of each point of the grid
are defined, one of the interpolator methods can be applied to
calculate the approximate value for the elevation.
In SPRING, the regular grid can be generated from samples,
that is, points and lines, regular or irregular grid. The following
interpolators can be used in the case of points and lines: nearest
neighbor,
simple average, weighted average, weighted average by quadrant,
weighted average by quadrant and elevation and splines.
Linear and bicubic interpolators can be used to generate a new
regular grid from another rectangular grid. The Linear interpolator is
used to generate a rectangular grid from a TIN (“Triangular
Irregular Network”).
Grids
The interpolation methods used for generating regular or
rectangular grids from samples will be presented next:
- Nearest Neighbor - for each grid point
(x,y), the system assigns the elevation of the sample closest to the
point (see figure below). This interpolator must be used when we want
to keep the elevations of the grid samples, without generating
intermediate values.

The elevation (+) corresponds to the closest sample value (*).
- Simple Average- the elevation of each
point of the grid is estimated from the simple average of the
elevations of the 8 nearest neighbors of this point. This interpolator
is normally used when we want to quickly generate the grid for
evaluating the gross digitization errors.

where:
n = number of neighbors
z = elevation (height) of the 8 n neighbors
i=1
f(x,y)= interpolation function

The elevation (+) is obtained from the 4 closest sample neighbors (*).
- Weighted Average - the elevation of each
point is calculated from from the weighted average of the elevations of
the 8 nearest neighbors of this point, however, we assign different
weights to each sample point using a function that considers the
distance of each elevation to the point at the grid.
d = ((x - x0)2 + (y - y0)2)1/2
d = euclidean distance from the interpolation point to
neighbor i
w(x,y) = (1/d)u=1 u =
1 = exponent of the weighting function
where:
w(x,y) = Weighting function
f(x,y) - Interpolation function
-
This interpolation provides intermediate
results between the simple average interpolator and the others that are
more sophisticated, in a shorter processing time.
- Weighted Average by Quadrant
- this interpolator calculates the weighted average using the later
interpolation function. One sample by quadrant is taken (total of 4
samples) and the number of sample points is equal for each quadrant
(see figure below). This interpolator should be used when all samples
are of the point type.

The elevation by quadrant with weight is proportional to the inverse of
the distance of the sample values.
- Weighted Average by Quadrant and elevation -
this interpolator also performs the same function of the interpolator
discussed above, but using the nearest contour line elevation. Besides
the quadrant restriction it also limits the number of samples by
elevation value, not allowing samples with repeated elevations. It is
recommended for samples of contour lines type.

O elevation is obtained by the weighted average of the contour lines
elevations by quadrant.
- Splines - A spline of "m" degree is a polynomial piece of "m" degree which is derived of "m-1" orde in each node.
The equation y = A1.x³ + B1.x² + C1.x + D1 is an example of a cubic spline function of y in function of x. Mathematically, this function is also a
piece of polynomial, which is the junction of other pieces of polynomials, in a limited range. The continuity of the curve resulting from this function is satisfied at the point of junction.
The Spline Curves are vectors of pieces of polynomials and continued in their nodes. The spline formed by low degree polynomials are useful for filling curves. As polynomials function of low
degree may not connect certain points, when you want to have the curve pass through certain points in an interpolation, using a technique of joining a number of spline segments (usually cubic spline),
with each segment connecting only two points.
Grids
Generating a Rectangular Grid from another Rectangular Grid
The generation of a new rectangular grid from an already
elaborated rectangular grid can be considered as a grid refinement and
it consists in making the spacing between the grid points smaller.
These internal points present elevations of the new grid estimated by
bicubic and bilinear interpolators.
-
To perform a bicubic refinement, according to a
neighborhood
relationship, the number of neighbors to be considered will be equal to
16 (see the figure below).
-
Consider a point P, placed inside the boundaries, on the
xy
plane, of the original grid. The four points nearest to point P are the
extremes of the cell
that contains P. Also near are the extremes of the adjacent cells to
the cell that contains P. These extremes are represented on the figure
below by the
letters A to Q. To evaluate the elevation on P we must use the
following procedure: 1) calculate the elevation of the points R, S, T,
and U from a (2-D) cubic interpolation between the elevation of the
points A-B-C-D, E-F-G-H, I-J-K-L and M-N-O-Q, respectively; 2) from the
elevation of the points R, S, T and U, we can obtain the elevation of
P, using the same cubic interpolator over these points.

Bicubic Interpolator.
-
Although the bicubic refinement is slower than the
bilinear, it provides more interesting results since it guarantees
continuity of first and second order between the functions that
represent
each cell in the model. Thus, the surface obtained is smooth on the
grid points and also along the segments that make the rectangles, that
is, the grid is smoother and each piece of grid is continuous and
smooth relative to its neighbors.
-
To calculate the bilinear surface for one cell in the
grid, we benefit from the characteristics of the ordering in the
position of the cell elements to optimize the procedure that implements
this interpolator.
We
consider a grid cell formed by the vertices A, B, C, and D, and a
generic point inside the cell, M=f(u,v), (u,v) in (0,1).
The bilinear interpolation on the ABCD cell is done by the following
procedure: initially we interpolate linearly the points E and F,
starting from the points C and D, and A and B, respectively; finally we
interpolate point M linearly, from points E and F (see the figure
below). This way, elevation Z, calculated at point M is:

Bilinear Interpolator.
- z = z x (1-v) + z x v =
M--------E---------F
- z = (z x (1-u) + z x u) x (1-v) + (z x (1-u) + z x u) x
v)
----------C---------D--------------------A-----------B
- z = v x (u x z + (1-u) x z) + (1- v) x ( ux z + (1-u) x
z)
------------B-------A--------------D-----------------C
- (u,v) normalized in (0,1)
-
Such method is very fast, computationally speaking, when
compared to the bicubic interpolator. Its greatest disadvantage is the
generation of surfaces not too smooth. Thus it should be used when a
smooth appearance for the surface is not required.
Grids
The conversion of the triangular grid to a rectangular grid
can be necessary when we require a matrix format for the digital
terrain model. This way, the information about the terrain that were
modeled by a triangular grid interpolator could be analyzed by other
matrix type information. The conversion process can use the following
interpolators: Linear, Quintic
with break lines and Quintic without break lines, described as
follows.
-
In the linear
interpolation, a plane is adjusted for every triangular patch in
the grid, to determine the values of z in every (x,y) position within
the triangle. The equation of a plane surface can be expressed by Ax
+By +Cz +D=0.
-
In this linear approach the different surface patches are
found in the common side of these triangles. This means that the
borders do not have a smooth continuities.
- Quintic interpolator without break lines
-
The quintic interpolator without break lines
adjusts a surface to the grid patches, using a fifth degree polynomial.
The use of this interpolator allows the generation of a smoother
surface
if compared to another grid generated by the linear interpolator.
-
Break lines are
lines that define the discontinuities in the surface for both sides of
the line, also called valley lines or crest lines. A river, for
example, can be edited as a break line where alongside its margins
there is a relief discontinuity, without any elevation associated to it.
-
These break lines could be, or not, considered in the
generation of a triangular grid. The quintic interpolator without break
lines obviously do not consider these break lines (see the example in
the figure below).

Quintic interpolator without
break lines.
-
This interpolator is recommended when one desires a
smooth surface and there are no valley or crest lines (break lines)
that are much outstanding.
- Quintic interpolator with break lines
-
This interpolator differs from the last one only in the
break lines. It uses the same fifth degree surface to adjust the grid
patches, however, the algorithm recognizes the break lines and the
surface alongside it will not be smoothed (see the example in the
figure below).

Grid generated by a quintic interpolator with break lines.
-
This interpolator is recommended for situations where the
break lines are edited to highlight the linear features of relief and
drainage and you want a smooth surface.
Grids
In the modeling of the surface by a triangular irregular
network, each polygon that forms one face of the polyhedron is a
triangle (see figure below). The vertices of the triangle are generally
sample points on the surface. Such modeling, considering the sides of
the triangles, allows the important morphological information, like the
discontinuities represented by linear features of the relief (crests)
and drainage (valleys), be considered during the generation of the
triangular grid, thus allowing to model the terrain surface preserving
the geomorphic characteristics of its surface.

Surface Model generated by a triangular grid.
The number of redundancies is greatly reduced, if compared to
the rectangular grid, since the mesh is thinner in regions with great
variations while being more open in almost plane regions. The surface
discontinuities can be modeled through characteristic lines and points.
This grid has the
advantage of using the sample points themselves to model the surface
without the need for any interpolation on them. The disadvantage of the
irregular grid is that the procedures for obtaining data derived from
triangular grids tend to be more complex and consequently more time
consuming than the ones of the rectangular grid.
Data pre-processing
The input of contour lines in numeric modeling, either by the
sensitivity of the digitizing table, or by the resolution of the
scanner, and the conversion algorithm, many times generates an
excessive number of points to represent the contour lines. The ideal
spacing between points of a contour line should be the mean distance
between the contour line and the neighboring contour lines. Such ideal
spacing allows the generation of triangles that are more equilateral,
which allows for a more efficient modeling of the terrain.
Another source of
redundant points occurs when a line is not digitized continually, from
its beginning until its end. In such cases, the first point in a line
could be the last point of the last line, or be so close to it that it
could be interpreted as being positioned in the same geographical
location. The last problem can be solved by the comparison of the
initial and final values of the contour lines. One of the points, thus
duplicated, can be removed from the set of samples.
The excess points, along a
line, are eliminated by using a simplifying procedure, based upon the Douglas-Peucker
algorithm. The Douglas-Peucker algorithm eliminates points by
analyzing the distance from each point to a straight
line that connects the first point to the last point in the contour
line. If all the points are at a distance less than a certain
tolerance, the line will be represented solely by the first and the
last points. If some point is at a longer distance, the point
most distant from the straight line will be considered the last and the
algorithm is restarted calculating the distances.
A special procedure is taken when the line represents an
island, that is, when the first point is the same as the last
one. In this case, the point before the last is used. Since the lines
are contour lines and its points are used as elevation samples in the
generation of the triangular grid, we should keep a maximum distance
between the points along the lines. Ideally, this distance should be
the mean among the distance from the analyzed line and the nearest
parallel lines.
The value of the tolerance
is calculated considering the original data scale. It is well known
that the precision of the data on maps is around 0.2 mm. The tolerance
value of 0.4 mm for the elimination of points was used in tests that
proved that such value allows for the generation of well-behaved
triangular grids (we search for triangles as equilateral as possible).
The maximum distance between points on the contour line is defined from
the tolerance of the Douglas-Peucker algorithm and tests have indicated that
a value of 20 times the tolerance could be used. These values are
presented as default in the triangular grid generation window.
The drainage lines can be used as additional sources of
information and can improve the quality of the terrain model. These
lines are represented by a set of points, and likewise the contour
lines, should be processed so that we have only the necessary number of
points for a good representation. The same procedure based on the Douglas-Peucker
algorithm is used, but with the difference that we don't need
to keep a maximum distance between the points.
Triangulation Storage Structures
The access to the triangulation to be generated should be the
more efficient as possible, due to the great data volume stored. A
typical triangulation for the modeling of elevation may have between
10,000 to 100,000 triangles, that should be continually modified during
the phase of creation, and be accessed often when you need to extract
data derived from the model. The structures chosen are based upon
vectors, one to store the vertices and another for the triangles.
- Storage
Structure for
Vertices
Each vertex contains the x,y and elevation z values
corresponding to a sample on the surface. These values are stored in
the TinNode class, where x and y form the point (TNpoint).
Besides these data, the
information about the source of the sample is stored. The vertices are
classified and obtained from the points on the contour lines, points on
the break lines (drainage lines), from isolated samples and points that
were eliminated in the process.
The vertices of break lines can be also classified as a
function of the way the elevation value was obtained. Since break lines
do not have elevation values associated, some method for estimation
should be used. When the break line intercepts a contour line, the
value is estimated as being the one of the contour line and is
classified as a vertex of a different type from the one whose value was
calculated by another method. Every basic storage unit constitutes a
position in a vector of size equal to the number of vertices, being
accessible directly by the vector's line index.
The initial vector size is equal to the number of samples (spot
heights plus the number of points on the contour lines after
simplification) added by 4. These 4 additional elements correspond tot
he extreme points of the bounding box of the samples, needed during the
process of triangulation.
- Storage Structure for Edges
The triangulation edges contain the information relative to
the vertices to which they are connected and to the triangles that
share this edge.
The unit used for the storage of the edge is oriented, being
the vertices classified as FROM and TO, and the triangles as being of
the RIGHT and of the LEFT.
Each basic storage unit
constitutes a position in a vector of size equal to the number of edges,
being directly accessible by the vector's line index.
The initial size of the vector is equal to the number of
samples (spot heights plus the number of points on the contour line
after simplification) multiplied by 3.
- Storage Structure for Triangles
Triangles contain the information about the three edges that
define it. To access the coordinates of the triangle's vertices it is
necessary to look at the edge's index and the index of the vertices,
obtaining thus the desired coordinates.
The triangle edges are numbered from 0 to 2, obeying the
sequence they are stored in each basic storage unit. The initial size
of the vector is the same as the number of samples (spot heights plus
the number of points on the contour lines after the simplification)
multiplied by 2.
Creation of the Delaunay Triangulation
The sampled points are used to create the irregular grid. The
method used is the incremental, where the points are inserted one by
one in the triangulation, modifying the existing triangulation,
performing Delaunay tests on the triangles generated and modified with
their neighbors. In the last phase of the process every triangle is
tested and modified, as necessary, to obey the Delaunay restrictions.
- Creation of the initial
triangles
To start the procedure of point insertion in the triangulation
it is necessary to have a initial set of triangles. These are based
upon the rectangle that bound all the samples to be used (see the
figure below). The four points that define the two initial triangles
are obtained by the vertices of the bounding rectangle, added by a
certain distance. The value used is the tolerance as a function of the
scale, being equal to 0.4 mm times the scale.
The vertices of the initial triangles are different from the
other vertices that correspond to the samples. In order to allow their
identification, the value attributed to them corresponds to the
greatest possible value represented by (MAXFLOAT) a 4-byte floating
point data structure. The value used is 3.4E37. Such value is a
standard and all the procedures should be aware of such value so they
can distinguish an invalid vertex from the normal ones.
The insertion of samples is done on the existing triangles.
Every sample to be inserted is contained in only one of the triangles
in the triangulation. Since the two initial triangles are created,
containing all the sample space, every sample must belong to one of the
existing triangles. The samples are inserted one by one, starting by
the point samples followed by the ones obtained from contour lines.
Contour line points that coincide with other points already inserted
are not to be used. This case may occur at the start or end of a
contour line, when it is represented by more than one line. Every
sample is inserted by a process that includes the definition of the
triangle that contains it, the modification of such triangle and its
neighbors, in case that is needed to obey the restriction imposed by
the Delaunay criterion.
- Application of the
Delaunay restriction to every triangle
Once all the samples have been inserted, a triangulation is
available. However, this triangulation might not have all the triangles
obeying the Delaunay criterion. In order to guarantee that the the
triangulation is Delaunay every triangle is tested against its
neighbors. The triangles are tested in the same sequence that they were
created.
The test of a triangle is performed against its 3 neighbors.
In case the tested triangle T and its neighbor TV need to be modified
to obey the criterion it is verified if the neighboring triangle was
already tested, that is, if TV lays before T in the sequence. When the
neighboring triangle TV comes before T in the sequence, TV should be
tested against its neighbors. If TV comes after T in the
sequence, the new neighbors of T are tested against T and the test
proceeds from T. In each of these tests , when any triangle is modified
and comes before T in the sequence, such triangle is tested again.
- Modifications in the
Delaunay triangulation
Over the created Delaunay triangulation modifications can be
performed so that it obeys to additional criteria. Among the
implemented modifications are the creation of a triangulation with a
convex hull, triangulation where the edges do not intercept contour lines,
triangulation where neighboring triangles have the smallest difference
in the angle between the normal.
- Creation of a
triangulation with edges that do not intercept contour lines
In the generation of a triangulation the contour lines are
used as a set of samples, where each point that compose the line is an
isolated sample. However, the contour line represents the whole x,y
region of the space between two consecutive points of the contour line
that have a constant value of the elevation, equal to the one of the
contour line. The triangulation should take into account this fact
during generation, keeping one edge over the contour line that connects
two sample points on it.
To obtain a triangulation where the edges do not intercept
contour lines, the Delaunay triangulation must be modified. The contour
lines are analyzed one by one, for every segment that connect the
samples extracted from the contour line. If the number of edges
intercepted by each segment is 1 or 2 the modification of the edge to
connect the vertices of the triangles that share this edge and that are
different from the present vertices of the edge might be enough.
If the number of intercepted edges is greater than 2, then the
points of interception are inserted in the triangulation.
- Creation of a
triangulation with the minimum difference in the angle between the
normals
The generation of a triangulation takes into account only the
X, and Y coordinates. The triangulation obtained by this method may
contain distortions due to the elevation, that is, in analyzes where
the elevation is considered the results may be more correct if the
triangulation also takes into account the Z coordinate.
One of the ways to insert the elevation information is to
modify the triangulation by using as the restriction criterion the
smallest possible angle between the normals to the surface of the
triangles. The modification in the triangulation is done in a process
similar to the one performed to obey the Delaunay criterion, that is,
every triangle created is tested against its neighbors in the same
sequence that they were created and the test of any triangle is
performed against its three neighbors. In case the triangle T and
its neighbor TV are modified during the test, it is verified if the
neighboring triangle has already been tested, that is, if TV comes
before T in the sequence. When the neighboring triangle TV comes before
T in the sequence, all the neighbors of TV should be tested again. If
the TV triangle comes after T in the sequence, the neighbors of T are
tested against T and the test proceeds from T. In every one of these
tests it is verified if the triangles modified come before T in the
sequence, and all of those that come before are tested again.
- Creation of triangles with
break lines
The triangulation created from samples can be modified with
the insertion of break lines.
The break lines can be in the same information layer as the contour
lines or in another layer. In the case of break lines in the same
layer, they are differentiated by the use of an identifier indicating
the type o the line. When the break lines are in another information
layer, the category of this layer should be different from the category
Numeric, so every line in
the layer will be considered a break line. The break lines in the input
layer will be copied and then inserted in the triangulation.
During the generation of triangular grids with break lines,
these break lines are incorporated to the triangulation, by
constituting triangle edges. The final model, that is, the irregular
triangular grid, will carry this additional information of incorporated
break lines, allowing for a more faithful representation of the
terrain, since it does not smooth features like valleys and crests.
NOTE: In SPRING this modeling can be made fro
samples (points and contour lines), regular grids or another triangular
grid (TIN). Once the triangular grid has been generated it is possible
to generate contour lines, to calculate declivity, and to generate a
regular grid from the TIN.
See
also:
How to generate a Triangular Grid.
Grids
|