Select to view content in your preferred language

export raster

549
1
06-29-2023 05:23 AM
JúliaMat
New Contributor

Hello!

I'm trying to convert 16-bit rasters to 8-bit rasters in ArcGIS Pro. I'm attempting to do it automatically.

However, all I'm getting are blank rasters without any information.

Here's what I used:

import arcpy
from arcpy.sa import *

input_folder = r"path_to_folder"
output_folder = r"path_to_folder"

# Nastavenie pracovného priečinka
arcpy.env.workspace = input_folder

# Získanie všetkých rastrových súborov v pracovnom priečinku
input_rasters = arcpy.ListRasters("*", "TIF")

for input_raster in input_rasters:
input_raster_path = input_folder + "\\" + input_raster
output_raster = output_folder + "\\" + input_raster
arcpy.CopyRaster_management(input_raster_path, output_raster, pixel_type="8_BIT_UNSIGNED")
rendered_raster = arcpy.ia.Render(input_raster_path, {'bands': [1, 2, 3]}).save(output_raster)

I need to define renderer settings, any idea how? 

0 Kudos
1 Reply
Taren_Esri
Esri Contributor

Hi @JúliaMat 

I ran the attached script in a Notebook in ArcGIS Pro. My version of Copy Raster was the result of dragging and dropping a successful Copy Raster GP tool result into the Python window. Oddly enough this worked just fine as the GP tool, and successfully converted to 8bit. Running the same code in the Notebook script failed to convert to 8 bit, which seems like a bug to me. I'd ask that you open up a Support case so we can get that logged and investigate further. Outside of this, I found I was able to successfully view the rasters within ArcGIS Pro once I selected the "DRA" button under the Raster Layer ribbon. I could not find an equivalent command for arcpy. Hopefully this helps a bit. 

import arcpy
from arcpy.sa import *
from arcpy.ia import *
inputR = r"C:\arcgis\ArcTutor\Raster\Data\Amberg_tif"
output = r"C:\temp"
arcpy.env.workspace = input
input_rasters = arcpy.ListRasters("*","TIF")
input_rasters
['090160.tif', '090161.tif', '090162.tif', '090163.tif', '100176.tif', '100177.tif', '100178.tif', '100179.tif', '110208.tif', '110209.tif', '110210.tif', '110211.tif']
for input_raster in input_rasters:
    input_raster_path = inputR + "\\" + input_raster
    output_raster = output + "\\" + input_raster
    arcpy.management.CopyRaster(
    in_raster= input_raster_path,
    out_rasterdataset= output_raster,
    config_keyword="",
    background_value=None,
    nodata_value="256",
    onebit_to_eightbit="NONE",
    colormap_to_RGB="NONE",
    pixel_type="8_BIT_UNSIGNED",
    scale_pixel_value="NONE",
    RGB_to_Colormap="NONE",
    format="TIFF",
    transform="NONE",
    process_as_multidimensional="CURRENT_SLICE",
    build_multidimensional_transpose="NO_TRANSPOSE"
)
    rendered_raster = arcpy.ia.Render(input_raster_path, {'bands': [1, 2, 3]}).save(output_raster)
rendered_raster

 

 

 

 

0 Kudos