Reputation: 699
I have an Excel file with pixel values and I'm trying to convert it to TIFF or raster dataset to be opened with Arcgis. I looked here for similar problems and I could not find any. I tried something but it gave an error. Excel file obtained from DEM
include 2098 rows x 2851 columns
without heading.
Here is my code:
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")
Here is the error message:
TypeError: Cannot handle this data type
The Excel file looks like this:
-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
Upvotes: 0
Views: 1267
Reputation: 13743
Your code had several problems:
Image
module was not imported from PIL
.df2
was int64
rather than int32
.Image.save()
was incorrect (the function name has to be lowercase).The following snippet fixes all those issues and should get the job done:
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')
Upvotes: 2