[gdal-dev] Extracting Z coordinate from DEM - Python
Cesar Francisco de Paula
cesarengenheiro1 at hotmail.com
Mon Jul 1 01:56:49 PDT 2019
Hi!!!
Im writing an algorithm in Python to extract Z coordinate of an DEM for a pair of X,Y coordinates. Im using GDAL. The algorithm works correctly by extracting the Z coordinate from the DEM.
Z = 1872 limiar = 0.00001
COORD_X = []
COORD_Y = []
for i in range(size):
print()
print()
print()
X = Xcp + (Z - Zcp) * (((m11 * xf[i]) + (m21 * yf[i]) - (m31 * focal)) / ((m13 * xf[i]) + (m23 * yf[i]) - (m33 * focal)))
Y = Ycp + (Z - Zcp) * (((m12 * xf[i]) + (m22 * yf[i]) - (m32 * focal)) / ((m13 * xf[i]) + (m23 * yf[i]) - (m33 * focal)))
rasterx = int((X - gt[0]) / gt[1])
rastery = int((Y - gt[3]) / gt[5])
Z_dem = float(layer.GetRasterBand(1).ReadAsArray(rasterx, rastery, 1, 1))
a = abs(Z_dem - Z)
Until this part of the algorithm everything works properly. In sequence I need to enter a condition to compare the result of the variable "a" with variable "limiar" and when I enter the conditional in the algorithm and try to execute, the python returns an error in line referring to "Z_dem".
if (a < limiar):
COORD_X.append(X)
COORD_Y.append(Y)
else:
Z = Z_dem
Error on Python:
File "C:/Users/cesar/OneDrive/Projeto_RGB/Monorestituicao_v01.py", line 106, in Z_dem = float(layer.GetRasterBand(1).ReadAsArray(rasterx, rastery, 1, 1)) TypeError: float() argument must be a string or a number, not 'NoneType'
I don't understand this error because the value on "Z_dem" is a float and not "NoneType".
Can someone assist please?
Kind Regards.
César de Paula
Enviado do Outlook<http://aka.ms/weboutlook>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190701/a8dbe0c9/attachment-0001.html>
More information about the gdal-dev
mailing list