2

I am trying to create a mosaic dataset that keeps the properties of the original rasters. However, when I try to use arcpy's MosaicToNewRaster, the nodata type of -999999.0 is not carried over. I would like to keep this default.

As a Minimum Reproducible Example, I am using the first three rasters on this page: https://rockyweb.usgs.gov/vdelivery/Datasets/Staged/Elevation/OPR/Projects/CO_NorthwestCO_2020_D20/CO_NWCO_1_2020/TIFF/

import arcpy
import os

directory_tiff = 'myPathToDownloadedTiffs'
string_raster_mosaic = 'Mosaic_Test.tif'

arcpy.env.workspace = directory_tiff
list_opr_tiles = arcpy.ListRasters()

rasInfo = arcpy.Raster(list_opr_tiles[0]).getRasterInfo()

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

string_pixel_type = pixel_types[rasInfo.getPixelType()]

arcpy.MosaicToNewRaster_management(input_rasters = list_opr_tiles, output_location = directory_tiff, raster_dataset_name_with_extension = string_raster_mosaic, pixel_type = string_pixel_type, number_of_bands = 1)

The code above produces a mosaic, and recognizes nodata correctly, but the nodata value in properties changes to 3.4e+38.

I then tried adding an additional step to try to assign a no-data with SetRasterProperties. That changes the nodata property value to -999999.0, but changes actual no data values to 3.4e+38.

How can I use mosaic to new raster to create a mosaic honoring the original no data of -999999.0? I am trying to avoid copying the first raster and mosaicking the others to that copy because I have 7k+ rasters and may have to break up the tiles into groups to create sub-mosaics before combining those into a final mosaic.

3
  • 1
    Alternative method is to use osgeo.gdal.BuildVRT. The osgeo.gdal package is included in the base ArcGIS Pro python environment.
    – user2856
    Commented Jan 26 at 4:51
  • The mosaic tool honours nodata environment settings, try setting that?
    – Hornbydd
    Commented Jan 26 at 15:29
  • Thank you @Hornbydd. I did try arcpy.env.nodata = 'NONE' right before MosaicToNewRaster and the nodata value is still converted to 3.4e+38.
    – ENIAC-6
    Commented Jan 26 at 16:07

1 Answer 1

1

Thanks to user2856's comment, using gdal from my cloned arcgispro-py3 environment worked (code from: https://www.youtube.com/watch?v=sBBMKbAj8XE).

from osgeo import gdal
import glob, os

directory_tiff = 'myPathToDownloadedTiffs'
os.chdir(directory_tiff)
demList = glob.glob('*.tif')
vrt = gdal.BuildVRT('merged.vrt', demList)
gdal.Translate('mergedDEM2.tif', vrt)
vrt = None

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.