1

I've been trying to find the cell size, or height/width/mean, of a cell by utilizing arcpy in the Python Window in ArcGIS Pro version 2.3.3., I run the following code:

import arcpy
env = arcpy.env
env.workspace = "D:\Fall 2019\GEOG 625\pr\pen"
raster = "D:\Fall 2019\GEOG 625\pr\pen\LandsatHMB201707"
description = arcpy.Describe(raster)
arcpy.env.Describe("D:\Fall 2019\GEOG 625\pr\pen\LandsatHMB201707").meanCellHeight

I've looked into the raster properties here https://pro.arcgis.com/en/pro-app/arcpy/functions/raster-band-properties.htm

and the error code I get is:

AttributeError: DescribeData: Method meanCellWidth does not exist

0

3 Answers 3

3

You are calling Describe function again using arcpy.env.Describe which does not seem to be correct. Although you already used arcpy.Describe() which is the correct one. you did not use it.

Here is a working code, you can adjust your code based on it:

import arcpy
from arcpy import env
env.workspace = r"F:\Ahmad\Test\Landsat_Test"
raster = "TestClassClip.tif"
desc = arcpy.Describe(raster)
cellsize = 'Hight = {0}, Width = {1}'.format(desc.meanCellHeight,desc.meanCellWidth)
print (cellsize)

Output:

Hight = 30.0, Width = 30.0

enter image description here

2
  • Thank you for the feedback Ahmad, unfortunately it did not work. However I talked to a classmate and figured out what the problem was: ` import arcpy from arcpy import env env.workspace = r"D:\Fall 2019\GEOG 625\pr\pen\LandsatHMB201707" describe = arcpy.Describe("LandsatHMB201707.tif\Band_1") Cell_Size = describe.meanCellWidth print(Cell_Size) ` Was the correct code. Have to specify the specific band due to file having numerous bands. Sep 20, 2019 at 19:30
  • @MichaelBreidert You are welcome. Glad you you could solve the problem.
    – ahmadhanb
    Sep 20, 2019 at 19:59
0
import arcpy
from arcpy import env
env.workspace = r"D:\Fall 2019\GEOG 625\pr\pen\LandsatHMB201707"
describe = arcpy.Describe("LandsatHMB201707.tif\Band_1")
Cell_Size = describe.meanCellWidth
print(Cell_Size)

Figured it out with a classmate, thank you for the help Ahmed

0
enter code here
import arcpy
my_raster = arcpy.Raster('/my_raster.tif')
cellsize = my_raster.meanCellHeight, my_raster.meanCellWidth

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.