I am attempting to loop over dozen of https S3-hosted COPC (LAZ) files in Python for QGIS to (1) render them, and (2) write out a simple thumbnail Jpeg. Using the script below I can successfully loop over downloaded local COPC files, but I can't figure out how to load https S3-hosted COPC (LAZ) files into QGIS.
At line 16, next, QgsPointCloudLayer call either faults or crashes QGIS using an https address. (again this works with local files).
pLayer = QgsPointCloudLayer(urlLOLA, nameCOPC, "pdal", pLayerOptions)
Here is the full code block, but really figuring out how to load a COPC/LAZ file from an https address using QgsPointCloudLayer should the key. All the image writing is just extra here.
EDIT: updated code below to replace "pdal" with "copc" and added pause function to allow time for the streamed file to load and render.
from qgis.core import *
import time
def pause(seconds):
print("Paused for " + str(seconds) + " seconds to allow load")
time_end = time.time() + seconds
while time.time() < time_end:
QgsApplication.processEvents()
#S3 URL (now works also!)
files=["https://astrogeo-ard.s3-us-west-2.amazonaws.com/moon/lro/lola/LolaRDR_15N30N_270E285E.copc.laz",
"https://astrogeo-ard.s3-us-west-2.amazonaws.com/moon/lro/lola/LolaRDR_15N30N_285E300E.copc.laz"]
#local files (works)
#files=["/tmp/LolaRDR_15N30N_270E285E.copc.laz",
# "/tmp/LolaRDR_15N30N_285E300E.copc.laz"]
canvas = iface.mapCanvas()
for urlLOLA in files:
nameCOPC=urlLOLA.split("/")[-1]
nameJPEG="/tmp/" + nameCOPC.replace(".copc.laz","_thumb.jpg")
pLayer = QgsPointCloudLayer(urlLOLA, nameCOPC, "copc")
if pLayer.isValid():
print(nameCOPC + ": " + str(pLayer.pointCount()))
QgsProject.instance().addMapLayer(pLayer)
#Grab newly added layer and set to 70% transparent
layer = iface.activeLayer()
layer.setOpacity(0.7)
#zoom to layer and refresh
extent = layer.extent()
canvas.setExtent(extent)
canvas.refresh()
#force 60-second pause to allow streamed COPC to load and render
pause(60)
canvas.waitWhileRendering()
#export Jpeg
canvas.saveAsImage(nameJPEG,None,"JPEG")
print("created file: " + nameJPEG)
#remove layer
QgsProject.instance().removeMapLayer( layer.id() )
canvas.refreshAllLayers()