1

In my ModelBuilder toolchain I created a raster and want to create another empty raster wit the same properties. For this purpouse I choose the "Create Raster Dataset". For this tool I need the following properties of my raster: number of bands and the pixel type.

The Number of bands I can extract with "Get Raster Properties" but I can't get the pxiel type with this tool. Is there a way to get to the pixel type information?

enter image description here

2

It is possible using arcpy.Describe and Raster Band properties, for example:

import arcpy
raster = r'C:\Test\Reprojected_epsg_3006.tif\Band_1'
print arcpy.Describe(raster).pixelType

Outputs:

U16

You can then integrate the code in your model following:

Integrating scripts within a model

  • How to pass 'U16' to "Create Raster Dataset"? Because the tool take string argument like '16_BIT_UNSIGNED' and doesn't accept 'U16' string as 'pixel type' argument in Python console or in tool Dialog window. – Kadir Şahbaz Apr 10 '18 at 7:35
  • Dont know how asker solved it. I would use a dictionary – BERA Apr 10 '18 at 7:37
  • I use dictionary like my answer. "Get Raster Properties" tool accepts output of Script as pixel type parameter in Python console but doesn't accept in ModelBuilder. Do you have any idea? – Kadir Şahbaz Apr 10 '18 at 7:42
  • Try Create Raster Dataset in the script instead of ModelBuilder – BERA Apr 10 '18 at 7:44
2

Using "Get Raster Properties" tool, you can get "Pixel Type", too.

VALUETYPE option gives you Pixel Type as a string integer. Refer to Get Raster Properties

VALUETYPE

A script like below helps to get corresponding string. Look at the link in @BERA's post to add the script to ArcToolBox and a model.

import arcpy
string = arcpy.GetParameterAsText(0)

pixel_types = {
    u"0": "1_BIT",
    u"1": "2_BIT",
    u"2": "4_BIT",
    u"3": "8_BIT_UNSIGNED",
    u"4": "8_BIT_SIGNED",
    u"5": "16_BIT_UNSIGNED",
    u"6": "16_BIT_SIGNED",
    u"7": "32_BIT_UNSIGNED",
    u"8": "32_BIT_SIGNED",
    u"9": "32_BIT_FLOAT",
    u"10": "64_BIT"}

param = pixel_types[string]
arcpy.SetParameterAsText(1, param)

Then use that script in model like following way:

enter image description here

  • How would this method be preferable to the -rather simple and concise- solution of BERA? – RJJoling Apr 9 '18 at 12:50
  • Actually, I thuoght that way should work . But I coudn't pass 'PixelType' (output of 'Script' tool) to 'Create Raster Dataset' tool as 'Pixel Type' parameter. I try something but I cannot overcome. – Kadir Şahbaz Apr 9 '18 at 14:26
  • t = arcpy.GetRasterProperties_management("raster","VALUETYPE").getOutput(0) returns u'5'. Then t_ = arcpy.Script(t).getOutput(0) returns u'16_BIT_UNSIGNED'. Then arcpy.CreateRasterDataset_management(out_path, out_name, pixel_type=t_) create a raster. It works perfectly. But I can't figure it out why "PixelType" doesn't pass in Model Builder. – Kadir Şahbaz Apr 9 '18 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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