35 #include <QFileDialog>
38 #include <QMessageBox>
41 #include <QInputDialog>
42 #include <QMessageBox>
46 #include <QTextStream>
47 #include <QMessageBox>
48 #include <boost/units/systems/si/io.hpp>
55 ui.statusbar->showMessage(tr(
"Opening image."));
58 const QString standard =
59 tr(
"Standard images (*.bmp *.gif *.jpg *.jpeg *.png *.pbm *.pgm *.ppm "
60 "*.tiff *.tif *.xbm *.xpm)");
62 const QString georeferenced =
63 tr(
"Geo-referenced images (*.tiff *.tif *.jp2 *.j2k *.jpf *.jpx *.jpm "
66 const QString all = tr(
"All files (*)");
68 const QString filtersList = standard +
";;" + georeferenced +
";;" + all;
70 QString selectedFilter;
72 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open file"),
77 if (!fileName.isEmpty()) {
78 if (selectedFilter == georeferenced) {
91 const QImage image (fileName);
93 QMessageBox::information(
this, tr(
"GeoDesk"),
94 tr(
"Cannot load %1.").arg(fileName));
98 imageLabel->setPixmap(QPixmap::fromImage(image));
101 imageLabel->adjustSize();
103 ui.actionZoomIn->setEnabled(
true);
104 ui.actionZoomOut->setEnabled(
true);
105 ui.actionNormalSize->setEnabled(
true);
106 ui.actionSetData->setEnabled(
false);
107 ui.actionSampleIsobath->setEnabled(
false);
108 ui.actionSetData->setChecked(
false);
109 ui.actionSampleIsobath->setChecked(
false);
112 const QFileInfo imageFile (fileName);
114 const QString imageExtension = imageFile.suffix();
116 const QString worldExtension =
'.' + imageExtension.at(0)
117 + imageExtension.at(imageExtension.size() - 1) +
'w';
120 imageFile.canonicalPath() + QDir::separator()
121 + imageFile.completeBaseName() + worldExtension;
123 ui.statusbar->showMessage(geoNotOk);
124 if (QFile::exists(worldFileName)) {
125 loadWorldFile(worldFileName);
128 ui.actionSaveWorldFile->setEnabled(
false);
129 ui.actionSaveReferencePoints->setEnabled(
false);
130 ui.actionSaveReferencePointsAs->setEnabled(
false);
132 dataFileName.clear();
133 referencePointFileName.clear();
137 ui.actionGeoreferenceImage->setEnabled(
true);
138 ui.actionSaveDataFile->setEnabled(
false);
139 ui.actionSaveDataFileAs->setEnabled(
false);
143 ui.statusbar->showMessage(noFile);
149 ui.statusbar->showMessage(tr(
"Loading world file."));
152 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open file"),
154 tr(
"World files (*.bpw *.gfw "
156 "*.tfw *.twfx *.xmw);;"
159 if (!fileName.isEmpty()) {
160 loadWorldFile(fileName);
162 ui.statusbar->showMessage(done);
165 ui.statusbar->showMessage(noFile);
171 ui.statusbar->showMessage(tr(
"Loading reference points."));
173 referencePointList.clear();
174 referencePointFileName = QFileDialog::getOpenFileName(
this, openFile,
178 if (!referencePointFileName.isEmpty()) {
180 QFile file (referencePointFileName);
181 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
183 QTextStream referencePointFileStream (&file);
185 while (!referencePointFileStream.atEnd()) {
190 referencePointFileStream >> image.
x() >> image.
y()
191 >> geographic.
x() >> geographic.
y();
193 const ReferencePointType referencePoint =
194 std::make_pair(image, geographic);
195 referencePointList.push_back(referencePoint);
199 QMessageBox::critical(
this, tr(
"Error"),
200 tr(
"File named \"%1\" cannot "
201 "be opened.").arg(referencePointFileName));
203 ui.statusbar->showMessage(done);
206 ui.statusbar->showMessage(noFile);
212 ui.statusbar->showMessage(tr(
"Loading data file."));
216 dataFileName = QFileDialog::getOpenFileName(
this, openFile,
217 QDir::currentPath(), textOrAny);
219 if (!dataFileName.isEmpty()) {
221 QFile file (dataFileName);
222 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
223 data = file.readAll();
227 QMessageBox::critical(
this, tr(
"Error"),
228 tr(
"File named \"%1\" cannot "
229 "be opened.").arg(dataFileName));
231 ui.statusbar->showMessage(done);
234 ui.statusbar->showMessage(noFile);
240 ui.statusbar->showMessage(tr(
"Zooming in."));
242 ui.statusbar->showMessage(done);
247 ui.statusbar->showMessage(tr(
"Zooming out."));
249 ui.statusbar->showMessage(done);
254 ui.statusbar->showMessage(tr(
"Back to normal size."));
255 imageLabel->adjustSize();
257 ui.actionZoomIn->setEnabled(
true);
258 ui.actionZoomOut->setEnabled(
true);
259 ui.statusbar->showMessage(done);
264 ui.statusbar->showMessage(tr(
"Saving reference points."));
266 if (referencePointFileName.isEmpty()) {
267 on_actionSaveReferencePointsAs_triggered();;
270 saveReferencePointFile();
276 ui.statusbar->showMessage(tr(
"Saving reference points in a new file."));
278 referencePointFileName = QFileDialog::getSaveFileName(
this,
286 saveReferencePointFile();
291 ui.statusbar->showMessage(tr(
"Saving world file."));
293 if (QFile::exists(worldFileName)) {
296 QMessageBox::question(
this, tr(
"Overwrite"),
297 tr(
"World file already exists, overwrite it?"),
298 QMessageBox::Yes | QMessageBox::No);
299 if (choice == QMessageBox::No) {
300 ui.statusbar->showMessage(aborted);
306 QFile worldFile (worldFileName);
307 worldFile.open(QIODevice::WriteOnly | QIODevice::Text
308 | QIODevice::Truncate);
310 QTextStream worldFileStream (&worldFile);
312 worldFileStream << change(0, 0) <<
'\n'
313 << change(1, 0) <<
'\n'
314 << change(0, 1) <<
'\n'
315 << change(1, 1) <<
'\n'
316 << change(0, 2) <<
'\n'
317 << change(1, 2) <<
'\n';
321 ui.actionSaveWorldFile->setEnabled(
false);
323 ui.statusbar->showMessage(tr(
"Saved world file: %1").arg(worldFileName));
329 ui.statusbar->showMessage(tr(
"Saving data file."));
331 if (dataFileName.isEmpty()) {
332 on_actionSaveDataFileAs_triggered();
341 ui.statusbar->showMessage(tr(
"Saving data in a new file."));
343 dataFileName = QFileDialog::getSaveFileName(
this, tr(
"Save data file as"),
345 tr(
"Text files (*.txt);;"
352 ui.statusbar->showMessage(
353 tr(
"Referencing: point 1 / %1").arg(requiredReference));
359 numberReferencePoints = 0;
366 ui.actionSampleIsobath->setEnabled(
true);
367 ui.statusbar->showMessage(tr(
"Stop setting geo-referenced data."));
371 ui.actionSampleIsobath->setEnabled(
false);
372 ui.statusbar->showMessage(tr(
"Setting geo-referenced data."));
380 ui.actionSetData->setEnabled(
true);
381 ui.statusbar->showMessage(tr(
"Stop sampling isobath."));
391 const double isobath =
392 QInputDialog::getDouble(
this, tr(
"Isobath value"),
393 tr(
"Enter isobath value in meter"), 0., 0.,
398 ui.actionSetData->setEnabled(
false);
399 ui.statusbar->showMessage(tr(
"Sampling isobath"));
402 ui.actionSampleIsobath->setChecked(
false);
410 const QChar degree = 0x00B0;
412 QWidget::mousePressEvent(event);
413 if (!imageLabel->pixmap())
return;
414 if (event->button() != Qt::LeftButton)
return;
417 const Point2D pos = getMousePosition(event->pos());
421 static std::vector<Point2D> r1 (requiredReference);
424 static std::vector<Point2D> r2 (requiredReference);
426 r1[numberReferencePoints] = pos;
429 r2[numberReferencePoints].x() =
430 QInputDialog::getDouble(
this, tr(
"Longitude"),
431 tr(
"Longitude in decimal degrees east"),
432 0., -180., 180., 4, &ok);
434 r2[numberReferencePoints].y() =
435 QInputDialog::getDouble(
this, tr(
"Latitude"),
436 tr(
"Latitude in decimal degrees north"),
437 0., -90., 90., 4, &ok);
439 referencePointList.push_back(std::make_pair(pos,
440 r2[numberReferencePoints]));
441 ui.actionSaveReferencePoints->setEnabled(
true);
442 ui.actionSaveReferencePointsAs->setEnabled(
true);
443 ++numberReferencePoints;
445 ui.statusbar->showMessage(
446 tr(
"Referencing: point %1 / %2").arg(numberReferencePoints
447 + 1).arg(requiredReference));
449 if (numberReferencePoints == requiredReference) {
451 ui.actionSaveWorldFile->setEnabled(
true);
452 ui.actionSetData->setEnabled(
true);
455 ui.statusbar->showMessage(geoOk);
460 const Eigen::Vector3d x (pos.
x(), pos.
y(), 1.);
462 const Eigen::Vector2d b = change * x;
464 const QString message = QString::number(b(0)) + degree + tr(
" E, ")
465 + QString::number(b(1)) + degree + tr(
" N");
469 const quantity<length> value
470 (QInputDialog::getDouble(
this, tr(
"Enter value"),
471 message, 0., 0., 15000., 2, &ok) * meter);
474 QTextStream dataStream (&data);
475 dataStream << pos.
x() <<
' ' << pos.
y() <<
' ' << b(0) <<
' ' << b(1)
476 <<
' ' << value.value() <<
'\n';
477 ui.actionSaveDataFile->setEnabled(
true);
478 ui.actionSaveDataFileAs->setEnabled(
true);
483 const Eigen::Vector3d x (pos.
x(), pos.
y(), 1.);
485 const Eigen::Vector2d b = change * x;
487 QTextStream dataStream (&data);
488 dataStream << pos.
x() <<
' ' << pos.
y() <<
' ' << b(0) <<
' ' << b(1)
489 <<
' ' << value <<
'\n';
490 ui.statusbar->showMessage(tr(
"Isobath ") + value + tr(
" m, ")
491 + QString::number(b(0)) + degree + tr(
" E,")
492 + QString::number(b(1)) + degree + tr(
" N"));
493 ui.actionSaveDataFile->setEnabled(
true);
494 ui.actionSaveDataFileAs->setEnabled(
true);
void on_actionSaveReferencePoints_triggered()
Save reference points, used for image geo-referencing.
void on_actionLoadDataFile_triggered()
Load a data file.
void on_actionLoadWorldFile_triggered()
Load a world file.
void on_actionSaveReferencePointsAs_triggered()
Save reference points in a new file.
void on_actionSaveDataFileAs_triggered()
Save data in a new file.
void on_actionZoomOut_triggered()
Zooms out an image.
void on_actionOpen_triggered()
Get the name of the file to be opened.
void on_actionSampleIsobath_triggered()
Sampling an isobath.
void on_actionSetData_triggered()
Enable setting of geo-referenced data.
Coefficients computeCoefficients(const std::vector< Point2D > &r1, const std::vector< Point2D > &r2)
Compute the projection coefficients.
void on_actionZoomIn_triggered()
Zooms in an image.
Definitions to create program main board.
double y() const
Access to ordinate, modification is not possible.
void on_actionSaveWorldFile_triggered()
Save a world file associated to an image.
void on_actionLoadReferencePoints_triggered()
Load reference points.
virtual void mousePressEvent(QMouseEvent *event)
What to do when mouse is clicked.
void on_actionGeoreferenceImage_triggered()
Give reference points for image geo-reference.
void on_actionNormalSize_triggered()
Gets the image back to its normal size.
double x() const
Access to abscissa, modification is not possible.
void on_actionSaveDataFile_triggered()
Save data which have been set by user.