From 8e116c2faaaede48db5998fe1f5d327c3a95868f Mon Sep 17 00:00:00 2001 From: Scott Turner Date: Wed, 13 May 2020 19:54:55 -0400 Subject: [PATCH 1/3] Georeferencing: Set reference point correctly when loading templates When loading a template from an OCAD file, etc. hold on to the received combined scale factor rather than update it based on the auxiliary scale factor and grid scale factor. --- src/fileformats/ocd_georef_fields.cpp | 2 +- src/fileformats/xml_file_format.cpp | 2 +- src/gdal/ogr_file_format.cpp | 4 ++-- src/gdal/ogr_template.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fileformats/ocd_georef_fields.cpp b/src/fileformats/ocd_georef_fields.cpp index 8077c10c9..e49cc554c 100644 --- a/src/fileformats/ocd_georef_fields.cpp +++ b/src/fileformats/ocd_georef_fields.cpp @@ -851,7 +851,7 @@ void OcdGeorefFields::setupGeoref(Georeferencing& georef, applyGridAndZone(georef, i, warning_handler); QPointF proj_ref_point(x, y); - georef.setProjectedRefPoint(proj_ref_point, false); + georef.setProjectedRefPoint(proj_ref_point, false, false); georef.setGrivation(qIsFinite(a) ? a : 0); } diff --git a/src/fileformats/xml_file_format.cpp b/src/fileformats/xml_file_format.cpp index b8990a7c1..f4d034373 100644 --- a/src/fileformats/xml_file_format.cpp +++ b/src/fileformats/xml_file_format.cpp @@ -593,7 +593,7 @@ bool XMLFileImporter::importImplementation() auto georef = map->getGeoreferencing(); auto ref_point = MapCoordF { georef.getMapRefPoint() }; auto new_projected = georef.toProjectedCoords(ref_point + offset_f); - georef.setProjectedRefPoint(new_projected, false); + georef.setProjectedRefPoint(new_projected, false, false); map->setGeoreferencing(georef); } } diff --git a/src/gdal/ogr_file_format.cpp b/src/gdal/ogr_file_format.cpp index 21c6109e2..79a7efa4a 100644 --- a/src/gdal/ogr_file_format.cpp +++ b/src/gdal/ogr_file_format.cpp @@ -850,7 +850,7 @@ bool OgrFileImport::importImplementation() auto georef = map->getGeoreferencing(); auto ref_point = MapCoordF { georef.getMapRefPoint() }; auto new_projected = georef.toProjectedCoords(ref_point + offset_f); - georef.setProjectedRefPoint(new_projected, false); + georef.setProjectedRefPoint(new_projected, false, false); map->setGeoreferencing(georef); } } @@ -970,7 +970,7 @@ ogr::unique_srs OgrFileImport::importGeoreferencing(OGRDataSourceH data_source) QString::fromLatin1("+proj=ortho +datum=WGS84 +ellps=WGS84 +units=m +lat_0=%1 +lon_0=%2 +no_defs") .arg(latitude, 0, 'f') .arg(longitude, 0, 'f') ); - ortho_georef.setProjectedRefPoint({}, false); + ortho_georef.setProjectedRefPoint({}, false, false); ortho_georef.setDeclination(map->getGeoreferencing().getDeclination()); map->setGeoreferencing(ortho_georef); return srsFromMap(); diff --git a/src/gdal/ogr_template.cpp b/src/gdal/ogr_template.cpp index a347c1278..8a67d3a2a 100644 --- a/src/gdal/ogr_template.cpp +++ b/src/gdal/ogr_template.cpp @@ -193,7 +193,7 @@ std::unique_ptr OgrTemplate::makeOrthographicGeoreferencing(cons georef->setProjectedCRS(QString{}, QString::fromLatin1("+proj=ortho +datum=WGS84 +ellps=WGS84 +units=m +lat_0=%1 +lon_0=%2 +no_defs") .arg(center.latitude()).arg(center.longitude())); - georef->setProjectedRefPoint({}, false); + georef->setProjectedRefPoint({}, false, false); } else { @@ -367,7 +367,7 @@ try explicit_georef = std::make_unique(); explicit_georef->setScaleDenominator(int(map_georef.getScaleDenominator())); explicit_georef->setProjectedCRS(QString{}, projected_crs_spec); - explicit_georef->setProjectedRefPoint({}, false); + explicit_georef->setProjectedRefPoint({}, false, false); } } } From 07524fbd6e11dcd455b82b4a0cd9f41a4f4db8cc Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 14 May 2020 07:34:20 +0200 Subject: [PATCH 2/3] GeoreferenceMappingTest: Use common setProjectedRefPoint pattern Amends 8e116c2f. --- test/georef_ocd_mapping_t.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/georef_ocd_mapping_t.cpp b/test/georef_ocd_mapping_t.cpp index 2bd42b04e..559601c60 100644 --- a/test/georef_ocd_mapping_t.cpp +++ b/test/georef_ocd_mapping_t.cpp @@ -266,7 +266,7 @@ private slots: } georef.setProjectedCRS(georef_result.crs_id, spec, crs_params); - georef.setProjectedRefPoint(georef_result.ref_point, false); + georef.setProjectedRefPoint(georef_result.ref_point, false, false); georef.setScaleDenominator(georef_result.scale); georef.setDeclination(georef_result.declination); georef.setGrivation(georef_result.grivation); From fc8d1d71d72822d176391c2889769851003dceec Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 14 May 2020 08:37:11 +0200 Subject: [PATCH 3/3] Improve consistency in georeferencing setup After calling Georeferencing::setProjectedRefPoint(..., false, false), consistently configure scaling and rotation explicitly. In most cases, this means simply preserving the current values of combined scale factor and grivation (which affect the transformation to paper coordinates directly), causing calculated updates to auxiliary scale factor and declination. Given that transformation is preserved, there shall be no visible effect. However, the Georeferencing objects are put into a consistent state with regard to the scaling and rotation variables, similar to what is otherwise achieved by calling setProjectedRefPoint(...). This relevant at least where Georeferencing objects are saved/loaded as member of template configuration etc. --- src/fileformats/ocd_georef_fields.cpp | 2 +- src/fileformats/xml_file_format.cpp | 2 ++ src/gdal/ogr_file_format.cpp | 3 +++ src/gdal/ogr_template.cpp | 4 ++++ src/templates/template_image.cpp | 2 ++ src/templates/template_track.cpp | 2 ++ 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fileformats/ocd_georef_fields.cpp b/src/fileformats/ocd_georef_fields.cpp index e49cc554c..96dbc490b 100644 --- a/src/fileformats/ocd_georef_fields.cpp +++ b/src/fileformats/ocd_georef_fields.cpp @@ -852,7 +852,7 @@ void OcdGeorefFields::setupGeoref(Georeferencing& georef, QPointF proj_ref_point(x, y); georef.setProjectedRefPoint(proj_ref_point, false, false); - + georef.setCombinedScaleFactor(1.0); georef.setGrivation(qIsFinite(a) ? a : 0); } diff --git a/src/fileformats/xml_file_format.cpp b/src/fileformats/xml_file_format.cpp index f4d034373..3fed5e457 100644 --- a/src/fileformats/xml_file_format.cpp +++ b/src/fileformats/xml_file_format.cpp @@ -594,6 +594,8 @@ bool XMLFileImporter::importImplementation() auto ref_point = MapCoordF { georef.getMapRefPoint() }; auto new_projected = georef.toProjectedCoords(ref_point + offset_f); georef.setProjectedRefPoint(new_projected, false, false); + georef.setCombinedScaleFactor(georef.getCombinedScaleFactor()); // keep combined scale factor + georef.setGrivation(georef.getGrivation()); // keep grivation, update declination map->setGeoreferencing(georef); } } diff --git a/src/gdal/ogr_file_format.cpp b/src/gdal/ogr_file_format.cpp index 79a7efa4a..b582f7bc4 100644 --- a/src/gdal/ogr_file_format.cpp +++ b/src/gdal/ogr_file_format.cpp @@ -851,6 +851,8 @@ bool OgrFileImport::importImplementation() auto ref_point = MapCoordF { georef.getMapRefPoint() }; auto new_projected = georef.toProjectedCoords(ref_point + offset_f); georef.setProjectedRefPoint(new_projected, false, false); + georef.setCombinedScaleFactor(georef.getCombinedScaleFactor()); // keep combined scale factor + georef.setGrivation(georef.getGrivation()); // keep grivation, update declination map->setGeoreferencing(georef); } } @@ -971,6 +973,7 @@ ogr::unique_srs OgrFileImport::importGeoreferencing(OGRDataSourceH data_source) .arg(latitude, 0, 'f') .arg(longitude, 0, 'f') ); ortho_georef.setProjectedRefPoint({}, false, false); + ortho_georef.setCombinedScaleFactor(1.0); ortho_georef.setDeclination(map->getGeoreferencing().getDeclination()); map->setGeoreferencing(ortho_georef); return srsFromMap(); diff --git a/src/gdal/ogr_template.cpp b/src/gdal/ogr_template.cpp index 8a67d3a2a..6c34ae693 100644 --- a/src/gdal/ogr_template.cpp +++ b/src/gdal/ogr_template.cpp @@ -194,6 +194,8 @@ std::unique_ptr OgrTemplate::makeOrthographicGeoreferencing(cons QString::fromLatin1("+proj=ortho +datum=WGS84 +ellps=WGS84 +units=m +lat_0=%1 +lon_0=%2 +no_defs") .arg(center.latitude()).arg(center.longitude())); georef->setProjectedRefPoint({}, false, false); + georef->setCombinedScaleFactor(1.0); + georef->setGrivation(0.0); } else { @@ -368,6 +370,8 @@ try explicit_georef->setScaleDenominator(int(map_georef.getScaleDenominator())); explicit_georef->setProjectedCRS(QString{}, projected_crs_spec); explicit_georef->setProjectedRefPoint({}, false, false); + explicit_georef->setCombinedScaleFactor(1.0); + explicit_georef->setGrivation(0.0); } } } diff --git a/src/templates/template_image.cpp b/src/templates/template_image.cpp index e9ee9b138..cf4cd8157 100644 --- a/src/templates/template_image.cpp +++ b/src/templates/template_image.cpp @@ -235,6 +235,8 @@ bool TemplateImage::postLoadConfiguration(QWidget* dialog_parent, bool& out_cent calculateGeoreferencing(); auto const center_pixel = MapCoordF(0.5 * (image.width() - 1), 0.5 * (image.height() - 1)); initial_georef.setProjectedRefPoint(georef->toProjectedCoords(center_pixel)); + initial_georef.setCombinedScaleFactor(1.0); + initial_georef.setGrivation(0.0); } GeoreferencingDialog dialog(dialog_parent, map, &initial_georef, false); diff --git a/src/templates/template_track.cpp b/src/templates/template_track.cpp index 9a401e8bf..9313fc661 100644 --- a/src/templates/template_track.cpp +++ b/src/templates/template_track.cpp @@ -609,6 +609,8 @@ void TemplateTrack::applyProjectedCrsSpec() georef.setScaleDenominator(int(map->getScaleDenominator())); georef.setProjectedCRS(QString{}, projected_crs_spec); georef.setProjectedRefPoint({}); + georef.setCombinedScaleFactor(1.0); + georef.setGrivation(0.0); track.changeMapGeoreferencing(georef); }