zoran-cuckovic / QGIS-visibility-analysis

Quantum GIS plugin for visibility analysis
GNU General Public License v3.0
72 stars 17 forks source link

AttributeError: 'NoneType' object has no attribute 'SetProjection' #36

Closed Mackatttack123 closed 2 years ago

Mackatttack123 commented 4 years ago

Hi, I'm trying to run a viewshed analysis but keep getting this error:

QGIS version: 3.10.0-A Coruña
QGIS code revision: 6c816b4204
Qt version: 5.12.3
GDAL version: 2.4.1
GEOS version: 3.7.2-CAPI-1.11.2 b55d2125
PROJ version: Rel. 5.2.0, September 15th, 2018
Processing algorithm…
Algorithm 'Viewshed' starting…
Input parameters:
{ 'DEM' : '/Users/mackfitzpatrick/Desktop/SPARC5L_MapPackage/commondata/raster_data/SRTM_30m.tif', 'OBSERVER_POINTS' : 'PointZM?crs=EPSG:900913&field=ID:string(255,0)&field=observ_hgt:double(10,4)&field=radius:double(10,2)&uid={bf488ec7-a4b5-4036-870d-1ac0e62b2a2c}', 'OUTPUT' : 'TEMPORARY_OUTPUT', 'REFRACTION' : 0.13, 'USE_CURVATURE' : False }

Traceback (most recent call last):
File "/Users/mackfitzpatrick/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/ViewshedAnalysis/algorithms/viewshed_raster.py", line 217, in processAlgorithm
dem.write_output(output_path)
File "/Users/mackfitzpatrick/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/ViewshedAnalysis/algorithms/modules/Raster.py", line 458, in write_output
ds.SetProjection(self.crs)
AttributeError: 'NoneType' object has no attribute 'SetProjection'

Execution failed after 0.50 seconds

Loading resulting layers
Algorithm 'Viewshed' finished

I'm not sure what I'm doing wrong. What am I missing here?

Mackatttack123 commented 4 years ago

Anyone have any idea about this one? I'm still stuck.

zoran-cuckovic commented 4 years ago

Hello! Are you working with projected data or raw SRTM ? Viewshed analysis plugin requires properly projected raster data (a UTM projection, for instance).

Mackatttack123 commented 4 years ago

Oh, I think I am using raw SRTM. How can I convert that to a UTM projection?

DFic commented 4 years ago

Recently encounter the same error. All input data were projected, in my case in EPSG:3765. The solution was to reduce the size of the input DEM - simply to crop the DEM to AOI - and then everything works fine.

Hint was in the plugin code in lines 225 - 226 _225 if not live_memory: 226 dem.write_output(outputpath)

zoran-cuckovic commented 4 years ago

Hello, You're suggesting that the algorithm doesn't handle well large datasets, ones that require successive read-write for each viewshed. This could be an issue. However, we should first do an experiment : could you reduce the parameter for maximum memory load (under Processing options > Providers > Visibility Analysis, see figure) in order to force the algorithm to abandon live memory calculation ? Does it still fail with your cropped dataset ?

image

Doctor-Who commented 2 years ago

Hello, I've got same error problem : AttributeError: 'NoneType' object has no attribute 'SetProjection' and really cannot understand what's wrong.

Traceback (most recent call last):
File "/home/nrochard/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ViewshedAnalysis/algorithms/viewshed_raster.py", line 234, in processAlgorithm
dem.write_output(output_path, compression = False)
File "/home/nrochard/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ViewshedAnalysis/algorithms/modules/Raster.py", line 465, in write_output
ds.SetProjection(self.crs)
AttributeError: 'NoneType' object has no attribute 'SetProjection'

Execution failed after 0.06 secondes

My data are in EPSG 2154 With my viewpoints data and DEM are well detected into QGIS My DEM was in COG so I've try also to translate into basic GTIFF and force SRID with GDAL (also well detected into QGIS everything was fine) The plugin still doesn't work :(

Any idea ?

QGIS on Pop!_OS 21.04

Version de QGIS | 3.22.0-Białowieża | Révision du code | d9022691f1
-- | -- | -- | --
Version de Qt | 5.15.2
Version de Python | 3.9.5
Version de GDAL/OGR | 3.2.2
Version de Proj | 7.2.1
Version de la base de données du registre EPSG | v10.008 (2020-12-16)
Version de GEOS | 3.9.0-CAPI-1.16.2
Version de SQLite | 3.34.1
Version de PDAL | 2.2.0
Version du client PostgreSQL | 13.4 (Ubuntu 13.4-0ubuntu0.21.04.1)
Version de SpatiaLite | 5.0.1
Version de QWT | 6.1.4
Version de QScintilla2 | 2.11.6
Version de l'OS | Pop!_OS 21.04
  |   |   |  
Extensions Python actives
postgis_geoprocessing | 0.9
processing_r | 3.1.0
mapswipetool_plugin | 1.2
HCMGIS | 21.8.28
TerrainShading | 0.9.3
ViewshedAnalysis | 1.7
DataPlotly | 3.8.1
geo2france | 0.9.3
Go2NextFeature3 | 2.1
SpreadsheetLayers | 2.0.1
BivariateRenderer | 0.3
mask | 1.10.1
MemoryLayerSaver | 4.0.4
menu_from_project | v2.0.1
GroupStats | 2.2.5
pg_raster_import | 1.0.10
processing | 2.12.99
MetaSearch | 0.3.5
sagaprovider | 2.12.99
db_manager | 0.1.20
grassprovider | 2.12.99
zoran-cuckovic commented 2 years ago

Hello, I can't tell much from this info, other than that you have a projection issue. I don't have issues with EPSG 2154 (Lambert 93) projection (?). Could you please attach a sample of your data ? Zoran

Doctor-Who commented 2 years ago

Dear @zoran-cuckovic thank you for your quick answer. I'm going to try to export some samples but my data are quite heavy (DEM around 60 Go 1m resolution) and around 2000 viewpoints. I really don't care if it means running 1 week as I've got a result ^^. This morning I've try on Windows 7 Pro with QGIS 3.16 LTR : same error. So I figure problem is from data.

Doctor-Who commented 2 years ago

Update : I'm trying to find a way to send to you my DEM. I've done an extract with GDAL with a simple gdal_translate by juste clipping with a box and it works on a small part of data ... But GDAL info doesn't give any clue as the metadata are the same except the extent ...

zoran-cuckovic commented 2 years ago

If it works on a smaller DEM dataset, you could have a memory issue. The algo is limited by available RAM space, which can be the case with lidar derived data. You should downsample to 5 or 10 meters.

Doctor-Who commented 2 years ago

My DEM is about 1m resolution on 32 000 km² and 2000 observers. I know it's quite a lot. Is there a way to modify some settings to use max RAM but also disk (like sort of swap) ? If not, I will follow your advice and degrade data. Anyway thanks for that great plugin ! (and also the hillshade one)

zoran-cuckovic commented 2 years ago

Hi, You cannot reduce the RAM imprint beyond a certain point. The algo extracts the data nedded for each observer into the RAM. Note for instance if you specify 30 km on a 1m DEM this would make for a 60 000 x 60 000 pixels chunk. This is huge ! You may try with GRASS which does handle large datasets, but I would guess that for 2000 observers you would need several days of computing (at least, even if it takes 5 min per observer, which is super-optimistic !). If this is your case, you need to downsample the DEM to something like 5 or 10m, or even 25m, depending on the radius of analysis. Best