forked from gvellut/FreehandRasterGeoreferencer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportgeorefrasterdialog.py
111 lines (91 loc) · 3.92 KB
/
exportgeorefrasterdialog.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
"""
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os.path
from PyQt5.QtWidgets import QDialog, QFileDialog, QMessageBox
from .ui_exportgeorefrasterdialog import Ui_ExportGeorefRasterDialog
class ExportGeorefRasterDialog(QDialog, Ui_ExportGeorefRasterDialog):
def __init__(self):
QDialog.__init__(self)
self.setupUi(self)
self.pushButtonBrowse.clicked.connect(self.showBrowserDialog)
self.checkBoxOnlyWorldFile.stateChanged.connect(self.setupOnlyWorldFile)
def clear(self, layer):
self.lineEditImagePath.setText("")
self.checkBoxRotationMode.setChecked(False)
self.checkBoxRotationMode.setEnabled(True)
self.checkBoxOnlyWorldFile.setChecked(False)
defaultPath, _ = os.path.splitext(layer.filepath)
self.defaultPath = defaultPath + "_georeferenced.png"
def setupOnlyWorldFile(self):
if self.checkBoxOnlyWorldFile.isChecked():
self._originalCheckBoxRotationModeChecked = (
self.checkBoxRotationMode.isChecked()
)
self.checkBoxRotationMode.setChecked(True)
self.checkBoxRotationMode.setEnabled(False)
else:
self.checkBoxRotationMode.setChecked(
self._originalCheckBoxRotationModeChecked
)
self.checkBoxRotationMode.setEnabled(True)
def showBrowserDialog(self):
if self.lineEditImagePath.text():
filepathDialog = self.lineEditImagePath.text()
else:
filepathDialog = self.defaultPath
if not self.checkBoxOnlyWorldFile.isChecked():
filepath, _ = QFileDialog.getSaveFileName(
None,
"Export georeferenced raster",
filepathDialog,
"Images (*.png *.bmp *.jpg *.tif *.tiff)",
)
else:
filepath, _ = QFileDialog.getOpenFileName(
None,
"Export world file for raster",
filepathDialog,
"Images (*.png *.bmp *.jpg *.tif *.tiff)",
)
if filepath:
self.lineEditImagePath.setText(filepath)
def accept(self):
result, message, details = self.validate()
if result:
self.done(QDialog.Accepted)
else:
msgBox = QMessageBox()
msgBox.setWindowTitle("Error")
msgBox.setText(message)
msgBox.setDetailedText(details)
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec_()
def validate(self):
result = True
message = ""
details = ""
self.isPutRotationInWorldFile = self.checkBoxRotationMode.isChecked()
self.isExportOnlyWorldFile = self.checkBoxOnlyWorldFile.isChecked()
self.imagePath = self.lineEditImagePath.text()
if not self.imagePath:
result = False
details += "A file must be selected"
if result:
_, extension = os.path.splitext(self.imagePath)
extension = extension.lower()
if extension not in [".jpg", ".bmp", ".png", ".tif", ".tiff"]:
result = False
if len(details) > 0:
details += "\n"
details += "The file must be an image"
if not result:
message = "There were errors in the form"
return result, message, details