Skip to content

Commit

Permalink
Merge GH-1522 (template georeferencing setup)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt committed Feb 13, 2020
2 parents 4b1116b + a7c0ca1 commit de9b337
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 178 deletions.
11 changes: 5 additions & 6 deletions src/gdal/gdal_image_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Kai Pastor
* Copyright 2019, 2020 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -284,12 +284,11 @@ TemplateImage::GeoreferencingOption GdalImageReader::readGeoTransform()
auto const result = GDALGetGeoTransform(dataset, geo_transform.data());
if (result == CE_None)
{
georef.type = TemplateImage::Georeferencing_GDAL;
georef.source = GDALGetDriverShortName(GDALGetDatasetDriver(dataset));
georef.crs_spec = toProjSpec(GDALGetProjectionRef(dataset));
georef.pixel_to_world = { geo_transform[1], geo_transform[2],
geo_transform[4], geo_transform[5],
geo_transform[0], geo_transform[3] };
georef.transform.source = GDALGetDriverShortName(GDALGetDatasetDriver(dataset));
georef.transform.pixel_to_world = { geo_transform[1], geo_transform[2],
geo_transform[4], geo_transform[5],
geo_transform[0], geo_transform[3] };
}
}
return georef;
Expand Down
4 changes: 2 additions & 2 deletions src/gdal/gdal_template.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Kai Pastor
* Copyright 2019, 2020 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -85,7 +85,7 @@ bool GdalTemplate::loadTemplateFileImpl(bool configuring)
available_georef = findAvailableGeoreferencing(reader.readGeoTransform());
if (!configuring && is_georeferenced)
{
if (available_georef.front().type == Georeferencing_None)
if (!isGeoreferencingUsable())
{
// Image was georeferenced, but georeferencing info is gone -> deny to load template
setErrorString(::OpenOrienteering::TemplateImage::tr("Georeferencing not found"));
Expand Down
48 changes: 31 additions & 17 deletions src/gui/select_crs_dialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2015 Kai Pastor
* Copyright 2012-2020 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -41,9 +41,10 @@ namespace OpenOrienteering {
namespace {

enum SpecialCRS {
SameAsMap = 1,
Local = 2,
Geographic = 3
SameAsMap = 1,
Local = 2,
Geographic = 3,
TemplateFile = 4,
};


Expand All @@ -52,34 +53,30 @@ enum SpecialCRS {


SelectCRSDialog::SelectCRSDialog(
const TemplateImage::GeoreferencingOptions& options,
const Georeferencing& georef,
QWidget* parent,
GeorefAlternatives alternatives,
const QString& description )
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint)
, options(options)
, georef(georef)
{
setWindowModality(Qt::WindowModal);
setWindowTitle(tr("Select coordinate reference system"));

crs_selector = new CRSSelector(georef, nullptr);
if (georef.isLocal())
crs_selector->clear();

if (alternatives.testFlag(TakeFromMap) && !georef.isLocal())
{
crs_selector->addCustomItem(tr("Same as map"), SpecialCRS::SameAsMap);
crs_selector->setCurrentIndex(0); // TakeFromMap
}

if (alternatives.testFlag(Local) || georef.isLocal())
{
crs_selector->clear();
crs_selector->addCustomItem(tr("Local"), SpecialCRS::Local);
crs_selector->setCurrentIndex(0); // TakeFromMap or Local, both is fine.
}

if (alternatives.testFlag(Geographic) && !georef.isLocal())
else
{
if (!options.template_file.crs_spec.isEmpty())
crs_selector->addCustomItem(tr("From template file"), SpecialCRS::TemplateFile );
crs_selector->addCustomItem(tr("Same as map"), SpecialCRS::SameAsMap);
crs_selector->addCustomItem(tr("Geographic coordinates (WGS84)"), SpecialCRS::Geographic);
}

status_label = new QLabel();
button_box = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
Expand All @@ -95,6 +92,20 @@ SelectCRSDialog::SelectCRSDialog(
form_layout->addItem(Util::SpacerItem::create(this));
crs_selector->setDialogLayout(form_layout);

auto const& crs_spec = options.effective.crs_spec;
if (georef.isLocal())
crs_selector->setCurrentIndex(0);
else if (crs_spec.isEmpty())
crs_selector->setCurrentIndex(crs_selector->findData(SpecialCRS::SameAsMap));
else if (crs_spec == options.template_file.crs_spec)
crs_selector->setCurrentIndex(crs_selector->findData(SpecialCRS::TemplateFile));
else if (crs_spec == georef.getProjectedCRSSpec())
crs_selector->setCurrentIndex(crs_selector->findData(SpecialCRS::SameAsMap));
else if (crs_spec == Georeferencing::geographic_crs_spec)
crs_selector->setCurrentIndex(crs_selector->findData(SpecialCRS::Geographic));
else
crs_selector->setCurrentCRS(CRSTemplateRegistry().find(QString::fromLatin1("PROJ.4")), { crs_spec });

auto layout = new QVBoxLayout();
layout->addLayout(form_layout, 1);
layout->addWidget(button_box, 0);
Expand All @@ -121,6 +132,9 @@ QString SelectCRSDialog::currentCRSSpec() const
case SpecialCRS::Geographic:
spec = Georeferencing::geographic_crs_spec;
break;
case SpecialCRS::TemplateFile:
spec = options.template_file.crs_spec;
break;
default:
spec = crs_selector->currentCRSSpec();
}
Expand Down
24 changes: 5 additions & 19 deletions src/gui/select_crs_dialog.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2015 Kai Pastor
* Copyright 2012-2020 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand All @@ -27,6 +27,8 @@
#include <QObject>
#include <QString>

#include "templates/template_image.h"

class QDialogButtonBox;
class QLabel;
class QWidget;
Expand All @@ -42,19 +44,6 @@ class SelectCRSDialog : public QDialog
{
Q_OBJECT
public:

/**
* Georeferencing alternatives
*/
enum GeorefAlternative
{
TakeFromMap = 1 << 0,
Local = 1 << 1,
Geographic = 1 << 2,
None = 0
};
Q_DECLARE_FLAGS(GeorefAlternatives, GeorefAlternative)

/**
* Creates a SelectCRSDialog.
*
Expand All @@ -65,9 +54,9 @@ Q_OBJECT
* Should explain what the selected CRS will be used for.
*/
SelectCRSDialog(
const TemplateImage::GeoreferencingOptions& options,
const Georeferencing& georef,
QWidget* parent,
GeorefAlternatives alternatives,
const QString& description = QString()
);

Expand All @@ -83,6 +72,7 @@ Q_OBJECT
void updateWidgets();

private:
const TemplateImage::GeoreferencingOptions& options;
const Georeferencing& georef;
CRSSelector* crs_selector;
QLabel* status_label;
Expand All @@ -92,8 +82,4 @@ Q_OBJECT

} // namespace OpenOrienteering


Q_DECLARE_OPERATORS_FOR_FLAGS(OpenOrienteering::SelectCRSDialog::GeorefAlternatives)


#endif
6 changes: 3 additions & 3 deletions src/gui/widgets/template_list_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2019 Kai Pastor
* Copyright 2012-2020 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -1102,10 +1102,10 @@ void TemplateListWidget::changeGeorefClicked()
if (position_action->isChecked())
position_action->trigger();
}
if (templ->trySetTemplateGeoreferenced(new_value, this) != new_value)
if (!templ->trySetTemplateGeoreferenced(new_value, this))
{
QMessageBox::warning(this, tr("Error"), tr("Cannot change the georeferencing state."));
georef_action->setChecked(false);
georef_action->setChecked(templ->isTemplateGeoreferenced());
}
updateButtons();
}
Expand Down
6 changes: 3 additions & 3 deletions src/templates/template.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2013-2019 Kai Pastor
* Copyright 2013-2020 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -676,9 +676,9 @@ bool Template::canChangeTemplateGeoreferenced()
}

// virtual
bool Template::trySetTemplateGeoreferenced(bool /*value*/, QWidget* /*dialog_parent*/)
bool Template::trySetTemplateGeoreferenced(bool value, QWidget* /*dialog_parent*/)
{
return is_georeferenced;
return isTemplateGeoreferenced() == value;
}


Expand Down
11 changes: 5 additions & 6 deletions src/templates/template.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2019 Kai Pastor
* Copyright 2012-2020 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -518,12 +518,11 @@ Q_OBJECT
* Tries to change the usage of georeferencing data.
*
* If supported by the actual template, this function tries to switch the
* state between non-georeferenced and georeferenced. It returns the final
* state which may be the same as before if the change is not implemented
* or fails for other reasons.
* state between non-georeferenced and georeferenced. It returns false when
* an error occurred, and true if the change was successful or if it was
* explicitly cancelled by the user.
*
* The default implementation changes nothing, and it just returns the
* current state.
* The default implementation returns true iff the state matches the value.
*/
virtual bool trySetTemplateGeoreferenced(bool value, QWidget* dialog_parent);

Expand Down
Loading

0 comments on commit de9b337

Please sign in to comment.