This document is archived and information here might be outdated.  Recommended version.


How to make measurements from images (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with image and raster data > How to make measurements from images

How to make measurements from images


Summary
You can measure point, length, centroid, area, perimeter, and building height from raster products, mosaic datasets, image services, and some National Imagery Transmission Format (NITF) images if these contain certain metadata information.
In general, basic measurement including measuring point, length, area, and centroid requires that the data have spatial reference. Measuring building height requires the data to have camera information (and/or sun angle if measuring the height using shadow). 3D mensuration (surface area and length) requires a digital elevation model (DEM).
Developers use the Mensuration class to perform these measurements.

In this topic


Basic measurement

The following code example shows how to measure length from a dataset. If the elevation model is set, you can measure the true length along the terrain. 
[C#]
static void MeasureLength(IRaster inputRaster, IPoint firstPoint, IPoint secondPoint,
    IRaster dem)
{
    //Note, make sure that the two points have the same spatial reference as the input raster.
    //Create the Mensuration class.
    IMensuration measure=new MensurationClass();
    measure.Raster=inputRaster;
    if (dem != null)
    {
        measure.DEM=dem;
    }

    //Define the mensuration result class.
    IDistanceMeasurement distanceResult=new DistanceMeasurementClass();
    IAngularMeasurement angularResult=new AngularMeasurementClass();

    //Measure in 3D if possible.
    IMensuration3D measure3D=(IMensuration3D)measure;
    if (measure3D.CanMeasure3D == true)
    {
        measure.GetDistance(firstPoint, secondPoint, out distanceResult);
        double result3d=distanceResult.DistanceMeasurement;
        double uncertainty3d=distanceResult.DistanceUncertainty;
        measure.GetAzimuthAngle(firstPoint, secondPoint, out angularResult);
        double result_angluar3d=angularResult.AngleMeasurement;
        double uncertainty_angular3d=angularResult.AngleUncertainty;
    }

    //Measure in 2D otherwise.
    if (measure.CanMeasure == true)
    {
        measure.GetDistance(firstPoint, secondPoint, out distanceResult);
        double result=distanceResult.DistanceMeasurement;
        double uncertainty=distanceResult.DistanceUncertainty;
        measure.GetAzimuthAngle(firstPoint, secondPoint, out angularResult);
        double result_angluar=angularResult.AngleMeasurement;
        double uncertainty_angular=angularResult.AngleUncertainty;
    }
}
[VB.NET]
Private Shared Sub MeasureLength(inputRaster As IRaster, firstPoint As IPoint, secondPoint As IPoint, dem As IRaster)
'Note, make sure that the two points have the same spatial reference as the input raster.
'Create the Mensuration class.
Dim measure As IMensuration=New MensurationClass()
measure.Raster=inputRaster
If dem IsNot Nothing Then
    measure.DEM=dem
End If

'Define the mensuration result class.
Dim distanceResult As IDistanceMeasurement=New DistanceMeasurementClass()
Dim angularResult As IAngularMeasurement=New AngularMeasurementClass()

'Measure in 3D if possible.
Dim measure3D As IMensuration3D=DirectCast(measure, IMensuration3D)
If measure3D.CanMeasure3D=True Then
    measure.GetDistance(firstPoint, secondPoint, distanceResult)
    Dim result3d As Double=distanceResult.DistanceMeasurement
    Dim uncertainty3d As Double=distanceResult.DistanceUncertainty
    measure.GetAzimuthAngle(firstPoint, secondPoint, angularResult)
    Dim result_angluar3d As Double=angularResult.AngleMeasurement
    Dim uncertainty_angular3d As Double=angularResult.AngleUncertainty
End If

'Measure in 2D otherwise.
If measure.CanMeasure=True Then
    measure.GetDistance(firstPoint, secondPoint, distanceResult)
    Dim result As Double=distanceResult.DistanceMeasurement
    Dim uncertainty As Double=distanceResult.DistanceUncertainty
    measure.GetAzimuthAngle(firstPoint, secondPoint, angularResult)
    Dim result_angluar As Double=angularResult.AngleMeasurement
    Dim uncertainty_angular As Double=angularResult.AngleUncertainty
End If
End Sub

Measuring height

Measuring building height requires that the dataset have the following camera model and/or sun information in addition to spatial reference:
  • Camera model is required if measuring height using the GetHeightFromBaseAndTop method.
  • Camera model and sun information is required if measuring height using the GetHeightFromTopAndTopShadow method.
  • Sun information is required if measuring height using the GetHeightFromBaseAndTopShadow method.
The following code example shows how to measure the height using GetHeightFromBaseAndTop:
[C#]
static void MeasureBuildHeight(IRaster inputRaster, IPoint firstPoint, IPoint
    secondPoint)
{
    //Note, make sure that the two points have the same spatial reference as the input raster.
    //Define the Mensuration class and set the input.
    IMensuration measure=new MensurationClass();
    measure.Raster=inputRaster;

    //Define the mensurement result.
    IHeightMeasurement heightResult=new HeightMeasurementClass();

    //Measure.
    if (measure.CanMeasureHeightBaseToTop == true)
    {
        measure.GetHeightFromBaseAndTop(firstPoint, secondPoint, out heightResult);
        double height=heightResult.HeightMeasurement;
        double uncertainty=heightResult.HeightUncertainty;
    }
}
[VB.NET]
Private Shared Sub MeasureBuildHeight(inputRaster As IRaster, firstPoint As IPoint, secondPoint As IPoint)
'Note, make sure that the two points have the same spatial reference as the input raster.
'Define the Mensuration class and set the input.
Dim measure As IMensuration=New MensurationClass()
measure.Raster=inputRaster

'Define the mensurement result.
Dim heightResult As IHeightMeasurement=New HeightMeasurementClass()

'Measure.
If measure.CanMeasureHeightBaseToTop=True Then
    measure.GetHeightFromBaseAndTop(firstPoint, secondPoint, heightResult)
    Dim height As Double=heightResult.HeightMeasurement
    Dim uncertainty As Double=heightResult.HeightUncertainty
End If
End Sub


See Also:

How to perform mensuration on an image service




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine