20
20
#include " kmz_groundoverlay_export.h"
21
21
22
22
#include < algorithm>
23
+ #include < cmath>
23
24
#include < iterator>
24
25
#include < vector>
25
26
@@ -147,8 +148,10 @@ KmzGroundOverlayExport::Metrics KmzGroundOverlayExport::makeMetrics(qreal const
147
148
KmzGroundOverlayExport::~KmzGroundOverlayExport () = default ;
148
149
149
150
KmzGroundOverlayExport::KmzGroundOverlayExport (const QString& path, const Map& map)
150
- : map(map)
151
- , is_kmz(path.endsWith(QLatin1String(" .kmz" ), Qt::CaseInsensitive))
151
+ : map(map)
152
+ , overlap(std::max(2 * (std::nexttoward(180.0 , 181.0 ) - 180.0 ), 0.000000000000001 ))
153
+ , precision(std::max(std::ceil(log(overlap)/log(0.1 ) + 0.5 ), 12.0 ))
154
+ , is_kmz(path.endsWith(QLatin1String(" .kmz" ), Qt::CaseInsensitive))
152
155
{
153
156
auto const fileinfo = QFileInfo (path);
154
157
if (is_kmz)
@@ -299,14 +302,19 @@ std::vector<KmzGroundOverlayExport::Tile> KmzGroundOverlayExport::makeTiles(cons
299
302
auto const bounding_box_map = boundingBoxMap (georef, bounding_box_lonlat);
300
303
301
304
auto eastwards = QLineF::fromPolar (metrics.tile_size_mm , georef.getDeclination ()).p2 ();
302
- auto southwards = QLineF::fromPolar (metrics.tile_size_mm , georef.getDeclination () + 270 ).p2 ();
305
+ auto northwards = QLineF::fromPolar (metrics.tile_size_mm , georef.getDeclination () + 90 ).p2 ();
303
306
304
307
auto const start_map = georef.toMapCoordF (fromLonLat (bounding_box_lonlat.topLeft ()));
305
308
auto tile_lonlat = QRectF (bounding_box_lonlat.topLeft (),
306
- toLonLat (georef.toGeographicCoords (MapCoordF (start_map + eastwards + southwards)))).normalized ();
307
- while (tile_lonlat.top () < bounding_box_lonlat.bottom ())
309
+ toLonLat (georef.toGeographicCoords (MapCoordF (start_map + eastwards + northwards))))
310
+ .normalized ();
311
+ auto const delta = QPointF (tile_lonlat.width () - overlap, tile_lonlat.height () - overlap);
312
+
313
+ auto const last_y = int (std::ceil ((bounding_box_lonlat.height () - overlap) / delta.y ()));
314
+ for (int y = 0 ; y < last_y; ++y)
308
315
{
309
- while (tile_lonlat.left () < bounding_box_lonlat.right ())
316
+ auto const last_x = int (std::ceil ((bounding_box_lonlat.width () - overlap) / delta.x ()));
317
+ for (int x = 0 ; x < last_x; ++x)
310
318
{
311
319
MapCoordF tile_map[] = {
312
320
georef.toMapCoordF (fromLonLat (tile_lonlat.topLeft ())),
@@ -320,15 +328,15 @@ std::vector<KmzGroundOverlayExport::Tile> KmzGroundOverlayExport::makeTiles(cons
320
328
&& std::any_of (begin (tile_map), end (tile_map), [&bounding_box_map](auto & p) { return p.y () >= bounding_box_map.top (); })
321
329
&& std::any_of (begin (tile_map), end (tile_map), [&bounding_box_map](auto & p) { return p.y () <= bounding_box_map.bottom (); }))
322
330
{
323
- auto const name = QByteArray (QByteArray::number (int (tiles. size ()) ) + " .jpg" );
331
+ auto const name = QByteArray (" tile_ " + QByteArray::number (x) + ' _ ' + QByteArray::number (y ) + " .jpg" );
324
332
auto const filepath = QByteArray (" files/" + name);
325
333
tiles.push_back ({name, filepath, tile_lonlat, boundingBox (tile_map[0 ], tile_map[1 ], tile_map[2 ], tile_map[3 ])});
326
334
}
327
335
328
- tile_lonlat.moveLeft (tile_lonlat.right ());
336
+ tile_lonlat.moveLeft (tile_lonlat.left () + delta. x ());
329
337
}
330
338
tile_lonlat.moveLeft (bounding_box_lonlat.left ());
331
- tile_lonlat.moveTop (tile_lonlat.bottom ());
339
+ tile_lonlat.moveTop (tile_lonlat.top () + delta. y ());
332
340
}
333
341
return tiles;
334
342
}
@@ -352,10 +360,10 @@ void KmzGroundOverlayExport::writeKml(QByteArray& buffer, const std::vector<KmzG
352
360
" <href>" ).append (tile.filepath ).append (" </href>\n "
353
361
" </Icon>\n "
354
362
" <LatLonBox>\n "
355
- " <north>" ).append (QByteArray::number (tile.rect_lonlat .bottom (), ' f' , 10 )).append (" </north>\n "
356
- " <south>" ).append (QByteArray::number (tile.rect_lonlat .top (), ' f' , 10 )).append (" </south>\n "
357
- " <east>" ).append (QByteArray::number (tile.rect_lonlat .right (), ' f' , 10 )).append (" </east>\n "
358
- " <west>" ).append (QByteArray::number (tile.rect_lonlat .left (), ' f' , 10 )).append (" </west>\n "
363
+ " <north>" ).append (QByteArray::number (tile.rect_lonlat .bottom (), ' f' , precision )).append (" </north>\n "
364
+ " <south>" ).append (QByteArray::number (tile.rect_lonlat .top (), ' f' , precision )).append (" </south>\n "
365
+ " <east>" ).append (QByteArray::number (tile.rect_lonlat .right (), ' f' , precision )).append (" </east>\n "
366
+ " <west>" ).append (QByteArray::number (tile.rect_lonlat .left (), ' f' , precision )).append (" </west>\n "
359
367
" <rotation>0</rotation>\n "
360
368
" </LatLonBox>\n "
361
369
" </GroundOverlay>\n "
0 commit comments