-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QtLocationPlugin: Add ArduPilot SRTM Elevation Provider
- Loading branch information
Showing
16 changed files
with
704 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/**************************************************************************** | ||
* | ||
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> | ||
* | ||
* QGroundControl is licensed according to the terms in the file | ||
* COPYING.md in the root of the source code directory. | ||
* | ||
****************************************************************************/ | ||
|
||
#include "TerrainQueryArduPilot.h" | ||
#include "TerrainTileArduPilot.h" | ||
#include "ElevationMapProvider.h" | ||
#include "QGCFileDownload.h" | ||
#include "QGCLoggingCategory.h" | ||
#include "QGCMapUrlEngine.h" | ||
#include "QGCZip.h" | ||
|
||
#include <QtCore/QDir> | ||
#include <QtCore/QStandardPaths> | ||
#include <QtCore/QUrl> | ||
#include <QtCore/QUrlQuery> | ||
#include <QtNetwork/QNetworkAccessManager> | ||
#include <QtNetwork/QNetworkReply> | ||
#include <QtNetwork/QNetworkRequest> | ||
#include <QtNetwork/QSslConfiguration> | ||
#include <QtPositioning/QGeoCoordinate> | ||
|
||
QGC_LOGGING_CATEGORY(TerrainQueryArduPilotLog, "qgc.terrain.terrainqueryardupilot") | ||
|
||
TerrainQueryArduPilot::TerrainQueryArduPilot(QObject *parent) | ||
: TerrainOnlineQuery(parent) | ||
{ | ||
// qCDebug(TerrainQueryArduPilotLog) << Q_FUNC_INFO << this; | ||
} | ||
|
||
TerrainQueryArduPilot::~TerrainQueryArduPilot() | ||
{ | ||
// qCDebug(TerrainQueryArduPilotLog) << Q_FUNC_INFO << this; | ||
} | ||
|
||
void TerrainQueryArduPilot::requestCoordinateHeights(const QList<QGeoCoordinate> &coordinates) | ||
{ | ||
if (coordinates.isEmpty()) { | ||
return; | ||
} | ||
|
||
_queryMode = TerrainQuery::QueryModeCoordinates; | ||
|
||
QSet<QUrl> urls; | ||
urls.reserve(coordinates.size()); | ||
|
||
const SharedMapProvider provider = UrlFactory::getMapProviderFromProviderType(QString(ArduPilotTerrainElevationProvider::kProviderKey)); | ||
for (const QGeoCoordinate &coord : coordinates) { | ||
if (!coord.isValid()) { | ||
continue; | ||
} | ||
const int x = provider->long2tileX(coord.longitude(), 1); | ||
const int y = provider->lat2tileY(coord.latitude(), 1); | ||
const QUrl url = provider->getTileURL(x, y, 1); | ||
(void) urls.insert(url); | ||
} | ||
|
||
const QList <QUrl> urlList = urls.values(); | ||
for (const QUrl &url : urlList) { | ||
_sendQuery(url); | ||
} | ||
} | ||
|
||
void TerrainQueryArduPilot::_sendQuery(const QUrl &url) | ||
{ | ||
qCDebug(TerrainQueryArduPilotLog) << Q_FUNC_INFO << url; | ||
|
||
QGCFileDownload *const download = new QGCFileDownload(this); | ||
(void) connect(download, &QGCFileDownload::downloadComplete, this, &TerrainQueryArduPilot::_parseZipFile); | ||
(void) connect(download, &QGCFileDownload::downloadComplete, download, &QGCFileDownload::deleteLater); | ||
if (!download->download(url.toString())) { | ||
qCWarning(TerrainQueryArduPilotLog) << "Failed To Download File"; | ||
_requestFailed(); | ||
} | ||
} | ||
|
||
void TerrainQueryArduPilot::_parseZipFile(const QString &remoteFile, const QString &localFile, const QString &errorMsg) | ||
{ | ||
if (!errorMsg.isEmpty()) { | ||
qCWarning(TerrainQueryArduPilotLog) << "Error During Download:" << errorMsg; | ||
_requestFailed(); | ||
return; | ||
} | ||
|
||
// TODO: verify .endsWith(".hgt") | ||
|
||
const QString outputDirectoryPath = QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).path() + "/QGC/SRTM1"; | ||
if (!QGCZip::unzipFile(localFile, outputDirectoryPath)) { | ||
qCWarning(TerrainQueryArduPilotLog) << "Failed To Unzip File" << localFile; | ||
_requestFailed(); | ||
return; | ||
} | ||
|
||
QFile file(outputDirectoryPath + "/" + localFile); | ||
if (!file.open(QIODevice::ReadOnly)) { | ||
qCWarning(TerrainQueryArduPilotLog) << "Failed To Unzip File" << localFile; | ||
_requestFailed(); | ||
return; | ||
} | ||
|
||
const QByteArray hgtData = file.readAll(); | ||
file.close(); | ||
|
||
qCDebug(TerrainQueryArduPilotLog) << Q_FUNC_INFO << "success"; | ||
switch (_queryMode) { | ||
case TerrainQuery::QueryModeCoordinates: | ||
_parseCoordinateData(localFile, hgtData); | ||
break; | ||
default: | ||
qCWarning(TerrainQueryArduPilotLog) << Q_FUNC_INFO << "Query Mode Not Supported"; | ||
break; | ||
} | ||
} | ||
|
||
void TerrainQueryArduPilot::_parseCoordinateData(const QString &localFile, const QByteArray &hgtData) | ||
{ | ||
const QList<QGeoCoordinate> coordinates = TerrainTileArduPilot::parseCoordinateData(localFile, hgtData); | ||
|
||
QList<double> heights; | ||
heights.reserve(coordinates.size()); | ||
for (const QGeoCoordinate &coord: coordinates) { | ||
heights.append(coord.altitude()); | ||
} | ||
|
||
emit coordinateHeightsReceived(!heights.isEmpty(), heights); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/**************************************************************************** | ||
* | ||
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> | ||
* | ||
* QGroundControl is licensed according to the terms in the file | ||
* COPYING.md in the root of the source code directory. | ||
* | ||
****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <QtCore/QLoggingCategory> | ||
#include <QtCore/QObject> | ||
|
||
#include "TerrainQueryInterface.h" | ||
|
||
Q_DECLARE_LOGGING_CATEGORY(TerrainQueryArduPilotLog) | ||
|
||
class QGeoCoordinate; | ||
|
||
class TerrainQueryArduPilot : public TerrainOnlineQuery | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit TerrainQueryArduPilot(QObject *parent = nullptr); | ||
~TerrainQueryArduPilot(); | ||
|
||
void requestCoordinateHeights(const QList<QGeoCoordinate> &coordinates) final; | ||
|
||
private: | ||
void _sendQuery(const QUrl &path); | ||
void _parseZipFile(const QString &remoteFile, const QString &localFile, const QString &errorMsg); | ||
void _parseCoordinateData(const QString &localFile, const QByteArray &hgtData); | ||
}; |
Oops, something went wrong.