<div dir="ltr"><div>Hi and thanks for the replies.</div><div><br></div><div>As for my other email related to reading a raster, I wanted to investigate the possibility of creating a raster using pure pyQGIS API.</div><div>It seems that it isn't possible without using at least the constantmap processing algo. </div><div>But I was hoping that it would be possible to use at least the Block class to work the raster as a matrix.</div><div><br></div><div>I was about to open an issue for the thing, but suspect I am using the API in a wrong way, since the results are scrambled.</div><div><br></div><div>Cheers,</div><div>Andrea</div><div><br></div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 9, 2023 at 10:57 AM Richard McDonnell <<a href="mailto:richard.mcdonnell@opw.ie">richard.mcdonnell@opw.ie</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-5220856359700759206">





<div lang="EN-IE">
<div class="m_-5220856359700759206WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi Andrea,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Please disregard my last email the formula is incorrect.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Apologies..<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Richard<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<table style="font-size:9pt;height:321px;font-family:Arial,sans-serif;width:500px;line-height:15px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="font-size:9pt;font-family:Arial,sans-serif;width:500px;color:rgb(0,77,68);padding-bottom:6px">
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(0,77,68)"><br>
——</span><br>
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(0,77,68)">Richard McDonnell MSc GIS, FME Certified Professional</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)"><i>FRM Data Management</i></span><br>
<br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">——</span><br>
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(0,77,68)">Oifig na nOibreacha Poiblí</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">Office of Public Works</span><br>
<br>
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(86,81,72)">Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(86,81,72)">Jonathan Swift Street, Trim, Co Meath, C15 NX36</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(86,81,72)">——</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(86,81,72)">M +353 87 688 5964 T +353 46 942 2409</span><br>
<a href="https://gov.ie/opw" target="_blank">https://gov.ie/opw</a><br>
<br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">——<br>
To send me files larger than 30MB, please use the link below <a href="https://filetransfer.opw.ie/filedrop/richard.mcdonnell@opw.ie" target="_blank">https://filetransfer.opw.ie/filedrop/richard.mcdonnell@opw.ie</a><br>
</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">Email Disclaimer: <a href="https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/" target="_blank">https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/</a>
</span></td>
</tr>
</tbody>
</table>
<table style="font-size:9pt;font-family:Arial,sans-serif;width:420px;line-height:15px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="font-size:9pt;font-family:Arial,sans-serif;width:420px;color:rgb(0,77,68);padding-bottom:6px">
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(0,77,68)"><br>
——</span><br>
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(0,77,68)">MSc GIS, FME Certified Professional</span><br>
<br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">——</span><br>
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(0,77,68)">Oifig na nOibreacha Poiblí</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">Office of Public Works</span><br>
<br>
<span style="font-family:Arial,sans-serif;font-weight:bold;color:rgb(86,81,72)">Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(86,81,72)">Jonathan Swift Street, Trim, Co Meath, C15 NX36</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(86,81,72)">——</span><br>
<span style="font-family:Arial,sans-serif;color:rgb(86,81,72)">M +353 87 688 5964 T +353 46 942 2409</span><br>
<font color="#565148"><a href="https://www.opw.ie" target="_blank">https://https://gov.ie/opw</a></font><br>
<br>
<span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">——<br>
</span><span style="font-family:Arial,sans-serif;color:rgb(0,77,68)">Email Disclaimer:
<a href="https://www.opw.ie/en/disclaimer/" target="_blank">https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/</a></span>
</td>
</tr>
</tbody>
</table>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> QGIS-User <<a href="mailto:qgis-user-bounces@lists.osgeo.org" target="_blank">qgis-user-bounces@lists.osgeo.org</a>>
<b>On Behalf Of </b>Richard McDonnell via QGIS-User<br>
<b>Sent:</b> 09 May 2023 09:27<br>
<b>To:</b> andrea antonello <<a href="mailto:andrea.antonello@gmail.com" target="_blank">andrea.antonello@gmail.com</a>><br>
<b>Cc:</b> <a href="mailto:qgis-user@lists.osgeo.org" target="_blank">qgis-user@lists.osgeo.org</a><br>
<b>Subject:</b> Re: [Qgis-user] [pyqgis] create new raster<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi Andrea,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">If you are ok substituting the method you are using for GDAL, then you can use the following..<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:10pt;font-family:"inherit",serif;border:1pt none windowtext;padding:0cm">gdal_calc.py -A input.tif --outfile=result.tif --calc="(A>=-2000)*(A<=1500)" --NoDataValue=-9999<u></u><u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:10pt;font-family:"inherit",serif;border:1pt none windowtext;padding:0cm"><u></u> <u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">You can also implement this in QGIS using GDAL Calculator from the Processing Toolbox, It can also
 be ran as a batch in QGIS or  built into a model if you are looking to batch it or it’s something that’s regularly done.<u></u><u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The output type is Float32, as you are using DTM, probably with decimal places a NoDATA value of -9999<u></u><u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Regards,<u></u><u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Richard<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<table border="0" cellspacing="0" cellpadding="0" width="0" style="width:375pt">
<tbody>
<tr>
<td width="500" style="width:375pt;padding:0cm 0cm 4.5pt">
<p class="MsoNormal" style="line-height:11.25pt"><b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
——</span></b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
<b>Richard McDonnell MSc GIS, FME Certified Professional</b><br>
<i>FRM Data Management</i><br>
<br>
——<br>
<b>Oifig na nOibreacha Poiblí</b><br>
Office of Public Works<br>
<br>
</span><b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
</span></b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">Jonathan Swift Street, Trim, Co Meath, C15 NX36</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">——</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">M +353 87 688 5964 T +353 46 942 2409</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
<a href="https://gov.ie/opw" target="_blank">https://gov.ie/opw</a><br>
<br>
——<br>
To send me files larger than 30MB, please use the link below <a href="https://filetransfer.opw.ie/filedrop/richard.mcdonnell@opw.ie" target="_blank">
https://filetransfer.opw.ie/filedrop/richard.mcdonnell@opw.ie</a><br>
<br>
Email Disclaimer: <a href="https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/" target="_blank">
https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/</a> <u></u>
<u></u></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="display:none"><u></u> <u></u></span></p>
<table border="0" cellspacing="0" cellpadding="0" width="0" style="width:315pt">
<tbody>
<tr>
<td width="420" style="width:315pt;padding:0cm 0cm 4.5pt">
<p class="MsoNormal" style="line-height:11.25pt"><b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
——</span></b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
<b>MSc GIS, FME Certified Professional</b><br>
<br>
——<br>
<b>Oifig na nOibreacha Poiblí</b><br>
Office of Public Works<br>
<br>
</span><b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36
</span></b><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">Jonathan Swift Street, Trim, Co Meath, C15 NX36</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">——</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)">M +353 87 688 5964 T +353 46 942 2409</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(86,81,72)"><a href="https://www.opw.ie" target="_blank">https://https://gov.ie/opw</a></span><span style="font-size:9pt;font-family:Arial,sans-serif;color:rgb(0,77,68)"><br>
<br>
——<br>
Email Disclaimer: <a href="https://www.opw.ie/en/disclaimer/" target="_blank">https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/</a>
<u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> QGIS-User <<a href="mailto:qgis-user-bounces@lists.osgeo.org" target="_blank">qgis-user-bounces@lists.osgeo.org</a>>
<b>On Behalf Of </b>andrea antonello via QGIS-User<br>
<b>Sent:</b> 09 May 2023 07:28<br>
<b>To:</b> <a href="mailto:qgis-user@lists.osgeo.org" target="_blank">qgis-user@lists.osgeo.org</a><br>
<b>Subject:</b> [Qgis-user] [pyqgis] create new raster<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hello,<u></u><u></u></p>
<div>
<p class="MsoNormal">I am trying to find out the best workflow to create a new raster.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">As an example I take an existing elevation model raster and loop over it to set values between 1500 and 2000 to novalue and write the result to a new raster.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This is the only way I found to do so:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:green"># create new raster with novalues between 1500 and 2000</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">dataType</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">dtmLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">dataProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">().</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">dataType</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(9,134,88)">1</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">crs</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">QgsCoordinateReferenceSystem</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'EPSG:3003'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">params</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> = {<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'EXTENT'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">:
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">dtmLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">extent</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(),<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'TARGET_CRS'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">:
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">crs</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'PIXEL_SIZE'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">:
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">dtmLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">rasterUnitsPerPixelX</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(),<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'NUMBER'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">: -</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(9,134,88)">9999.0</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.5pt;font-family:"Courier New";color:green"># 'OUTPUT_TYPE': dataType,</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'OUTPUT'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">:
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">QgsProcessing</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">TEMPORARY_OUTPUT</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">}<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRaster</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">processing</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.run(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'qgis:createconstantrasterlayer'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">params</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)[</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'OUTPUT'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">]<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRasterLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">QgsRasterLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRaster</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'temp'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(163,21,21)">'gdal'</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRasterProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRasterLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">dataProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">()<u></u><u></u></span></p>
</div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">block</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">QgsRasterBlock</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">dataType</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">cols</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">rows</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(175,0,219)">for</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">row</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:blue">in</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">range</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">rows</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">):<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(175,0,219)">for</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">col</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:blue">in</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">range</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">cols</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">):<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">       
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">point</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">dtmLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">dataProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">().</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">transformCoordinates</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">QgsPoint</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">col</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">row</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">),
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">transformType</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">       </span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">value</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">res</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">dtmLayer</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">dataProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">().</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">sample</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(38,127,153)">QgsPointXY</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">point</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">x</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(),
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">point</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">y</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">()),
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(9,134,88)">1</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">       
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">        </span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(175,0,219)">if</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">res</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:blue">and</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">value</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> != -</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(9,134,88)">9999.0</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">:<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">           
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(175,0,219)">if</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">value</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> <
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(9,134,88)">1000</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:blue">or</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">value</span><span style="font-size:10.5pt;font-family:"Courier New";color:black"> >
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(9,134,88)">2000</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">:<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black">               
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">block</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">setValue</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">row</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">col</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">value</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRasterProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">setEditable</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:blue">True</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRasterProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">writeBlock</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">block</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">,
</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">band</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">=</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(9,134,88)">1</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:14.25pt"><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(0,16,128)">newRasterProvider</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">.</span><span style="font-size:10.5pt;font-family:"Courier New";color:rgb(121,94,38)">setEditable</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">(</span><span style="font-size:10.5pt;font-family:"Courier New";color:blue">False</span><span style="font-size:10.5pt;font-family:"Courier New";color:black">)<u></u><u></u></span></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This code has two main issues:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">1. if I uncomment the line containing OUTPUT_TYPE, I am getting an error about the type passed. But I can't find the right type needed there, it should be the one taken from the original provider.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">2. the resulting raster is scrambled as if there was a shift in the setting of the values. But the QgsRasterBlock seems to be built correctly (rows, cols) and the values set properly (col, row).<br>
3. in the above example, the dtmLayer has an epsg 3033 crs and when loaded manually into QGIS, it is recognized. But when I read the layer's metadata crs with pyQGIS , it is not able to read it and tells me it is invalid. <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Has anyone a hint about what I am doing wrong? <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Andrea<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>

</div></blockquote></div></div>