我对 python 和编码非常陌生。我正在尝试使冰 DEM(test5) 适合 NZ DEM 的顶部,以便点对齐。数据具有不同的像元大小。这就是我到目前为止所拥有的。目前它所做的只是将数据放入一个 numpy 数组中。我不确定我的下一步应该是什么。附件是包含文件的谷歌驱动器的链接。 https://drive.google.com/drive/folders/1E_IxZoA1PnA4gufFHBtLVRtVTUvFNFPs?usp=sharing
# -*- coding: utf-8 -*-
"""
Created on Wed May 19 15:40:19 2021
@author: pyoli286
"""
import numpy as np
# pathDem = str(input("input the path to file for example 'U:/SURV319/lab1work/lab1/': "))
# nameDem = str(input("input .asc file. For example 'nzdem1000.asc': "))
# pathIce = str(input("input the path to file for example 'U:/SURV319/lab1work/lab1/': "))
# nameIce = str(input("input .asc file. For example 'nzdem1000.asc': "))
pathDem = "/Users/liampyott/Documents/2021/319/Lab3/work/"
nameDem = "nzdem1000.asc"
pathIce = "/Users/liampyott/Documents/2021/319/Lab3/work/"
nameIce = "test5.asc"
def demNZ (inDemNz):
"""
takes the DEM for New Zealand and reads the first 6 lines and ads to a numpy array
"""
f = open(inDemNz, 'r')
headerline1 = f.readline()
headerline1 = headerline1.split()
NCOLS = int(headerline1[1])
headerline2 = f.readline()
headerline2 = headerline2.split()
NROWS = int(headerline2[1])
headerline3 = f.readline()
headerline3 = headerline3.split()
XLLCORNER = int(headerline3[1])
headerline4 = f.readline()
headerline4 = headerline4.split()
YLLCORNER = int(headerline4[1])
headerline5 = f.readline()
headerline5 = headerline5.split()
CELLSIZE = int(headerline5[1])
headerline6 = f.readline()
headerline6 = headerline6.split()
NODATA_VALUE = int(headerline6[1])
nzDem = []
for row in f:
row = row.split()
for col in row:
nzDem.append(float(col))
nzdem2d = np.reshape(nzDem, (NROWS, NCOLS))
return nzdem2d
def demIce (inDemIce):
"""
takes the DEM for ice and reads the first 6 lines and and ads to a numpy array
"""
f = open(inDemIce, 'r')
headerline1 = f.readline()
headerline1 = headerline1.split()
NCOLS = int(headerline1[1])
headerline2 = f.readline()
headerline2 = headerline2.split()
NROWS = int(headerline2[1])
headerline3 = f.readline()
headerline3 = headerline3.split()
XLLCORNER = int(headerline3[1])
headerline4 = f.readline()
headerline4 = headerline4.split()
YLLCORNER = int(headerline4[1])
headerline5 = f.readline()
headerline5 = headerline5.split()
CELLSIZE = int(headerline5[1])
headerline6 = f.readline()
headerline6 = headerline6.split()
NODATA_VALUE = int(headerline6[1])
iceDem = []
for row in f:
row = row.split()
for col in row:
iceDem.append(float(col))
ice2d = np.reshape(iceDem, (NROWS, NCOLS))
f.close
return ice2d
inDemNz = (pathDem+nameDem)
inDemIce = (pathIce+nameIce)
demNZ(inDemNz)
demIce(inDemIce)