Skip to content

Commit a5a12bb

Browse files
authored
Merge GH-1407
Fix OGR georeferencing setup
2 parents 8aa0be0 + 9b3958b commit a5a12bb

File tree

5 files changed

+50
-14
lines changed

5 files changed

+50
-14
lines changed

src/gdal/ogr_file_format.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ namespace {
456456
{
457457
auto geo_srs = ogr::unique_srs { OSRNewSpatialReference(nullptr) };
458458
OSRSetWellKnownGeogCS(geo_srs.get(), "WGS84");
459+
#if GDAL_VERSION_MAJOR >= 3
460+
OSRSetAxisMappingStrategy(geo_srs.get(), OAMS_TRADITIONAL_GIS_ORDER);
461+
#endif
459462

460463
auto num_layers = OGR_DS_GetLayerCount(data_source);
461464
for (int i = 0; i < num_layers; ++i)

src/gdal/ogr_template.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,12 @@ namespace {
7171
}
7272

7373

74-
std::unique_ptr<Georeferencing> getDataGeoreferencing(const QString& path, const Georeferencing& initial_georef)
75-
{
76-
Map tmp_map;
77-
tmp_map.setGeoreferencing(initial_georef);
78-
OgrFileImport importer{ path, &tmp_map, nullptr, OgrFileImport::UnitOnGround};
79-
importer.setGeoreferencingImportEnabled(true);
80-
importer.setLoadSymbolsOnly(true);
81-
if (!importer.doImport())
82-
return {}; // failure
83-
84-
return std::make_unique<Georeferencing>(tmp_map.getGeoreferencing()); // success
85-
}
86-
87-
8874
bool preserveRefPoints(Georeferencing& data_georef, const Georeferencing& initial_georef)
8975
{
9076
// Keep a configured local reference point from initial_georef?
9177
auto data_crs_spec = data_georef.getProjectedCRSSpec();
9278
if ((!initial_georef.isValid() || initial_georef.isLocal())
79+
&& initial_georef.getProjectedRefPoint() != QPointF{}
9380
&& data_georef.isValid()
9481
&& !data_georef.isLocal()
9582
&& data_georef.getProjectedRefPoint() == QPointF{}
@@ -119,6 +106,20 @@ const std::vector<QByteArray>& OgrTemplate::supportedExtensions()
119106
}
120107

121108

109+
std::unique_ptr<Georeferencing> OgrTemplate::getDataGeoreferencing(const QString& path, const Georeferencing& initial_georef)
110+
{
111+
Map tmp_map;
112+
tmp_map.setGeoreferencing(initial_georef);
113+
OgrFileImport importer{ path, &tmp_map, nullptr, OgrFileImport::UnitOnGround};
114+
importer.setGeoreferencingImportEnabled(true);
115+
importer.setLoadSymbolsOnly(true);
116+
if (!importer.doImport())
117+
return {}; // failure
118+
119+
return std::make_unique<Georeferencing>(tmp_map.getGeoreferencing()); // success
120+
}
121+
122+
122123
OgrTemplate::OgrTemplate(const QString& path, Map* map)
123124
: TemplateMap(path, map)
124125
{

src/gdal/ogr_template.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Q_OBJECT
4949
public:
5050
static const std::vector<QByteArray>& supportedExtensions();
5151

52+
static std::unique_ptr<Georeferencing> getDataGeoreferencing(const QString& path, const Georeferencing& initial_georef);
53+
5254

5355
OgrTemplate(const QString& path, Map* map);
5456

test/data/templates/map.osm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<osm version="0.6" generator="dg0yt" copyright="OpenOrienteering" attribution="2019 OpenOrienteering" license="GPL-3+">
3+
<bounds minlat="50.0008100" minlon="7.9994900" maxlat="50.0009000" maxlon="7.9996600"/>
4+
<node id="1" visible="true" version="1" changeset="234" timestamp="2010-10-26T11:11:11Z" user="dg0yt" uid="3456" lat="50.00082" lon="7.99965"/>
5+
<node id="2" visible="true" version="1" changeset="234" timestamp="2010-10-26T11:11:11Z" user="dg0yt" uid="3456" lat="50.00089" lon="7.99965"/>
6+
<node id="3" visible="true" version="1" changeset="234" timestamp="2010-10-26T11:11:11Z" user="dg0yt" uid="3456" lat="50.00089" lon="7.99950"/>
7+
<node id="4" visible="true" version="1" changeset="234" timestamp="2010-10-26T11:11:11Z" user="dg0yt" uid="3456" lat="50.00082" lon="7.99950"/>
8+
<way id="5" visible="true" version="1" changeset="234" timestamp="2010-10-26T11:11:11Z" user="dg0yt" uid="3456">
9+
<nd ref="1"/>
10+
<nd ref="2"/>
11+
<nd ref="3"/>
12+
<nd ref="4"/>
13+
<nd ref="1"/>
14+
<tag k="building" v="yes"/>
15+
<tag k="name" v="Virtual Building"/>
16+
</way>
17+
</osm>

test/template_t.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "core/map.h"
3535
#include "core/map_view.h"
3636
#include "fileformats/xml_file_format_p.h"
37+
#include "gdal/ogr_template.h"
3738
#include "templates/template.h"
3839
#include "templates/world_file.h"
3940

@@ -200,6 +201,18 @@ private slots:
200201
#endif
201202
}
202203

204+
#ifdef MAPPER_USE_GDAL
205+
void ogrTemplateGeoreferencingTest()
206+
{
207+
auto const osm_fileinfo = QFileInfo(QStringLiteral("testdata:templates/map.osm"));
208+
QVERIFY(osm_fileinfo.exists());
209+
auto georef = OgrTemplate::getDataGeoreferencing(osm_fileinfo.absoluteFilePath(), Georeferencing{});
210+
QVERIFY(georef);
211+
auto latlon = georef->getGeographicRefPoint();
212+
QCOMPARE(qRound(latlon.latitude()), 50);
213+
QCOMPARE(qRound(latlon.longitude()), 8);
214+
}
215+
#endif
203216
};
204217

205218

0 commit comments

Comments
 (0)