I have recently been having some issues converting rasters to numpy arrays. The RasterToNumPyArray tool seems to be adding or subtracting rows or columns depending on which dataset I'm working on.
For instance I have a raster that contains 114 rows, and 160 columns. After converting it to an array it has 115 rows, and 160 column. If I convert this array back to a raster the data appears to be shifted up.
I have tried specifying the number of rows and columns to process in the RasterToNumPyArray tool. The row and column count issue is fixed but the output raster is still shifted up one row.
This issue happens whether the data is in a geographic or projected coordinate system.
Any idea why this would be happening? I am including a python script where I was seeing this issue.
import arcpy import numpy as np from arcpy import env from os import path env.overwriteOutput = True env.outputCoordinateSystem = arcpy.SpatialReference(4326) input_ras = r'PATH_TO_INPUT_RASTER' input_ras_name = path.basename(input_ras) ras_desc = arcpy.Describe(input_ras) rows = ras_desc.height cols = ras_desc.width x_cell_size = ras_desc.meanCellWidth y_cell_size = ras_desc.meanCellHeight lower_left_corner = arcpy.Point(ras_desc.extent.XMin, ras_desc.extent.YMin) print input_ras_name print 'rows:', rows print 'cols:', cols print lower_left_corner arr = arcpy.RasterToNumPyArray(input_ras, lower_left_corner, cols, rows, -9999) print '\narry based on input raster' print 'rows:', np.shape(arr) print 'cols:', np.shape(arr) print '\nconverting array back to a raster' output_ras = arcpy.NumPyArrayToRaster(arr, lower_left_corner, input_ras, input_ras) output_ras.save(r'PATH_TO_OUTPUT_RASTER')
edit: I explored the row and column count a little more. The following screen shot shows the row and column count three different ways - one of which is different. Could this mean anything?
edit 2: The problem does not seem to occur after converting my tif to a GRID and then processing the data. Ideally thought I would not want to perform this intermediate step.