PixelBlock

Zusammenfassung

Defines a group or block of pixels to include for raster processing. The PixelBlockCollection object is made up of one or more PixelBlock objects.

Diskussion

The PixelBlock object defines a block of pixels within a raster to use for processing. It is used in conjunction with the PixelBlockCollection object to iterate through one or more large rasters for processing.

Syntax

PixelBlock
 (data, extent)
ParameterErläuterungDatentyp
data

A NumPy array containing the pixel values for the pixel block.

If the raster is not multidimensional, the shape of the array should be (rows, columns, bands).

If the raster is multidimensional, the shape of the array should be (slices, rows, columns, bands).

NumPyArray
extent

The spatial extent of the pixel block.

Extent

Eigenschaften

EigenschaftErläuterungDatentyp
cell_size
(Schreibgeschützt)

The cell size of the pixels in the pixel block. This is a tuple containing the cell size in the x-direction and the y-direction (x-size, y-size).

tuple
tlc
(Schreibgeschützt)

The coordinates of the pixel block's upper left corner.

Point
spatial_reference
(Schreibgeschützt)

The spatial reference of the exported image. Supported options include the following:

  • None
  • SpatialReference data type
  • ICS or ICS:<object_id>, where object_id selects the specific raster whose image coordinate system should be used.
If a value is not specified, the spatial reference of the raster dataset is used.

SpatialReference

Methodenübersicht

MethodeErläuterung
getData ()

Returns the NumPy array within the pixel block.

Methoden

getData ()
Rückgabewert
DatentypErläuterung
NumPyArray

The NumPy array object from the pixel block.

Codebeispiel

PixelBlock example

Iterates through pixel blocks to calculate the total area of forest in a land cover raster.

import arcpy 

# Specify the input raster
in_raster = arcpy.Raster("landcover.tif")  

# Create a PixelBlockCollection

blockCollection = arcpy.ia.PixelBlockCollection(
	in_raster, pixel_block_size = (512, 512), nodata_to_values = -1) 
forest_cell_count = 0 

# Iterate through each PixelBlock 

try: 
    while True: 
        pixelblock = next(blockCollection) 
        np_array = pixelblock.getData() 
        forest_cell_count+= np.count_nonzero(np_array == 1) # value = 1 is forest class 
except StopIteration: 
    pass 
print ("total forest pixels : " + str(forest_cell_count))