1

I am automating the creation a mosaic raster dataset from thousands of individual elevation tiles and am tying to extract the pixel type metadata from the input tiles and specify this pixel type in arcpy.MosaicToNewRaster(). My tiles are 32-bit float and have a uniform pixel type. If I leave pixel type empty, the default value for MosaicToNewRaster() is 8-bit unsigned, which results in a mosaic where all pixel values are 255. I have tried to use both Describe and RasterInfo on the first tile in the directory and they both return a string '32F'. However, when I use this string value in MosaicToNewRaster, it returns the following error:

ExecuteError: Failed to execute. Parameters are not valid. ERROR 000676: Output file format with specified pixel type or number of bands or colormap is not supported. The suggested pixel type is: 1_BIT Failed to execute (MosaicToNewRaster).

My code:

# import arcpy, os

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
arcpy.env.workspace = "My_Data_Directory_Path"

# Create list of input raster tiles
list_opr_tiles = arcpy.ListRasters()
list_tile_paths = [os.path.join("My_Data_Directory_Path", tile) for tile in list_opr_tiles]

# Instantiate instance of RasterInfo object
rasInfo = arcpy.Raster(list_tile_paths[0]).getRasterInfo()

# Assign variable to raster's pixelType property
string_pixel_type = rasInfo.getPixelType()

# Assign variable to raster's bandCount property
string_band_count = rasInfo.getBandCount()

arcpy.MosaicToNewRaster_management(input_rasters = list_tile_paths, output_location = "My_Output_Directory_Path", raster_dataset_name_with_extension = "My_Mosaic_Name", pixel_type = string_pixel_type, number_of_bands = string_band_count)

I have also tried using Describe and that returns '32F' as well.

string_pixel_type = arcpy.Describe(list_tile_paths[0]).PixelType

When I test what I'm trying to achieve in the Pro GUI and export the Mosaic To New Raster Tool to python I get:

arcpy.management.MosaicToNewRaster( "PROJCS['NAD_1983_2011_UTM_Zone_13N',GEOGCS['GCS_NAD_1983_2011',DATUM['D_NAD_1983_2011',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-105.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]", "32_BIT_FLOAT", 0.5, 1, "LAST", "FIRST")

I can see that if I manually pass a '32_BIT_FLOAT' argument to the MosaicToNewRaster() pixel_type parameter, this will technically work. However, that is not what I want to do as it is not robust (I have a number of projects to run this on and their pixel value could change).

Is there another way that I'm not thinking of to pass the pixel type value? It's unclear to me why MosaicToNewRaster can pick up the cell size and spatial reference system, but not the pixel type or band count from the tiles forming the mosaic.

2 Answers 2

2

There's an ArcGIS Idea about this:

arcpy.Describe.PixelType returns useless value

From the help you can get the pixel types output by getPixelType and required by MosaicToNewRaster:

enter image description here

enter image description here

You can use that info to build a dict that you can query:

pixel_types = {
    "U1": "1_BIT",
    "U2": "2_BIT",
    "U4": "4_BIT",
    "S8": "8_BIT_SIGNED",
    "U8": "8_BIT_UNSIGNED",
    "S16": "16_BIT_UNSIGNED",
    "U16": "16_BIT_SIGNED",
    "S32": "32_BIT_UNSIGNED",
    "U32": "32_BIT_SIGNED",
    "F32": "32_BIT_FLOAT",
    "F64": "64_BIT"
}

pixel_type = pixel_types[rasInfo.getPixelType()]
-1

I believe the signed and unsigned pairs in the dictionary are backwards (e.g., "S8" should be "8_BIT_SIGNED" not "8_BIT_UNSIGNED").

https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/rasterinfo-class.htm

It should be:

pixel_types = {
    "U1": "1_BIT",
    "U2": "2_BIT",
    "U4": "4_BIT",
    "S8": "8_BIT_SIGNED",
    "U8": "8_BIT_UNSIGNED",
    "S16": "16_BIT_SIGNED",
    "U16": "16_BIT_UNSIGNED",
    "S32": "32_BIT_SIGNED",
    "U32": "32_BIT_UNSIGNED",
    "F32": "32_BIT_FLOAT",
    "F64": "64_BIT"
}
1
  • Thanks, I've edited my answer to correct the error. Next time you see an issue like this, I suggest you leave a comment or edit the answer yourself so the original user gets notified.
    – user2856
    Commented Mar 12 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.