Closed Editor-1 closed 3 months ago
Hello, There seems to be a problem with your dem. What are you trying to do, exactly ? could you please provide your code?
Thank you for your help. The following is my python script code. What I want to do is to combine the two operations of creating lookout point and view analysis together. I did not report any error when I used your plug-in step by step, but I reported an error when I combined them
import os
import datetime
project = QgsProject.instance()
projectLocation = project.fileName()
fileStorage = os.path.dirname(os.path.dirname(projectLocation)) +'/storage'
os.makedirs(fileStorage, exist_ok=True)
pubulicName = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
demFile = r'C:\Users\xxx\Desktop\xxx\xxx\GIS_Study_Data\xxx\xxx_16bit_12.5m.tif'
shpFile = r'C:\Users\xxx\xxx\xxx\xxx\GIS_Study_Data\xxx\xxx.shp'
gpkgFile = fileStorage + '/'+ pubulicName+'-vp.gpkg'
obRadius = 5000
obHeight = 5
tarHeight = 0
viewtifFile = fileStorage + '/'+ pubulicName+'-view.tif'
resultFile = fileStorage + '/'+ pubulicName+'-result.tif'
processing.run("visibility:createviewpoints",
{
'OBSERVER_POINTS':shpFile,
'DEM':demFile,
'OBSERVER_ID':'',
'RADIUS':obRadius,
'RADIUS_FIELD':'',
'OBS_HEIGHT':obHeight,
'OBS_HEIGHT_FIELD':'',
'TARGET_HEIGHT':tarHeight,
'TARGET_HEIGHT_FIELD':'',
'RADIUS_IN_FIELD':'',
'AZIM_1_FIELD':'',
'AZIM_2_FIELD':'',
'ANGLE_UP_FIELD':'',
'ANGLE_DOWN_FIELD':'',
'OUTPUT':gpkgFile
})
processing.run("visibility:viewshed",
{
'ANALYSIS_TYPE':0,
'OBSERVER_POINTS':gpkgFile,
'DEM':demFile,
'USE_CURVATURE':False,
'REFRACTION':0.13,
'OPERATOR':0,
'OUTPUT':viewtifFile
})
processing.run("native:reclassifybytable",
{
'INPUT_RASTER':viewtifFile,
'RASTER_BAND':1,
'TABLE':['0','0','0','1','255','1'],
'NO_DATA':-9999,
'RANGE_BOUNDARIES':0,
'NODATA_FOR_MISSING':False,
'DATA_TYPE':1
# 'OUTPUT':'TEMPORARY_OUTPUT'
'OUTPUT':resultFile
})
layer_tree = project.layerTreeRoot()
group_name = pubulicName + '-Group'
group = None
group = QgsLayerTreeGroup(group_name)
layer_tree.addChildNode(group)
viewtLayer = QgsRasterLayer(viewtifFile, pubulicName + 'view')
resultLayer = QgsRasterLayer(resultFile, pubulicName + 'resultview')
project.addMapLayer(viewtLayer, addToLegend=False)
group.addLayer(viewtLayer)
project.addMapLayer(resultLayer, addToLegend=False)
group.addLayer(resultLayer)
My dem should be fine, because the above errors did not occur when I stepped through your plugin
Hello, this is quite complicated function. When I tried to run it, a coding error appeared on line 55 (missing comma). Once fixed, no problems appeared on my side (?)
I found the frequent creation of lookout points a bit tedious, so I wrote a python script to automate this, using the files generated by the lookout points as input for the next step, but the following error message was reported: