gpt4 book ai didi

python - 将 Excel 转换为 TIFF 文件

转载 作者:行者123 更新时间:2023-12-01 03:29:37 30 4
gpt4 key购买 nike

我有一个包含像素值的 Excel 文件,我正在尝试将其转换为 TIFF 或栅格数据集以使用 Arcgis 打开。我在这里寻找类似的问题,但找不到任何问题。我尝试了一些东西,但它给出了一个错误。从 DEM 获取的 Excel 文件包含 2098 行 x 2851 列,无标题。

这是我的代码:

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

最佳答案

您的代码有几个问题:

  1. Image 模块未从 PIL 导入。
  2. df2 的数据类型是 int64 而不是 int32
  3. 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')

关于python - 将 Excel 转换为 TIFF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41076811/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com