<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi Eric,</p>
<p>you might try to use a /vsimem/ path. For example, save your image to "/vsimem/myimage.tif" and<br />open it as QgsRasterLayer. I haven't tested it with gdal.Datasets, but it works with with ogr.DataSources.<br />Probably you shouldn't overwrite or delete the "/vsimem" object while QGIS has still a reference on it.</p>
<p>More details here: https://gdal.org/user/virtual_file_systems.html#vsimem-in-memory-files</p>
<p>Greetings,</p>
<p>Benjamin</p>
<p id="reply-intro">On 2021-03-03 00:00, Eric Younkin - NOAA Federal wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div id="replybody1">
<div dir="ltr">Hello,
<div> </div>
<div>I've been trying to figure out how to draw grids and lines from numpy arrays without driving to a raster/vector file first.  I tried using the gdal 'MEM' driver to make a gdal Dataset from a numpy array and pass that in as a QgsRasterLayer, I get the following:</div>
<div> </div>
<div>>>> memobj<br /><osgeo.gdal.Dataset; proxy of <Swig Object of type 'GDALDatasetShadow *' at 0x0000019B3131AC30> ><br />>>> QgsRasterLayer(memobj, 'testlayer', 'gdal')</div>
Traceback (most recent call last):<br />  File "<input>", line 1, in <module><br />TypeError: QgsRasterLayer(): arguments did not match any overloaded call:<br />  overload 1: too many arguments<br />  overload 2: argument 1 has unexpected type 'Dataset'
<div>
<div> </div>
<div>
<div>The only other approach that I could find was:</div>
<div> </div>
<div><a href="https://gis.stackexchange.com/questions/201804/how-to-create-raster-layer-directly-from-numpy-array-in-qgis-without-saving-to" target="_blank" rel="noopener noreferrer">https://gis.stackexchange.com/questions/201804/how-to-create-raster-layer-directly-from-numpy-array-in-qgis-without-saving-to<br /></a></div>
<div> </div>
<div>but I suspect that the return from the processing.run command is probably a temp file, so it is still going to file.  Is there not a way to generate a raster layer from a numpy array without writing to file first?<br /><br />Thanks,<br />Eric</div>
<div> </div>
-- <br />
<div class="v1gmail_signature" dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr"><span><span style="color: #0000ff;">Eric Younkin<br />Physical Scientist<br /></span></span></div>
<div dir="ltr"><span><span style="color: #0000ff;">NOAA OCS, </span></span><span style="color: #0000ff; font-size: 12.8px;">Hydrographic Systems and Technology Branch</span></div>
<div dir="ltr"><span><span style="color: #0000ff;">1315 East-West Highway</span></span></div>
<div dir="ltr"><span><span style="color: #0000ff;">N/CS11, Room 6604<br />Silver Spring, MD 20910</span></span></div>
<div><span><span style="color: #0000ff;">Office: </span></span><span style="font-family: arial,sans,sans-serif; font-size: 13px; white-space: pre-wrap;"><span style="color: #0000ff;">240-847-8208</span></span></div>
<div dir="ltr"><span><span style="color: #0000ff;"> Cell: 828-331-8197</span><br /></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">_______________________________________________<br />QGIS-Developer mailing list<br /><a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br />List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br />Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></div>
</blockquote>
<p><br /></p>
<div id="signature">-- <br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">--<br />Benjamin Jakimow, Doctoral Researcher<br />Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin<br /><br />e-mail: <a href="mailto:benjamin.jakimow@geo.hu-berlin.de">benjamin.jakimow@geo.hu-berlin.de</a><br /><br />phone:  +49 (0) 30 2093 6894<br />mobile: +49 (0) 157 5656 8477<br />fax:    +49 (0) 30 2093 6848<br />mail:   Unter den Linden 6 | 10099 Berlin | Germany<br />room: 2'222</div>
</div>
</body></html>