# REGION.sml

#### Syntax Highlighing:

```comments, key words, predefined symbols, class members & methods, functions & classes
```
```# REGION.SML
# sample script for tutorial "Writing Scripts with SML".
# Opens two region objects, finds their
# intersection, and uses it to find information
# about point elements in a vector object.
clear();
# Get two input region objects and an input vector with 3D points.
region Reg1, Reg2, IntReg;
vector V;
GetInputRegion(Reg1);
GetInputRegion(Reg2);
GetInputVector(V);
# Get a new output region object.
GetOutputRegion(IntReg);
# Find intersection of two input regions and assign
# to output region.
IntReg = RegionAND(Reg1,Reg2);
# Get georef information for input vector.
class Georef georefV;
georefV = GetLastUsedGeorefObject(V);
# Find the number of vector points that lie in the intersection
# region and the maximum point Z value and its location.
numeric x, y, z;
numeric maxX, maxY, maxZ, count;
numeric map_x, map_y;
for each point in V {
x = V.point.Internal.x;	# get point coordinates from
y = V.point.Internal.y;	# Internal element table.
z = V.point.Internal.z;
# transform x and y object coordinates to map coordinates.
ObjectToMap(V,x,y,georefV,map_x,map_y);
# loop to find points in region.
if (PointInRegion(map_x,map_y,IntReg)) {
count = count + 1;
if (z > maxZ ) then	# set values for current maxZ point.
maxZ = z;
maxX = map_x;
maxY = map_y;
}
}
print("Number of points in region intersect =", count);
print("Maximum point elevation in region intersect =", maxZ);
print("Map x-coordinate of maximum elevation point =", maxX);
print("Map y-coordinate of maximum elevation point =", maxY);```