Build Pyramids And Statistics (Data Management)

Summary

Traverses a folder structure, building pyramids and calculating statistics for all the raster datasets it contains. It can also build pyramids and calculate statistics for all the items in a mosaic dataset.

Usage

  • All supported raster formats will be processed.

  • Wavelet compressed raster datasets, such as ECW, JPEG2000, and MrSID, do not need to have pyramids built. These formats have internal pyramids that are created upon encoding.

Parameters

LabelExplanationData Type
Include Sub-directories
(Optional)

Specifies whether subdirectories will be included.

  • Unchecked—Does not include subdirectories.
  • Checked—Includes all the raster datasets within the subdirectories when loading. This is the default.
Boolean
Build Pyramids
(Optional)

Specifies whether pyramids will be built.

  • Unchecked—Pyramids will not be built.
  • Checked—Pyramids will be built. This is the default.
Boolean
Calculate Statistics
(Optional)

Specify whether to calculate statistics.

  • Unchecked—Does not calculate statistics.
  • Checked—Calculates statistics. This is the default.
Boolean
Include Source Datasets
(Optional)

Specify whether to calculate statistics on the source raster datasets, or calculate statistics on the raster items in a mosaic dataset. This option only applies to mosaic datasets.

  • Unchecked—Statistics will be calculated for each raster item in the mosaic dataset (on each row in the attribute table). Any functions added to the raster item will be applied before generating the statistics. This is the default.
  • Checked—Calculates statistics on the source data of the mosaic dataset.
Boolean
Block Field
(Optional)

The name of the field within a mosaic dataset's attribute table used to identify items that should be considered one item when performing some calculations and operations.

String
Estimate Mosaic Dataset Statistics
(Optional)

Specify whether to calculate statistics for the mosaic dataset (not the rasters within it). The statistics are derived from the existing statistics that have been calculated for each raster in the mosaic dataset.

  • Unchecked—Statistics are not calculated for the mosaic dataset. This is the default.
  • Checked—Statistics will be calculated for the mosaic dataset.
Boolean
X Skip Factor
(Optional)

The number of horizontal pixels between samples.

A skip factor controls the portion of the raster that is used when calculating the statistics. The input value indicates the horizontal or vertical skip factor, where a value of 1 will use each pixel and a value of 2 will use every second pixel. The skip factor can only range from 1 to the number of columns/rows in the raster.

The value must be greater than zero and less than or equal to the number of columns in the raster. The default is 1 or the last skip factor used.

Long
Y Skip Factor
(Optional)

The number of vertical pixels between samples.

A skip factor controls the portion of the raster that is used when calculating the statistics. The input value indicates the horizontal or vertical skip factor, where a value of 1 will use each pixel and a value of 2 will use every second pixel. The skip factor can only range from 1 to the number of columns/rows in the raster.

The value must be greater than zero and less than or equal to the number of rows in the raster. The default is 1 or the last y skip factor used.

Long
Ignore Values
(Optional)

The pixel values that are not to be included in the statistics calculation.

The default is no value.

Long
Pyramid levels
(Optional)

The number of reduced-resolution dataset layers that will be built. The default value is -1, which will build full pyramids. A value of 0 will result in no pyramid levels.

The maximum number of pyramid levels you can specify is 29. Any value of 30 or higher will create a full set of pyramids.

Long
Skip first level
(Optional)

Specifies whether the first pyramid level will be skipped. Skipping the first level will take up slightly less disk space but will slow down performance at these scales.

  • Unchecked—The first pyramid level will not be skipped; it will be built. This is the default.
  • Checked—The first pyramid level will be skipped; it will not be built.

Boolean
Pyramid resampling technique
(Optional)

Specifies the resampling technique that will be used to build the pyramids.

  • Nearest neighborThe value of the closest pixel will be used to assign a value to the output pixel when resampling. This is the default.
  • BilinearThe new value of a pixel will be based on a weighted distance average of the four nearest input pixel centers.
  • CubicThe new value of a pixel will be based on fitting a smooth curve through the 16 nearest input pixel centers.
String
Pyramid compression type
(Optional)

Specifies the compression type that will be used when building the raster pyramids.

  • DefaultIf the source data is compressed using a wavelet compression, pyramids will be built using the JPEG compression type; otherwise, LZ77 will be used. This is the default.
  • LZ77 CompressionThe LZ77 compression algorithm will be used to build pyramids. This compression type can be used for any data type.
  • JPEG CompressionThe JPEG compression algorithm will be used to build pyramids. Only data that adheres to the JPEG compression specification can use this compression type. If this compression type is specified, you can then set the Compression quality parameter value.
  • JPEG Luma and ChromaA lossy compression using the luma (Y) and chroma (Cb and Cr) color space components will be used.
  • No compressionNo compression will be used when building pyramids.
String
Compression quality (1-100)
(Optional)

The compression quality that will be used when pyramids are built with the JPEG compression type. The value must be between 0 and 100. The values closer to 100 will produce a higher-quality image, but the compression ratio will be lower.

Long
Skip Existing
(Optional)

Specify whether to calculate statistics only where they are missing, or regenerate them even if they exist.

  • Checked—Statistics will only be calculated if they do not already exist. This is the default.
  • Unchecked—Statistics will be calculated even if they already exist; existing statistics will be overwritten.
Boolean
Query Definition
(Optional)

An SQL expression to select raster datasets that will be processed.

SQL Expression

Derived Output

LabelExplanationData Type
Updated Input Data

The updated output workspace.

Text File; Workspace; Raster Layer; Mosaic Layer

arcpy.management.BuildPyramidsandStatistics({include_subdirectories}, {build_pyramids}, {calculate_statistics}, {BUILD_ON_SOURCE}, {block_field}, {estimate_statistics}, {x_skip_factor}, {y_skip_factor}, {ignore_values}, {pyramid_level}, {SKIP_FIRST}, {resample_technique}, {compression_type}, {compression_quality}, {skip_existing}, {where_clause})
NameExplanationData Type
include_subdirectories
(Optional)

Specifies whether subdirectories will be included.

  • NONEDoes not include subdirectories.
  • INCLUDE_SUBDIRECTORIESIncludes all the raster datasets within the subdirectories when loading. This is the default.
Boolean
build_pyramids
(Optional)

Specifies whether pyramids will be built.

  • NONEPyramids will not be built.
  • BUILD_PYRAMIDSPyramids will be built. This is the default.
Boolean
calculate_statistics
(Optional)

Specify whether to calculate statistics.

  • NONEDoes not calculate statistics.
  • CALCULATE_STATISTICSCalculates statistics. This is the default.
Boolean
BUILD_ON_SOURCE
(Optional)

Specify whether to calculate statistics on the source raster datasets, or calculate statistics on the raster items in a mosaic dataset. This option only applies to mosaic datasets.

  • NONEStatistics will be calculated for each raster item in the mosaic dataset (on each row in the attribute table). Any functions added to the raster item will be applied before generating the statistics. This is the default.
  • BUILD_ON_SOURCECalculates statistics on the source data of the mosaic dataset.
Boolean
block_field
(Optional)

The name of the field within a mosaic dataset's attribute table used to identify items that should be considered one item when performing some calculations and operations.

String
estimate_statistics
(Optional)

Specify whether to calculate statistics for the mosaic dataset (not the rasters within it). The statistics are derived from the existing statistics that have been calculated for each raster in the mosaic dataset.

  • NONEStatistics are not calculated for the mosaic dataset. This is the default.
  • ESTIMATE_STATISTICSStatistics will be calculated for the mosaic dataset.
Boolean
x_skip_factor
(Optional)

The number of horizontal pixels between samples.

A skip factor controls the portion of the raster that is used when calculating the statistics. The input value indicates the horizontal or vertical skip factor, where a value of 1 will use each pixel and a value of 2 will use every second pixel. The skip factor can only range from 1 to the number of columns/rows in the raster.

The value must be greater than zero and less than or equal to the number of columns in the raster. The default is 1 or the last skip factor used.

Long
y_skip_factor
(Optional)

The number of vertical pixels between samples.

A skip factor controls the portion of the raster that is used when calculating the statistics. The input value indicates the horizontal or vertical skip factor, where a value of 1 will use each pixel and a value of 2 will use every second pixel. The skip factor can only range from 1 to the number of columns/rows in the raster.

The value must be greater than zero and less than or equal to the number of rows in the raster. The default is 1 or the last y skip factor used.

Long
ignore_values
[ignore_value,...]
(Optional)

The pixel values that are not to be included in the statistics calculation.

The default is no value.

Long
pyramid_level
(Optional)

The number of reduced-resolution dataset layers that will be built. The default value is -1, which will build full pyramids. A value of 0 will result in no pyramid levels.

The maximum number of pyramid levels you can specify is 29. Any value of 30 or higher will create a full set of pyramids.

Long
SKIP_FIRST
(Optional)

Specifies whether the first pyramid level will be skipped. Skipping the first level will take up slightly less disk space but will slow down performance at these scales.

  • NONEThe first pyramid level will not be skipped; it will be built. This is the default.
  • SKIP_FIRSTThe first pyramid level will be skipped; it will not be built.
Boolean
resample_technique
(Optional)

Specifies the resampling technique that will be used to build the pyramids.

  • NEARESTThe value of the closest pixel will be used to assign a value to the output pixel when resampling. This is the default.
  • BILINEARThe new value of a pixel will be based on a weighted distance average of the four nearest input pixel centers.
  • CUBICThe new value of a pixel will be based on fitting a smooth curve through the 16 nearest input pixel centers.
String
compression_type
(Optional)

Specifies the compression type that will be used when building the raster pyramids.

  • DEFAULTIf the source data is compressed using a wavelet compression, pyramids will be built using the JPEG compression type; otherwise, LZ77 will be used. This is the default.
  • LZ77The LZ77 compression algorithm will be used to build pyramids. This compression type can be used for any data type.
  • JPEGThe JPEG compression algorithm will be used to build pyramids. Only data that adheres to the JPEG compression specification can use this compression type. If this compression type is specified, you can then set the Compression quality parameter value.
  • JPEG_YCBCRA lossy compression using the luma (Y) and chroma (Cb and Cr) color space components will be used.
  • NONENo compression will be used when building pyramids.
String
compression_quality
(Optional)

The compression quality that will be used when pyramids are built with the JPEG compression type. The value must be between 0 and 100. The values closer to 100 will produce a higher-quality image, but the compression ratio will be lower.

Long
skip_existing
(Optional)

Specify whether to calculate statistics only where they are missing, or regenerate them even if they exist.

  • SKIP_EXISTINGStatistics will only be calculated if they do not already exist. This is the default.
  • OVERWRITEStatistics will be calculated even if they already exist; existing statistics will be overwritten.
Boolean
where_clause
(Optional)

An SQL expression to select raster datasets that will be processed.

SQL Expression

Derived Output

NameExplanationData Type
out_workspace

The updated output workspace.

Text File; Workspace; Raster Layer; Mosaic Layer

Code sample

BuildPyramidsAndStatistics example 1 (Python window)

This is a Python sample for the BuildPyramidsAndStatistics tool.

import arcpy
from arcpy import env
env.workspace = "c:/data"
arcpy.env.pyramid = "PYRAMIDS 3 BILINEAR JPEG"
arcpy.env.rasterStatistics = "STATISTICS 4 6 (0)"
arcpy.BuildPyramidsandStatistics_management("folder", "INCLUDE_SUBDIRECTORIES",
                                            "BUILD_PYRAMIDS", "CALCULATE_STATISTICS")
BuildPyramidsAndStatistics example 2 (stand-alone script)

This is a Python script sample for the BuildPyramidsAndStatistics tool.

##====================================
##Build Pyramids and Statistics
##Usage: BuildPyramidsandStatistics_management in_workspace {INCLUDE_SUBDIRECTORIES
##                                                 | NONE} {BUILD_PYRAMIDS | NONE}
##                                                 {CALCULATE_STATISTICS | NONE}
    
try:
    import arcpy
    arcpy.env.workspace = r"C:/Workspace"

    ##Define parameters for build pyramids and calculate statitics in environment setting
    arcpy.env.pyramid = "PYRAMIDS 3 BILINEAR JPEG"
    arcpy.env.rasterStatistics = "STATISTICS 4 6 (0)"
    
    ##Build pyramids and calculate statistics for all raster in a folder
    arcpy.BuildPyramidsandStatistics_management("folder", "INCLUDE_SUBDIRECTORIES",
                                                "BUILD_PYRAMIDS", "CALCULATE_STATISTICS")
    
    ##Build pyramids and calculate statistics for all raster in a GDB
    arcpy.BuildPyramidsandStatistics_management("fgdb.gdb", "INCLUDE_SUBDIRECTORIES",
                                                "BUILD_PYRAMIDS", "CALCULATE_STATISTICS")
    
    ##Build pyramids and calculate statistics for all raster in a Mosaic Dataset
    arcpy.BuildPyramidsandStatistics_management("fgdb.gdb/md", "INCLUDE_SUBDIRECTORIES",
                                                "BUILD_PYRAMIDS", "CALCULATE_STATISTICS")

except:
    print "Build Pyramids and Statistics example failed."
    print arcpy.GetMessages()

Related topics