-
Notifications
You must be signed in to change notification settings - Fork 13
/
qgis2fds_algorithm.py
770 lines (656 loc) · 25.7 KB
/
qgis2fds_algorithm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
# -*- coding: utf-8 -*-
"""qgis2fds"""
__author__ = "Emanuele Gissi"
__date__ = "2020-05-04"
__copyright__ = "(C) 2020 by Emanuele Gissi"
__revision__ = "$Format:%H$" # replaced with git SHA1
DEBUG = False
from qgis.core import (
QgsProject,
QgsPoint,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsProcessingException,
QgsProcessingAlgorithm,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterPoint,
QgsProcessingParameterExtent,
QgsProcessingParameterFile,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterBoolean,
QgsRasterFileWriter,
QgsRasterLayer,
QgsRasterPipe,
QgsRasterProjector
)
import os, sys
from .types import (
utils,
FDSCase,
Domain,
OBSTTerrain,
GEOMTerrain,
LanduseType,
Texture,
Wind,
)
from . import algos
import processing
DEFAULTS = {
"chid": "terrain",
"fds_path": "./",
"extent": None,
"pixel_size": 10.0,
"origin": None,
"dem_layer": None,
"landuse_layer": None,
"landuse_type_filepath": "",
"fire_layer": None,
"wind_filepath": "",
"tex_layer": None,
"tex_pixel_size": 5.0,
"nmesh": 1,
"cell_size": None,
"export_obst": True,
"debug": False,
}
class qgis2fdsAlgorithm(QgsProcessingAlgorithm):
"""
qgis2fds algorithm.
"""
def initAlgorithm(self, config=None):
"""!
Inputs and outputs of the algorithm.
"""
project = QgsProject.instance()
# Check if project crs has changed
prev_project_crs_desc, _ = project.readEntry("qgis2fds", "project_crs", None)
is_project_crs_changed = False
if prev_project_crs_desc != project.crs().description():
is_project_crs_changed = True
# Define parameter: chid
defaultValue, _ = project.readEntry("qgis2fds", "chid", DEFAULTS["chid"])
self.addParameter(
QgsProcessingParameterString(
"chid",
"FDS case identificator (CHID)",
multiLine=False,
defaultValue=defaultValue,
)
)
# Define parameter: fds_path
defaultValue, _ = project.readEntry(
"qgis2fds", "fds_path", DEFAULTS["fds_path"]
)
self.addParameter(
QgsProcessingParameterFile(
"fds_path",
"Save in folder",
behavior=QgsProcessingParameterFile.Folder,
fileFilter="All files (*.*)",
defaultValue=defaultValue,
)
)
# Define parameter: extent
defaultValue, _ = project.readEntry("qgis2fds", "extent", DEFAULTS["extent"])
self.addParameter(
QgsProcessingParameterExtent(
"extent",
"Domain extent",
defaultValue=defaultValue,
)
)
# Define parameter: pixel_size
defaultValue, _ = project.readDoubleEntry(
"qgis2fds", "pixel_size", DEFAULTS["pixel_size"]
)
self.addParameter(
QgsProcessingParameterNumber(
"pixel_size",
"Desired resolution (in meters)",
type=QgsProcessingParameterNumber.Double,
defaultValue=defaultValue,
minValue=0.1,
)
)
# Define parameter: origin [optional]
if is_project_crs_changed:
defaultValue = DEFAULTS["origin"]
else:
defaultValue, _ = project.readEntry(
"qgis2fds", "origin", DEFAULTS["origin"]
)
param = QgsProcessingParameterPoint(
"origin",
"Domain origin (if not set, use domain extent centroid)",
optional=True,
defaultValue=defaultValue,
)
self.addParameter(param)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
# Define parameter: dem_layer
defaultValue, _ = project.readEntry(
"qgis2fds", "dem_layer", DEFAULTS["dem_layer"]
)
if not defaultValue:
try: # first layer name containing "dem"
defaultValue = [
layer.name()
for layer in QgsProject.instance().mapLayers().values()
if "DEM" in layer.name() or "dem" in layer.name()
][0]
except IndexError:
pass
self.addParameter(
QgsProcessingParameterRasterLayer(
"dem_layer",
"DEM layer",
defaultValue=defaultValue,
)
)
# Define parameter: landuse_layer [optional]
defaultValue, _ = project.readEntry(
"qgis2fds", "landuse_layer", DEFAULTS["landuse_layer"]
)
self.addParameter(
QgsProcessingParameterRasterLayer(
"landuse_layer",
"Landuse layer (if not set, landuse is not exported)",
optional=True,
defaultValue=defaultValue,
)
)
# Define parameter: landuse_type_filepath [optional]
defaultValue, _ = project.readEntry(
"qgis2fds", "landuse_type_filepath", DEFAULTS["landuse_type_filepath"]
)
self.addParameter(
QgsProcessingParameterFile(
"landuse_type_filepath",
"Landuse type *.csv file (if not set, landuse is not exported)",
behavior=QgsProcessingParameterFile.File,
fileFilter="CSV files (*.csv)",
optional=True,
defaultValue=defaultValue,
)
)
# Define parameters: fire_layer [optional]
defaultValue, _ = project.readEntry(
"qgis2fds", "fire_layer", DEFAULTS["fire_layer"]
)
if not defaultValue:
try: # first layer name containing "fire"
defaultValue = [
layer.name()
for layer in QgsProject.instance().mapLayers().values()
if "Fire" in layer.name() or "fire" in layer.name()
][0]
except IndexError:
pass
self.addParameter(
QgsProcessingParameterVectorLayer(
"fire_layer",
"Fire layer",
optional=True,
defaultValue=defaultValue,
)
)
# Define parameters: devc_layer # FIXME implement
#
# defaultValue, _ = project.readEntry("qgis2fds", "devc_layer", None)
# if not defaultValue:
# try: # first layer name containing "devc"
# defaultValue = [
# layer.name()
# for layer in QgsProject.instance().mapLayers().values()
# if "DEVC" in layer.name() or "devc" in layer.name()
# ][0]
# except IndexError:
# pass
# self.addParameter(
# QgsProcessingParameterVectorLayer(
# "devc_layer",
# "FDS DEVCs layer",
# optional=True,
# defaultValue=defaultValue,
# )
# )
# Define parameters: wind_filepath [optional]
defaultValue, _ = project.readEntry(
"qgis2fds", "wind_filepath", DEFAULTS["wind_filepath"]
)
self.addParameter(
QgsProcessingParameterFile(
"wind_filepath",
"Wind *.csv file",
behavior=QgsProcessingParameterFile.File,
fileFilter="CSV files (*.csv)",
optional=True,
defaultValue=defaultValue,
)
)
# Define parameter: tex_layer [optional]
defaultValue, _ = project.readEntry(
"qgis2fds", "tex_layer", DEFAULTS["tex_layer"]
)
param = QgsProcessingParameterRasterLayer(
"tex_layer",
"Texture layer (if not set, export current view)",
optional=True,
defaultValue=defaultValue,
)
self.addParameter(param)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
# Define parameter: tex_pixel_size [optional]
defaultValue, _ = project.readDoubleEntry(
"qgis2fds", "tex_pixel_size", DEFAULTS["tex_pixel_size"]
)
param = QgsProcessingParameterNumber(
"tex_pixel_size",
"Texture layer pixel size (in meters)",
type=QgsProcessingParameterNumber.Double,
defaultValue=defaultValue,
minValue=0.1,
)
self.addParameter(param)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
# Define parameter: nmesh
defaultValue, _ = project.readNumEntry("qgis2fds", "nmesh", DEFAULTS["nmesh"])
param = QgsProcessingParameterNumber(
"nmesh",
"Max number of FDS MESHes",
type=QgsProcessingParameterNumber.Integer,
defaultValue=defaultValue,
minValue=1,
)
self.addParameter(param)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
# Define parameter: cell_size
defaultValue, _ = project.readDoubleEntry("qgis2fds", "cell_size")
param = QgsProcessingParameterNumber(
"cell_size",
"FDS MESH cell size (in meters; if not set, use desired resolution)",
type=QgsProcessingParameterNumber.Double,
optional=True,
defaultValue=defaultValue or None, # protect
minValue=0.1,
)
self.addParameter(param)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
# Define parameter: export_obst
defaultValue, _ = project.readBoolEntry(
"qgis2fds", "export_obst", DEFAULTS["export_obst"]
)
param = QgsProcessingParameterBoolean(
"export_obst",
"Export FDS OBSTs",
defaultValue=defaultValue,
)
self.addParameter(param)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
# Define parameter: debug
defaultValue, _ = project.readBoolEntry(
"qgis2fds", "debug", DEFAULTS["debug"]
)
param = QgsProcessingParameterBoolean("debug","debug",defaultValue=defaultValue)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param)
# Output
# param = QgsProcessingParameterFeatureSink( # DEBUG FIXME
# "utm_dem_layer", # Name
# "Interpolated DEM Layer", # Description
# createByDefault=False,
# defaultValue=None,
# )
# self.addParameter(param)
# param = QgsProcessingParameterFeatureSink( # DEBUG FIXME
# "sampling_layer", # Name
# "Sampling Layer", # Description
# type=QgsProcessing.TypeVectorPoint,
# createByDefault=False,
# defaultValue=None,
# )
# self.addParameter(param)
def processAlgorithm(self, parameters, context, feedback):
"""
Process algorithm.
"""
results, outputs, project = {}, {}, QgsProject.instance()
# Check project crs and save it
if not project.crs().isValid():
raise QgsProcessingException(
f"Project CRS <{project.crs().description()}> is not valid, cannot proceed."
)
project.writeEntry("qgis2fds", "project_crs", project.crs().description())
# Get parameter: chid
chid = self.parameterAsString(parameters, "chid", context)
if not chid:
raise QgsProcessingException(self.invalidSourceError(parameters, "chid"))
project.writeEntry("qgis2fds", "chid", chid)
# Get parameter: fds_path
project_path = project.readPath("./")
if not project_path:
raise QgsProcessingException(
"Save the qgis project to disk, cannot proceed."
)
fds_path = self.parameterAsFile(parameters, "fds_path", context)
if not fds_path:
raise QgsProcessingException(
self.invalidSourceError(parameters, "fds_path")
)
project.writeEntry("qgis2fds", "fds_path", fds_path)
fds_path = os.path.join(project_path, fds_path) # make abs
# Establish os specific parameters directory
if sys.platform.startswith('linux'):
pass
elif sys.platform == 'darwin':
os.environ["PROJ_LIB"]="/Applications/QGIS.app/Contents/Resources/proj"
elif (sys.platform == 'win32') or (sys.platform == 'cygwin'):
pass
# Get parameter for debug
DEBUG = self.parameterAsBool(parameters, "debug", context)
# Get parameter: pixel_size
pixel_size = self.parameterAsDouble(parameters, "pixel_size", context)
if not pixel_size or pixel_size <= 0.0:
raise QgsProcessingException(
self.invalidSourceError(parameters, "pixel_size")
)
project.writeEntryDouble("qgis2fds", "pixel_size", pixel_size)
# Get parameter: nmesh
nmesh = self.parameterAsInt(parameters, "nmesh", context)
if not nmesh or nmesh < 1:
raise QgsProcessingException(self.invalidSourceError(parameters, "nmesh"))
project.writeEntry("qgis2fds", "nmesh", nmesh)
# Get parameter: cell_size
cell_size = self.parameterAsDouble(parameters, "cell_size", context)
if not cell_size:
cell_size = pixel_size
project.writeEntry("qgis2fds", "cell_size", "")
elif cell_size <= 0.0:
raise QgsProcessingException(
self.invalidSourceError(parameters, "cell_size")
)
else:
project.writeEntryDouble("qgis2fds", "cell_size", cell_size)
# Get parameter: extent (and wgs84_extent)
extent = self.parameterAsExtent(parameters, "extent", context)
if not extent:
raise QgsProcessingException(self.invalidSourceError(parameters, "extent"))
project.writeEntry("qgis2fds", "extent", parameters["extent"]) # as str
wgs84_crs = QgsCoordinateReferenceSystem("EPSG:4326")
wgs84_extent = self.parameterAsExtent(
parameters, "extent", context, crs=wgs84_crs
)
# Get parameter: origin
wgs84_origin = QgsPoint(wgs84_extent.center())
origin = parameters.get("origin") or ""
project.writeEntry("qgis2fds", "origin", origin) # as str
if origin:
if "[" in origin:
crs_txt = origin.split('[')[1].split(']')[0]
origin_crs = QgsCoordinateReferenceSystem(crs_txt)
else:
origin_crs = project.crs()
# prevent a QGIS bug when using parameterAsPoint with crs=wgs84_crs
# the point is exported in project crs
origin = self.parameterAsPoint(parameters, "origin", context)
wgs84_origin = QgsPoint(origin)
project_to_wgs84_tr = QgsCoordinateTransform(
origin_crs, wgs84_crs, project
)
wgs84_origin.transform(project_to_wgs84_tr)
# Get applicable UTM crs, then UTM origin and extent
utm_epsg = utils.lonlat_to_epsg(lon=wgs84_origin.x(), lat=wgs84_origin.y())
utm_crs = QgsCoordinateReferenceSystem(utm_epsg)
wgs84_to_utm_tr = QgsCoordinateTransform(wgs84_crs, utm_crs, project)
utm_origin = wgs84_origin.clone()
utm_origin.transform(wgs84_to_utm_tr)
utm_extent = self.parameterAsExtent(parameters, "extent", context, crs=utm_crs)
# Get parameters: landuse_layer and landuse_type (optional)
landuse_layer, landuse_type_filepath = None, None
if "landuse_layer" in parameters and "landuse_type_filepath" in parameters:
landuse_type_filepath = self.parameterAsFile(
parameters, "landuse_type_filepath", context
)
landuse_layer = self.parameterAsRasterLayer(
parameters, "landuse_layer", context
)
if landuse_layer and not landuse_layer.crs().isValid():
raise QgsProcessingException(
f"Landuse layer CRS <{landuse_layer.crs().description()}> is not valid, cannot proceed."
)
project.writeEntry(
"qgis2fds", "landuse_layer", parameters.get("landuse_layer")
) # as str
project.writeEntry(
"qgis2fds", "landuse_type_filepath", landuse_type_filepath
)
landuse_type = LanduseType(
feedback=feedback,
project_path=project_path,
filepath=landuse_type_filepath,
)
# Get parameter: fire_layer (optional)
fire_layer, utm_fire_layer, utm_b_fire_layer = None, None, None
if "fire_layer" in parameters:
fire_layer = self.parameterAsVectorLayer(parameters, "fire_layer", context)
if fire_layer:
if not fire_layer.crs().isValid():
raise QgsProcessingException(
f"Fire layer CRS <{fire_layer.crs().description()}> is not valid, cannot proceed."
)
utm_fire_layer, utm_b_fire_layer = algos.get_utm_fire_layers(
context,
feedback,
fire_layer=fire_layer,
destination_crs=utm_crs,
pixel_size=pixel_size,
)
project.writeEntry(
"qgis2fds", "fire_layer", parameters.get("fire_layer")
) # as str
# Get devc_layer (optional)
# devc_layer = None
# if parameters["devc_layer"]:
# devc_layer = self.parameterAsVectorLayer(parameters, "devc_layer", context)
# if not devc_layer.crs().isValid():
# raise QgsProcessingException(
# f"DEVCs layer CRS <{devc_layer.crs().description()}> is not valid, cannot proceed."
# )
# project.writeEntry("qgis2fds", "devc_layer", parameters["devc_layer"])
# Get parameter: wind_filepath (optional)
wind_filepath = self.parameterAsFile(parameters, "wind_filepath", context)
project.writeEntry("qgis2fds", "wind_filepath", wind_filepath)
wind = Wind(
feedback=feedback, project_path=project_path, filepath=wind_filepath
)
# Get parameter: tex_layer (optional)
tex_layer, texture = None, None
if "tex_layer" in parameters:
tex_layer = self.parameterAsRasterLayer(parameters, "tex_layer", context)
if tex_layer and not tex_layer.crs().isValid():
raise QgsProcessingException(
f"Texture layer CRS <{tex_layer.crs().description()}> is not valid, cannot proceed."
)
project.writeEntry("qgis2fds", "tex_layer", parameters.get("tex_layer"))
# Get parameter: tex_pixel_size
tex_pixel_size = float(
self.parameterAsDouble(parameters, "tex_pixel_size", context)
)
if not tex_pixel_size or tex_pixel_size <= 0.0:
raise QgsProcessingException(
self.invalidSourceError(parameters, "tex_pixel_size")
)
project.writeEntryDouble("qgis2fds", "tex_pixel_size", tex_pixel_size)
texture = Texture(
feedback=feedback,
path=fds_path,
name=chid,
image_type="png",
pixel_size=tex_pixel_size,
tex_layer=tex_layer,
utm_extent=utm_extent,
utm_crs=utm_crs,
)
# Get DEVCs layer # FIXME implement
# utm_devc_layer = None
# if devc_layer:
# pass
# if feedback.isCanceled():
# return {}
# Get parameter: export_obst
export_obst = self.parameterAsBool(parameters, "export_obst", context)
project.writeEntryBool("qgis2fds", "export_obst", export_obst)
# Get parameter: dem_layer
dem_layer = self.parameterAsRasterLayer(parameters, "dem_layer", context)
if not dem_layer:
raise QgsProcessingException(
self.invalidSourceError(parameters, "dem_layer")
)
if not dem_layer.crs().isValid():
raise QgsProcessingException(
f"DEM layer CRS <{dem_layer.crs().description()}> is not valid, cannot proceed."
)
project.writeEntry("qgis2fds", "dem_layer", parameters.get("dem_layer"))
# Calc the interpolated DEM layer
outputs["utm_dem_layer"] = algos.clip_and_interpolate_dem(
context,
feedback,
dem_layer=dem_layer,
extent=utm_extent,
extent_crs=utm_crs,
pixel_size=pixel_size,
# output=parameters["utm_dem_layer"], # DEBUG
)
if feedback.isCanceled():
return {}
# results["utm_dem_layer"] = outputs["utm_dem_layer"]["OUTPUT"] # DEBUG
utm_dem_layer = QgsRasterLayer(outputs["utm_dem_layer"]["OUTPUT"])
# Get the sampling grid
outputs["sampling_layer"] = algos.get_sampling_point_grid_layer(
context,
feedback,
utm_dem_layer=utm_dem_layer,
landuse_layer=landuse_layer,
landuse_type=landuse_type,
utm_fire_layer=utm_fire_layer, # utm
utm_b_fire_layer=utm_b_fire_layer, # utm buffered
# output=parameters["sampling_layer"], # DEBUG
)
if feedback.isCanceled():
return {}
# if DEBUG:
# results["sampling_layer"] = outputs["sampling_layer"]["OUTPUT"] # DEBUG FIXME
sampling_layer = context.getMapLayer(outputs["sampling_layer"]["OUTPUT"])
if sampling_layer.featureCount() < 9:
raise QgsProcessingException(
f"[QGIS bug] Too few features in sampling layer, cannot proceed.\n{sampling_layer.featureCount()}"
)
# Align utm_extent to the new interpolated dem
utm_extent = algos.get_pixel_aligned_extent(
context,
feedback,
raster_layer=utm_dem_layer,
extent=None,
extent_crs=None,
to_centers=False,
larger=0.0,
)
if feedback.isCanceled():
return {}
if DEBUG:
for layer_id in context.temporaryLayerStore().mapLayers():
layer = context.getMapLayer(layer_id)
name = layer.name()
if chid in name:
outname = os.path.join(project_path,"debug_" + name)
else:
outname = os.path.join(project_path,"debug_" + chid + "_" + name)
if type(layer) is QgsRasterLayer:
outname = outname + '.tif'
renderer = layer.renderer()
provider = layer.dataProvider()
pipe = QgsRasterPipe()
projector = QgsRasterProjector()
projector.setCrs(layer.crs(), layer.crs())
file_writer = QgsRasterFileWriter(outname)
file_writer.Mode(1)
width = layer.width()
height = layer.height()
layer_extent = layer.extent()
layer_crs = layer.crs()
error = file_writer.writeRaster(pipe, width, height, layer_extent, layer_crs)
else:
outname = outname + '.gpkg'
alg_params = {"INPUT": name, "OUTPUT": outname, 'LAYER_NAME': name}
processing.run("native:savefeatures", alg_params, context=context)
feedback.pushInfo("Saving %s"%(outname))
# Prepare terrain, domain, and fds_case
if export_obst:
Terrain = OBSTTerrain
else:
Terrain = GEOMTerrain
terrain = Terrain(
feedback=feedback,
sampling_layer=sampling_layer,
utm_origin=utm_origin,
landuse_layer=landuse_layer,
landuse_type=landuse_type,
fire_layer=fire_layer,
path=fds_path,
name=chid,
)
if feedback.isCanceled():
return {}
domain = Domain(
feedback=feedback,
utm_crs=utm_crs,
utm_extent=utm_extent,
utm_origin=utm_origin,
wgs84_origin=wgs84_origin,
min_z=terrain.min_z,
max_z=terrain.max_z,
cell_size=cell_size,
nmesh=nmesh,
)
fds_case = FDSCase(
feedback=feedback,
path=fds_path,
name=chid,
utm_crs=utm_crs,
wgs84_origin=wgs84_origin,
pixel_size=pixel_size,
dem_layer=dem_layer,
domain=domain,
terrain=terrain,
texture=texture,
wind=wind,
)
fds_case.save()
return results
def name(self):
"""!
Returns the algorithm name.
"""
return "Export terrain"
def displayName(self):
"""!
Returns the translated algorithm name.
"""
return self.name()
def group(self):
"""!
Returns the name of the group this algorithm belongs to.
"""
return self.groupId()
def groupId(self):
"""
Returns the unique ID of the group this algorithm belongs to.
"""
return ""
def createInstance(self):
return qgis2fdsAlgorithm()