ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / GetZsFromSurfaceAsync Method / GetZsFromSurfaceAsync(Geometry) Method
The input geometry
Example

In This Topic
    GetZsFromSurfaceAsync(Geometry) Method
    In This Topic
    Obtains a geometry that is similar to the given input geometry, where some or all Z values are populated from the default Ground Surface Layer.
    Syntax
    Public Overloads Function GetZsFromSurfaceAsync( _
       ByVal geometry As Geometry _
    ) As Task(Of SurfaceZsResult)
    public Task<SurfaceZsResult> GetZsFromSurfaceAsync( 
       Geometry geometry
    )

    Parameters

    geometry
    The input geometry

    Return Value

    A result that contains a status, plus an output geometry only if the status is favorable.
    Exceptions
    ExceptionDescription
    The input geometry is null.
    This Map does not have a Ground Surface Layer.
    This Map does not have a CIM definition.
    This Map does not have any surfaces.
    Remarks
    If the surface has no data at a particular input geometry point, then the corresponding output geometry point Z will be set to the value specified in SurfaceZsMissingHandler.DefaultOutputZ.
    Example
    Get Z values from the default ground surface
    {
        //Note: This method must be called on the MCT
        // Get the center of the map's full extent
        MapPoint mapPoint = MapView.Active.Map.CalculateFullExtent().Center;
        //Pass any Geometry type to GetZsFromSurfaceAsync
        var surfaceZResult = await MapView.Active.Map.GetZsFromSurfaceAsync(mapPoint);
        if (surfaceZResult.Status == SurfaceZsResultStatus.Ok)
        {
            // cast to a mapPoint
            var mapPointZ = surfaceZResult.Geometry as MapPoint;
            var z = mapPointZ.Z;
        }
    }
    Get Z values from a specific surface
    {
        var eleLayer = MapView.Active.Map.GetElevationSurfaceLayers().FirstOrDefault(l => l.Name == "TIN");
        //Pass any Geometry type to GetZsFromSurfaceAsync
        //Note: This method must be called on the MCT
        //Ensure the feature layer is a line layer and is Z aware
        var selectedFeatures = featureLayer.GetSelection();
        var rowCursor = selectedFeatures.Search();
        while (rowCursor.MoveNext())
        {
            var feature = rowCursor.Current as Feature;
            var polyline = feature.GetShape() as Polyline;
            var zResult = await MapView.Active.Map.GetZsFromSurfaceAsync(polyline, eleLayer);
            if (zResult.Status == SurfaceZsResultStatus.Ok)
            {
                var polylineZ = zResult.Geometry as Polyline;
                // process the polylineZ
                // For example, you can iterate through the points and access their Z values
            }
        }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also