3 #include "common/rectc.h"
7 static QList
<DEM::Tile
> tiles(const RectC
&rect
)
14 for (int i
= qFloor(rect
.top()); i
>= qFloor(rect
.bottom()); i
--)
15 for (int j
= qFloor(rect
.left()); j
<= qFloor(rect
.right()); j
++)
16 list
.append(DEM::Tile(j
, i
));
21 static bool isZip(const QUrl
&url
)
23 QFileInfo
fi(url
.fileName());
24 return (fi
.suffix().toLower() == "zip");
28 DEMLoader::DEMLoader(const QString
&dir
, QObject
*parent
)
29 : QObject(parent
), _dir(dir
)
31 _downloader
= new Downloader(this);
32 connect(_downloader
, &Downloader::finished
, this, &DEMLoader::finished
);
35 int DEMLoader::numTiles(const RectC
&rect
) const
37 QList
<DEM::Tile
> tl(tiles(rect
));
40 for (int i
= 0; i
< tl
.size(); i
++) {
41 const DEM::Tile
&t
= tl
.at(i
);
42 QString
fn(tileFile(t
));
43 QString
zn(fn
+ ".zip");
45 if (!(QFileInfo::exists(zn
) || QFileInfo::exists(fn
)))
52 bool DEMLoader::loadTiles(const RectC
&rect
)
54 QList
<DEM::Tile
> tl(tiles(rect
));
57 /* Create the user DEM dir only when a download is requested as it will
58 override the global DEM dir. */
59 if (!_dir
.mkpath(_dir
.absolutePath())) {
60 qWarning("%s: %s", qPrintable(_dir
.canonicalPath()),
61 "Error creating DEM directory");
64 DEM::setDir(_dir
.path());
66 for (int i
= 0; i
< tl
.size(); i
++) {
67 const DEM::Tile
&t
= tl
.at(i
);
68 QString
fn(tileFile(t
));
69 QString
zn(fn
+ ".zip");
71 if (!(QFileInfo::exists(zn
) || QFileInfo::exists(fn
))) {
73 dl
.append(Download(url
, isZip(url
) ? zn
: fn
));
76 if (dl
.size() > DEM_DOWNLOAD_LIMIT
) {
77 qWarning("DEM download limit (%d) exceeded.", DEM_DOWNLOAD_LIMIT
);
82 return _downloader
->get(dl
, _headers
);
85 bool DEMLoader::checkTiles(const RectC
&rect
) const
87 QList
<DEM::Tile
> tl(tiles(rect
));
89 for (int i
= 0; i
< tl
.size(); i
++) {
90 const DEM::Tile
&t
= tl
.at(i
);
91 QString
fn(tileFile(t
));
92 QString
zn(fn
+ ".zip");
94 if (!(QFileInfo::exists(zn
) || QFileInfo::exists(fn
)))
101 QUrl
DEMLoader::tileUrl(const DEM::Tile
&tile
) const
105 url
.replace("$lon", tile
.lonStr());
106 url
.replace("$lat", tile
.latStr());
111 QString
DEMLoader::tileFile(const DEM::Tile
&tile
) const
113 return _dir
.absoluteFilePath(tile
.fileName());
116 void DEMLoader::setAuthorization(const Authorization
&authorization
)
118 QList
<HTTPHeader
> headers
;
119 if (!authorization
.isNull())
120 headers
.append(authorization
.header());