forked from Sdmillheim/NASA-SRTM-elevation-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrtmwrite.py
18 lines (16 loc) · 1.08 KB
/
srtmwrite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Defines a class with a function to read tuple from parser into numpy array and save as a CSV file.
# Prompts the user to provide a file name.
import numpy as np
class srtmWriter(object):
def srtmWriteFile(self, hgtcontents, detail, unitscale):
csvtarget = np.zeros(((3600/detail)**2,3)) #either 3600X3600 or 1200X1200. One less than file dimension because files overlap.
i = 0
for ydimension in range(1, int(3600/detail + 1)): # int(3600/detail + 1) represents height and width of square
for xdimension in range(1, int(3600/detail + 1)):
csvtarget[i][0]=int(xdimension)*unitscale*detail*30 # x dimension of 3D space
csvtarget[i][1]=-int(ydimension)*unitscale*detail*30 # y dimension of 3D space
csvtarget[i][2]=int(hgtcontents[int(3600/detail + 1)*ydimension+xdimension]*unitscale) # z dimension of 3D space
i += 1
csvfilename = input("What would you like to name your CSV file?")
np.savetxt(csvfilename + ".csv", csvtarget, delimiter=",")
return 'File is saved.'