Geographic Information Systems Asked on August 4, 2021
I’m trying to create a r.sunmask
raster for every hour of the year for a specific DEM, so 24 rasters per day for 365 days. I’m quite new to QGIS and would like to know if there was a way to automate the process and to create some sort of cycle in Python so that it will create all the output raster without me having to manually create each one of them.
You can use Python datetime module to generate the appropriate dates, then use processing
module from QGIS (if you intend to use the Python interpreter of QGIS).
I have not tested the various parameters needed for r.sunmask
, but the main logic could be as follows:
import datetime
from qgis import processing
start = datetime.datetime(2020, 1, 1)
end = datetime.datetime(2021, 1, 1)
delta = datetime.timedelta(hours = 1)
# the list of datetimes to create
requested_dt = []
current = start
while current <= end: # stop at '2021-01-01 00:00:00' included
requested_dt.append(current)
current += delta
# get a reference to your elevation model
dem = QgsProject.instance().mapLayersByName('name_of_your_dem_in_qgis')[0]
# Run r.sunmask algorithm for each datetime
for dt in requested_dt:
y, m, d, h, _, _, _, _, _ = current.timetuple()
parameters = {
'elevation': dem,
'year': y,
'month': m,
'day': d,
'hour': h,
'minute': 0,
'second': 0,
'output': '/path/to/output-{}-{}-{}-{}h.tiff'.format(y, m, d, h)
}
processing.run('grass:r.sunmask.datetime',parameters)
Answered by mgc on August 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP