将TIF栅格转换为NumPy数组会导致Python27中的MemoryError

时间:2018-11-03 00:02:21

标签: python python-2.7 out-of-memory arcgis arcpy

我正在尝试将ArcGIS栅格图像转换成NumPy数组,以便可以在NetworkX中进行分析。我的python代码适用于某些栅格,但是大型栅格图像(大约> 7000行/列的任何栅格)都会失败,并显示Python错误,提示“内存错误”。是否有解决此错误的好方法?请注意,我必须使用Python 27,因为ArcPy模块使用此版本。预先感谢您的帮助!

这是我的代码:

        rasters = arcpy.ListRasters(wild_card="ClipRast_FID{0}.tif".format(FID_Unique))
        for raster in rasters:

            print 'raster being converted to Numpy Array: FID{0}'.format(FID_Unique)
            inRas = arcpy.Raster(raster)
            lowerLeft = arcpy.Point(X=inRas.extent.XMin, Y=inRas.extent.YMin)
            print 'Lower left XY values are {0}'.format(lowerLeft)
            cellSize = inRas.meanCellWidth
            print 'cell size is {0}'.format(cellSize)

            column = arcpy.GetRasterProperties_management(in_raster=inRas, property_type="COLUMNCOUNT")
            column = column.getOutput(0)
            column = int(column)
            print 'number of columns are {0}'.format(column)

            row = arcpy.GetRasterProperties_management(in_raster=inRas, property_type="ROWCOUNT")
            row = row.getOutput(0)
            row = int(row)
            print 'number of rows are {0}'.format(row)

            no_data_value = -9999
            array = arcpy.RasterToNumPyArray(inRas, lower_left_corner=lowerLeft, ncols=column, nrows=row,
                                             nodata_to_value=no_data_value)

            np.savetxt(Output2 + 'Numpy_Raster_Array_FID' + str(FID_Unique) + '.asc', array, fmt= "%1.3g")
            print 'raster conversion successful.'

0 个答案:

没有答案