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 serviceTo 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 |