Skip to content

Commit e87495e

Browse files
committed
Moved calculating image size before png to geotiff conversion.
Moved calculating image size before png to geotiff conversion. Renamed class and file.
1 parent a586520 commit e87495e

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

arho_feature_template/core/create_geotiff.py arho_feature_template/core/geotiff_creator.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from arho_feature_template.utils.misc_utils import get_active_plan_id, use_wait_cursor
1919

2020

21-
class CreateGeoTiff:
21+
class GeoTiffCreator:
2222
def __init__(self, desired_pixel_size=0.5):
2323
"""Initialize the CreateGeoTiff class and fetch the required data."""
2424
self.desired_pixel_size = desired_pixel_size
@@ -71,6 +71,12 @@ def create_geotiff(self, geotiff_path):
7171
]
7272
)
7373
settings.setBackgroundColor(QColor(255, 255, 255))
74+
width = int(buffered_bbox.width() / self.desired_pixel_size) * self.desired_pixel_size
75+
height = int(buffered_bbox.height() / self.desired_pixel_size) * self.desired_pixel_size
76+
buffered_bbox.setXMinimum(int(buffered_bbox.xMinimum()))
77+
buffered_bbox.setYMinimum(int(buffered_bbox.yMinimum()))
78+
buffered_bbox.setXMaximum(buffered_bbox.xMinimum() + width)
79+
buffered_bbox.setYMaximum(buffered_bbox.yMinimum() + height)
7480
settings.setExtent(buffered_bbox)
7581

7682
# Calculate image size
@@ -107,24 +113,16 @@ def finished():
107113
render.finished.connect(finished)
108114
render.start()
109115

110-
def _create_geotiff_from_png(self, image_path, geotiff_path, pixels_x, pixels_y, buffered_bbox):
116+
def _create_geotiff_from_png(self, image_path, geotiff_path, buffered_bbox):
111117
"""Convert the rendered PNG to GeoTIFF."""
112-
transform = [
113-
buffered_bbox.xMinimum(),
114-
self.desired_pixel_size,
115-
0,
116-
buffered_bbox.yMaximum(),
117-
0,
118-
-self.desired_pixel_size,
119-
]
120118

121119
ds = gdal.Open(image_path)
122120

123121
output_bounds = [
124-
transform[0],
125-
transform[3],
126-
transform[0] + pixels_x * transform[1],
127-
transform[3] + pixels_y * transform[5],
122+
buffered_bbox.xMinimum(),
123+
buffered_bbox.yMaximum(),
124+
buffered_bbox.xMaximum(),
125+
buffered_bbox.yMinimum(),
128126
]
129127

130128
# Convert the PNG to GeoTIFF

arho_feature_template/plugin.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from qgis.PyQt.QtGui import QIcon
99
from qgis.PyQt.QtWidgets import QAction, QWidget
1010

11-
from arho_feature_template.core.create_geotiff import CreateGeoTiff
11+
from arho_feature_template.core.geotiff_creator import GeoTiffCreator
1212
from arho_feature_template.core.plan_manager import PlanManager
1313
from arho_feature_template.gui.dialogs.plugin_settings import PluginSettings
1414
from arho_feature_template.gui.docks.validation_dock import ValidationDock
@@ -292,8 +292,8 @@ def edit_lifecycles(self):
292292

293293
def create_geotiff(self):
294294
"""Create geotiff from currently active plan."""
295-
create_geotiff = CreateGeoTiff()
296-
create_geotiff.select_output_file()
295+
geotiff_creator = GeoTiffCreator()
296+
geotiff_creator.select_output_file()
297297

298298
def unload(self) -> None:
299299
"""Removes the plugin menu item and icon from QGIS GUI."""

0 commit comments

Comments
 (0)