Skip to content

Volume measurement analysis object

This sample demonstrates how to measure the volumes of ground surface features both programmatically and interactively, using a real-world–style example: planning a track and field facility. You will learn how to create a volume measurement analysis, configure it for cut-and-fill and stockpile calculations, draw measurement areas interactively, and retrieve results for display or further processing.

To configure the analysis, create a VolumeMeasurementAnalysis instance and choose the measurement method by setting the measureType property. When using the "cut-fill" measure type, you can further customize the analysis with VolumeMeasurementCutFillOptions. If you already have a polygon defining the measurement area, set it using the geometry property. If not, leave it undefined and refer to the later code snippet that demonstrates how to create the polygon interactively. Finally, add the analysis to the scene.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
// Configure the analysis
const volumeMeasurementAnalysis = new VolumeMeasurementAnalysis({
  measureType: "cut-fill", // the default value
  cutFillOptions: {
    targetElevation: 659 // defaults to meters
  },
});

// Add the analysis to the scene
viewElement.analyses.add(volumeMeasurementAnalysis);

To obtain the measurement results, retrieve the VolumeMeasurementAnalysisView3D using the Scene component's whenAnalysisView.

Use dark colors for code blocksCopy
1
2
3
4
5
// Retrieve measured results from analysis view once available
const analysisView = await viewElement.whenAnalysisView(volumeMeasurementAnalysis);
await reactiveUtils.whenOnce(() => analysisView.result);

const result = analysisView.result;

To draw an area interactively, use the VolumeMeasurementAnalysisView3D.place() method after retrieving the VolumeMeasurementAnalysisView3D.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
// Cancel the placement operation at some later point
// by calling abortController.abort()
const abortController = new AbortController();

try {
  await analysisView.place({ signal: abortController.signal });
} catch (error) {
  if (error.name === "AbortError") {
    console.log("Placement operation was cancelled.");
  }
}

Finally, VolumeMeasurementAnalysis allows you to fully customize both the input units and display units to suit your specific use case.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
const volumeMeasurementAnalysis = new VolumeMeasurementAnalysis({
  // Units to display in the UI and in the results
  displayUnits: {
    volume: "square-meters",
    elevation: "meters"
  },
  // Units for input values
  inputUnits: {
    elevation: "feet"
  }
});
Image preview of related sample Analysis objects

Analysis objects

Image preview of related sample Area measurement analysis object

Area measurement analysis object

Image preview of related sample Measurement components in 3D

Measurement components in 3D

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.