@@ -25,13 +25,13 @@ def __init__(self, desired_pixel_size=0.5):
25
25
self .plan_layer = PlanLayer .get_from_project ()
26
26
27
27
if not self .plan_layer :
28
- iface .messageBar ().pushWarning ("" , "No active plan layer found ." )
28
+ iface .messageBar ().pushWarning ("" , "Ei aktiivista kaavaa ." )
29
29
return
30
30
31
31
self .feature = PlanLayer .get_feature_by_id (get_active_plan_id (), no_geometries = False )
32
32
33
33
if not self .feature :
34
- iface .messageBar ().pushWarning ("" , "No active feature found ." )
34
+ iface .messageBar ().pushWarning ("" , "Ei aktiivista kaavaa ." )
35
35
return
36
36
37
37
def select_output_file (self ):
@@ -40,7 +40,7 @@ def select_output_file(self):
40
40
None , "Määritä GeoTIFF tallennuspolku" , "" , "GeoTIFF Files (*.tif)"
41
41
)
42
42
if not geotiff_path :
43
- iface .messageBar ().pushWarning ("" , "No file selected ." )
43
+ iface .messageBar ().pushWarning ("" , "Tallennuspolkua ei määritetty ." )
44
44
return None
45
45
46
46
self .create_geotiff (geotiff_path )
@@ -49,16 +49,16 @@ def select_output_file(self):
49
49
def create_geotiff (self , geotiff_path ):
50
50
"""Creates a GeoTIFF from the active plan layer and feature."""
51
51
if not self .plan_layer or not self .feature :
52
- return # Stop if there is no valid layer or feature
52
+ return
53
53
54
- # **Get Feature Extent + Buffer**
54
+ # Set buffered bounding box
55
55
bbox = self .feature .geometry ().boundingBox ()
56
56
buffer_percentage = 0.1
57
57
buffer_x = bbox .width () * buffer_percentage
58
58
buffer_y = bbox .height () * buffer_percentage
59
59
buffered_bbox = bbox .buffered (max (buffer_x , buffer_y ))
60
60
61
- # **Set Map Rendering Settings**
61
+ # Rendering settings
62
62
settings = QgsMapSettings ()
63
63
settings .setLayers (
64
64
[
@@ -73,18 +73,17 @@ def create_geotiff(self, geotiff_path):
73
73
settings .setBackgroundColor (QColor (255 , 255 , 255 ))
74
74
settings .setExtent (buffered_bbox )
75
75
76
- # **Determine Image Size in Pixels**
76
+ # Calculate image size
77
77
pixels_x = int (buffered_bbox .width () / self .desired_pixel_size )
78
78
pixels_y = int (buffered_bbox .height () / self .desired_pixel_size )
79
79
settings .setOutputSize (QSize (pixels_x , pixels_y ))
80
80
81
- # **Render Map**
82
81
render = QgsMapRendererParallelJob (settings )
83
82
84
83
def finished ():
85
84
img = render .renderedImage ()
86
85
87
- # Save the image as PNG
86
+ # Save the image as PNG temporarily
88
87
image_path = geotiff_path .replace (".tif" , ".png" )
89
88
img .save (image_path , "PNG" )
90
89
@@ -94,16 +93,16 @@ def finished():
94
93
f .write (pgw_content )
95
94
96
95
# Convert PNG to GeoTIFF
97
- self ._create_geotiff_from_png (image_path , geotiff_path , settings , pixels_x , pixels_y , buffered_bbox )
96
+ self ._create_geotiff_from_png (image_path , geotiff_path , pixels_x , pixels_y , buffered_bbox )
98
97
99
- # ** Delete the temporary PNG file**
98
+ # Delete temporary PNG
100
99
if os .path .exists (image_path ):
101
100
os .remove (image_path )
102
101
103
102
render .finished .connect (finished )
104
103
render .start ()
105
104
106
- def _create_geotiff_from_png (self , image_path , geotiff_path , settings , pixels_x , pixels_y , buffered_bbox ):
105
+ def _create_geotiff_from_png (self , image_path , geotiff_path , pixels_x , pixels_y , buffered_bbox ):
107
106
"""Convert the rendered PNG to GeoTIFF."""
108
107
transform = [
109
108
buffered_bbox .xMinimum (),
0 commit comments