SclFindTriangle
Overview
You can use SclFindTriangle to locate the triangle in a specified trisolation that contains a specified X,Y position and return the Z value of the triangle surface at that position.
Synopsis
$TrisolationHandle SclFindTriangle SeedTriangleIndex $x $y z Description
Description
You can use SclFindTriangle to find, for a specified trisolation, the triangle that encloses a specified X,Y position and interpolate the Z value and description fields at the X,Y position of interest.
The function requires a trisolation that has been created by the CREATE DTM function as the algorithm that performs the search across the triangle mesh expects the triangles to be organised in a certain manner.
Arguments
- TrisolationHandle
- SeedTriangleIndex
- x
- y
- z
- Description
Pass by value. This is the handle to the trisolation within which the triangle containing the specified X,Y position of interest is to be found.
Pass by value. The index of the triangle from which the search for the position of interest is to commence. This variable is modified to contain the index of the triangle that contains the position of interest on successful completion of the search process. The most appropriate initial value for this argument is 0. That is, the first triangle in the trisolation.
The search starts at the triangle specified by the seed triangle and uses the neighbouring triangle indices to rapidly navigate through the triangle network until the triangle containing the position of interest is found.
For best performance the value returned in this variable should be used on subsequent calls to SclFindTriangle, particularly when subsequent positions of interest are geographically related. This permits the search to start from a triangle which is already close to the desired position thus speeding up the search.
Pass by value. The X value of the location of interest.
Pass by value. The Y value of the location of interest.
Pass by reference. The name of the variable that will be assigned the Z value of the trisolation surface at the specified X,Y position.
Pass by reference. If the description fields of the points that are used as triangle vertices contain numeric values then these numeric values will be interpolated just as the vertex Z values are to give a value at the position of interest.
If the description fields contain non-nueric data then the values of one of the triangle vertex points will be returned. It is not possible to determine from which vertex the values will be obtained.
Returns
$SCL_TRUE if the position of interest is inside the perimter of the trisolation.
$SCL_FALSE if the position of interest is outside the perimeter of the trisolation.
Note that a simple boundary check of the position of interest against the trisolation perimeter is performed before the search through the triangle network is performed.
Examples
#
#
# Load a DTM and then find the Z value of the DTM triangles for each
# point in the first segment of string 1
#
# This example also shows how to handle the situation when a point is
# outside the trisolation perimeter
#
# create the SWA and load the DTM
SclCreateSwa SwaHandle "findtriangle"
if {[catch {$SwaHandle SclSwaOpenFile pit1.dtm }] != 0} {
# this is how we trap for errors
puts "Error loading pit1.dtm"
} else {
# load was successful - so get trisolation handle
$SwaHandle SclCreateTriobject TriobjectHandle 1
$TriobjectHandle SclCreateTrisolation TrisolationHandle 1
set SeedTriangle 0
# get segment handle
$SwaHandle SclCreateString StringHandle 1
$StringHandle SclGetItem SegmentHandle 0
set numpoints [$SegmentHandle SclCountItems]
# for each point for DTM Z value
for {set i 0} {$i < $numpoints} {incr i} {
$SegmentHandle SclGetItem PointHandle $i
set x [$PointHandle SclGetValueByName x]
set y [$PointHandle SclGetValueByName y]
set z [$PointHandle SclGetValueByName z]
$TrisolationHandle SclFindTriangle SeedTriangle $x $y zdtm desc
puts "Triangle found = $SeedTriangle, Point Z value=$z, DTM Z value = $zdtm"
}
}
# show how it works for some random locations
set x 2400
set y 6800
$TrisolationHandle SclFindTriangle SeedTriangle $x $y zdtm desc
puts "Triangle found = $SeedTriangle, Point Z value=$z, DTM Z value = $zdtm"
set x 2420
set y 6820
$TrisolationHandle SclFindTriangle SeedTriangle $x $y zdtm desc
puts "Triangle found = $SeedTriangle, Point Z value=$z, DTM Z value = $zdtm"
# show how to handle a point being outside the trisolation boundary
set x 0
set y 0
set result [$TrisolationHandle SclFindTriangle SeedTriangle $x $y zdtm desc]
if {$result} {
puts "Triangle found = $SeedTriangle, Point Z value=$z, DTM Z value = $zdtm"
} else {
puts "point x=$x, y=$y is outside the DTM"
}
# destroy the swa before exiting
SclDestroy SwaHandle
|