<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
Hi!!!</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<p>I<code>m writing an algorithm in Python to extract Z coordinate of an DEM for a pair of X,Y coordinates. I</code>m using GDAL. The algorithm works correctly by extracting the Z coordinate from the DEM.</p>
<pre><code><span>Z </span><span>=</span><span> </span><span>1872</span><span> limiar </span><span>=</span><span> </span><span>0.00001</span><span>
COORD_X </span><span>=</span><span> </span><span>[]</span><span>
COORD_Y </span><span>=</span><span> </span><span>[]</span><span>
</span><span>for</span><span> i </span><span>in</span><span> range</span><span>(</span><span>size</span><span>):</span><span>
</span><span>print</span><span>()</span><span>
</span><span>print</span><span>()</span><span>
</span><span>print</span><span>()</span><span>
X </span><span>=</span><span> </span><span>Xcp</span><span> </span><span>+</span><span> </span><span>(</span><span>Z </span><span>-</span><span> </span><span>Zcp</span><span>)</span><span> </span><span>*</span><span> </span><span>(((</span><span>m11 </span><span>*</span><span> xf</span><span>[</span><span>i</span><span>])</span><span> </span><span>+</span><span> </span><span>(</span><span>m21 </span><span>*</span><span> yf</span><span>[</span><span>i</span><span>])</span><span> </span><span>-</span><span> </span><span>(</span><span>m31 </span><span>*</span><span> focal</span><span>))</span><span> </span><span>/</span><span> </span><span>((</span><span>m13 </span><span>*</span><span> xf</span><span>[</span><span>i</span><span>])</span><span> </span><span>+</span><span> </span><span>(</span><span>m23 </span><span>*</span><span> yf</span><span>[</span><span>i</span><span>])</span><span> </span><span>-</span><span> </span><span>(</span><span>m33 </span><span>*</span><span> focal</span><span>)))</span><span>
</span><span>
Y </span><span>=</span><span> </span><span>Ycp</span><span> </span><span>+</span><span> </span><span>(</span><span>Z </span><span>-</span><span> </span><span>Zcp</span><span>)</span><span> </span><span>*</span><span> </span><span>(((</span><span>m12 </span><span>*</span><span> xf</span><span>[</span><span>i</span><span>])</span><span> </span><span>+</span><span> </span><span>(</span><span>m22 </span><span>*</span><span> yf</span><span>[</span><span>i</span><span>])</span><span> </span><span>-</span><span> </span><span>(</span><span>m32 </span><span>*</span><span> focal</span><span>))</span><span> </span><span>/</span><span> </span><span>((</span><span>m13 </span><span>*</span><span> xf</span><span>[</span><span>i</span><span>])</span><span> </span><span>+</span><span> </span><span>(</span><span>m23 </span><span>*</span><span> yf</span><span>[</span><span>i</span><span>])</span><span> </span><span>-</span><span> </span><span>(</span><span>m33 </span><span>*</span><span> focal</span><span>)))</span><span>

rasterx </span><span>=</span><span> int</span><span>((</span><span>X </span><span>-</span><span> gt</span><span>[</span><span>0</span><span>])</span><span> </span><span>/</span><span> gt</span><span>[</span><span>1</span><span>])</span><span>
rastery </span><span>=</span><span> int</span><span>((</span><span>Y </span><span>-</span><span> gt</span><span>[</span><span>3</span><span>])</span><span> </span><span>/</span><span> gt</span><span>[</span><span>5</span><span>])</span><span>
Z_dem </span><span>=</span><span> float</span><span>(</span><span>layer</span><span>.</span><span>GetRasterBand</span><span>(</span><span>1</span><span>).</span><span>ReadAsArray</span><span>(</span><span>rasterx</span><span>,</span><span> rastery</span><span>,</span><span> </span><span>1</span><span>,</span><span> </span><span>1</span><span>))</span><span>
a </span><span>=</span><span> abs</span><span>(</span><span>Z_dem </span><span>-</span><span> Z</span><span>)</span></code></pre>
<p>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".</p>
<pre><code><span>    </span><span>if</span><span> </span><span>(</span><span>a </span><span><</span><span> limiar</span><span>):</span><span>
    COORD_X</span><span>.</span><span>append</span><span>(</span><span>X</span><span>)</span><span>
    COORD_Y</span><span>.</span><span>append</span><span>(</span><span>Y</span><span>)</span><span>
    </span><span>else</span><span>:</span><span>
    Z </span><span>=</span><span> Z_dem</span></code></pre>
<p>Error on Python:</p>
<p><strong><em>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'</em></strong></p>
<p><strong><em><br>
</em></strong></p>
<p>I don't understand this error because the value on "Z_dem" is a float and not "NoneType". </p>
<p><br>
</p>
<p>Can someone assist please?</p>
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
Kind Regards.</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
César de Paula</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Arial,Helvetica,sans-serif; font-size: 10pt;">
<br>
</div>
<div id="Signature">
<p>Enviado do <a href="http://aka.ms/weboutlook">Outlook</a><br>
</p>
</div>
</body>
</html>