将 Excel 转换为 TIFF 文件
Convert an Excel to TIFF file
我有一个包含像素值的 Excel 文件,我正在尝试将其转换为 TIFF 或栅格数据集以使用 Arcgis 打开。我在这里寻找类似的问题,但找不到任何问题。我尝试了一些但它给出了一个错误。 Excel 从 DEM
获得的文件包含 2098 rows x 2851 columns
没有标题。
这是我的代码:
import pandas as pd
import Image as im
file = r'C:/Users/owrasa/PycharmProjects/den/demrep2.xlsx'
size = 2098, 2851
df = pd.read_excel(file, header=0)
df2 = pd.np.array(df)
imarray = im.fromarray(df2)
imsave = im.SAVE(imarray, "TIFF")
这是错误消息:
TypeError: Cannot handle this data type
Excel 文件如下所示:
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60 60 60 60
-32767 -32767 -32767 -32767 60 60 60 60 60 60 60 60 60 60 60
-32767 -32767 -32767 60 60 60 60 60 60 60 60 60 60 60 60
-32767 -32767 59 60 60 60 60 60 60 60 60 60 60 60 60
-32767 59 59 59 59 60 60 60 60 60 60 60 60 60 60
59 59 59 59 59 59 59 59 59 60 60 60 59 60 60
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
您的代码有几个问题:
Image
模块不是从 PIL
导入的。
df2
的数据类型是 int64
而不是 int32
。
- 对
Image.save()
的调用不正确(函数名称必须小写)。
以下代码片段修复了所有这些问题,应该可以完成工作:
import pandas as pd
import numpy as np
import PIL.Image as im
file = r'C:/Users/owrasa/PycharmProjects/den/demrep2.xlsx'
df = pd.read_excel(file, header=0)
df2 = pd.np.array(df).astype(np.int32)
imarray = im.fromarray(df2)
imarray.save(r'C:/Users/owrasa/PycharmProjects/den/demrep2.tif')
我有一个包含像素值的 Excel 文件,我正在尝试将其转换为 TIFF 或栅格数据集以使用 Arcgis 打开。我在这里寻找类似的问题,但找不到任何问题。我尝试了一些但它给出了一个错误。 Excel 从 DEM
获得的文件包含 2098 rows x 2851 columns
没有标题。
这是我的代码:
import pandas as pd
import Image as im
file = r'C:/Users/owrasa/PycharmProjects/den/demrep2.xlsx'
size = 2098, 2851
df = pd.read_excel(file, header=0)
df2 = pd.np.array(df)
imarray = im.fromarray(df2)
imsave = im.SAVE(imarray, "TIFF")
这是错误消息:
TypeError: Cannot handle this data type
Excel 文件如下所示:
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60 60 60
-32767 -32767 -32767 -32767 -32767 -32767 60 60 60 60 60 60 60 60 60
-32767 -32767 -32767 -32767 60 60 60 60 60 60 60 60 60 60 60
-32767 -32767 -32767 60 60 60 60 60 60 60 60 60 60 60 60
-32767 -32767 59 60 60 60 60 60 60 60 60 60 60 60 60
-32767 59 59 59 59 60 60 60 60 60 60 60 60 60 60
59 59 59 59 59 59 59 59 59 60 60 60 59 60 60
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
59 59 59 59 59 59 59 59 59 59 59 59 59 59 59
您的代码有几个问题:
Image
模块不是从PIL
导入的。df2
的数据类型是int64
而不是int32
。- 对
Image.save()
的调用不正确(函数名称必须小写)。
以下代码片段修复了所有这些问题,应该可以完成工作:
import pandas as pd
import numpy as np
import PIL.Image as im
file = r'C:/Users/owrasa/PycharmProjects/den/demrep2.xlsx'
df = pd.read_excel(file, header=0)
df2 = pd.np.array(df).astype(np.int32)
imarray = im.fromarray(df2)
imarray.save(r'C:/Users/owrasa/PycharmProjects/den/demrep2.tif')