OpenRoads Designer CONNECT Edition SDK Help

Quick statistics of terrain model attached like (Highest elevation, mean Elevation, lowest Elevation)

The below code shows how to get the terrain from geometry model and calculate the high, low, and mean terrain elevation from all terrain points.

//Required References
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.SDK;
using Bentley.GeometryNET;
using Bentley.MstnPlatformNET;
using Bentley.TerrainModelNET;

 public void QuickStatisticsOfTerrainModelAttached()
        {
            Bentley.CifNET.GeometryModel.SDK.TerrainSurface terrainSurface = null;
            try
            {
                //Get active dgn model
                Bentley.DgnPlatformNET.DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
                //Create connection to dgnModel
                Bentley.CifNET.SDK.ConsensusConnection consensusConnection = new ConsensusConnection(dgnModel);
                //Get active geometric model
                Bentley.CifNET.GeometryModel.SDK.GeometricModel geometricModel = consensusConnection.GetActiveGeometricModel();
                if (geometricModel.ActiveSurface == null) return;
                List<DPoint3d> pointList = new List<DPoint3d>();
                //Get active terrain
                terrainSurface = geometricModel.ActiveSurface as TerrainSurface;
                if (terrainSurface == null) return;

                //Get the low and high elevation value from all terrain points
                var range = terrainSurface.DTM.Range3d;
                double dLowElevation = range.Low.Z;
                double dHighElevation = range.High.Z;

                double sumOfElevations = 0.0;
                long count = terrainSurface.DTM.VerticesCount;

                //Browse all points of terrain surface
                terrainSurface.DTM.BrowsePoints(new PointsBrowsingCriteria(), (DPoint3d[] tPoint, object oArg) =>
                {
                    foreach (DPoint3d point in tPoint)
                    {
                        sumOfElevations += point.Z;
                    }
                    return true;
                }
                , null);

                //Calculate the mean elevation
                double dMeanElevation = sumOfElevations / count;

                Trace.WriteLine("Highest Elevation : " + dHighElevation);
                Trace.WriteLine("Mean Elevation : " + dMeanElevation);
                Trace.WriteLine("Lowest Elevation : " + dLowElevation);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }

Output