Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
8b7553b5
Commit
8b7553b5
authored
Nov 16, 2017
by
Andreas Bircher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
download tiles when downloading offline map
parent
17fe7893
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
30 deletions
+80
-30
QGCMapEngineManager.cc
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc
+2
-0
QGCMapEngineManager.h
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h
+3
-0
Terrain.cc
src/Terrain.cc
+48
-12
Terrain.h
src/Terrain.h
+10
-1
TerrainTile.cc
src/TerrainTile.cc
+15
-15
TerrainTile.h
src/TerrainTile.h
+2
-2
No files found.
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc
View file @
8b7553b5
...
...
@@ -157,6 +157,8 @@ QGCMapEngineManager::startDownload(const QString& name, const QString& mapType)
}
else
{
qWarning
()
<<
"QGCMapEngineManager::startDownload() No Tiles to save"
;
}
// TODO: this could also get some feedback
_elevationProvider
.
cacheTerrainTiles
(
QGeoCoordinate
(
_bottomRightLat
,
_topleftLon
),
QGeoCoordinate
(
_topleftLat
,
_bottomRightLon
));
}
//-----------------------------------------------------------------------------
...
...
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h
View file @
8b7553b5
...
...
@@ -19,6 +19,7 @@
#include "QGCLoggingCategory.h"
#include "QGCMapEngine.h"
#include "QGCMapTileSet.h"
#include "Terrain.h"
Q_DECLARE_LOGGING_CATEGORY
(
QGCMapEngineManagerLog
)
...
...
@@ -152,6 +153,8 @@ private:
int
_actionProgress
;
ImportAction
_importAction
;
bool
_importReplace
;
ElevationProvider
_elevationProvider
;
};
#endif
src/Terrain.cc
View file @
8b7553b5
...
...
@@ -95,6 +95,37 @@ bool ElevationProvider::queryTerrainData(const QList<QGeoCoordinate>& coordinate
return
true
;
}
bool
ElevationProvider
::
cacheTerrainTiles
(
const
QGeoCoordinate
&
southWest
,
const
QGeoCoordinate
&
northEast
)
{
qCDebug
(
TerrainLog
)
<<
"Cache terrain tiles southWest:northEast"
<<
southWest
<<
northEast
;
// Correct corners of the tile to fixed grid
QGeoCoordinate
southWestCorrected
;
southWestCorrected
.
setLatitude
(
floor
(
southWest
.
latitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
southWestCorrected
.
setLongitude
(
floor
(
southWest
.
longitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
QGeoCoordinate
northEastCorrected
;
northEastCorrected
.
setLatitude
(
ceil
(
northEast
.
latitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
northEastCorrected
.
setLongitude
(
ceil
(
northEast
.
longitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
// Add all tiles to download queue
for
(
double
lat
=
southWestCorrected
.
latitude
()
+
TerrainTile
::
srtm1TileSize
/
2.0
;
lat
<
northEastCorrected
.
latitude
();
lat
+=
TerrainTile
::
srtm1TileSize
)
{
for
(
double
lon
=
southWestCorrected
.
longitude
()
+
TerrainTile
::
srtm1TileSize
/
2.0
;
lon
<
northEastCorrected
.
longitude
();
lon
+=
TerrainTile
::
srtm1TileSize
)
{
QString
uniqueTileId
=
_uniqueTileId
(
QGeoCoordinate
(
lat
,
lon
));
_tilesMutex
.
lock
();
if
(
_downloadQueue
.
contains
(
uniqueTileId
)
||
_tiles
.
contains
(
uniqueTileId
))
{
_tilesMutex
.
unlock
();
continue
;
}
_downloadQueue
.
append
(
uniqueTileId
.
replace
(
"_"
,
","
));
_tilesMutex
.
unlock
();
qCDebug
(
TerrainLog
)
<<
"Adding tile to download queue: "
<<
uniqueTileId
;
}
}
_downloadTiles
();
return
true
;
}
bool
ElevationProvider
::
cacheTerrainTiles
(
const
QList
<
QGeoCoordinate
>&
coordinates
)
{
if
(
coordinates
.
length
()
==
0
)
{
...
...
@@ -105,9 +136,10 @@ bool ElevationProvider::cacheTerrainTiles(const QList<QGeoCoordinate>& coordinat
QString
uniqueTileId
=
_uniqueTileId
(
coordinate
);
_tilesMutex
.
lock
();
if
(
_downloadQueue
.
contains
(
uniqueTileId
)
||
_tiles
.
contains
(
uniqueTileId
))
{
_tilesMutex
.
unlock
();
continue
;
}
_downloadQueue
.
append
(
uniqueTileId
.
replace
(
"
-
"
,
","
));
_downloadQueue
.
append
(
uniqueTileId
.
replace
(
"
_
"
,
","
));
_tilesMutex
.
unlock
();
qCDebug
(
TerrainLog
)
<<
"Adding tile to download queue: "
<<
uniqueTileId
;
}
...
...
@@ -166,7 +198,8 @@ void ElevationProvider::_requestFinishedTile()
QJsonParseError
parseError
;
QJsonDocument
responseJson
=
QJsonDocument
::
fromJson
(
responseBytes
,
&
parseError
);
qCDebug
(
TerrainLog
)
<<
"ERROR: Received "
<<
responseJson
;
// TODO: Handle error in downloading data
// TODO (birchera): Handle error in downloading data
_downloadTiles
();
return
;
}
...
...
@@ -175,7 +208,8 @@ void ElevationProvider::_requestFinishedTile()
QJsonParseError
parseError
;
QJsonDocument
responseJson
=
QJsonDocument
::
fromJson
(
responseBytes
,
&
parseError
);
if
(
parseError
.
error
!=
QJsonParseError
::
NoError
)
{
// TODO: Handle error in downloading data
// TODO (birchera): Handle error in downloading data
_downloadTiles
();
return
;
}
...
...
@@ -187,7 +221,7 @@ void ElevationProvider::_requestFinishedTile()
}
else
{
delete
tile
;
}
_tilesMutex
.
lock
();
_tilesMutex
.
un
lock
();
}
_downloadTiles
();
...
...
@@ -202,7 +236,7 @@ void ElevationProvider::_downloadTiles(void)
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
_downloadQueue
.
first
());
_downloadQueue
.
pop_front
();
_tilesMutex
.
unlock
();
QUrl
url
(
QStringLiteral
(
"https://api.airmap.com/elevation/stage/srtm1/carpet"
));
QUrl
url
(
QStringLiteral
(
"https://api.airmap.com/elevation/stage/srtm1/
ele/
carpet"
));
url
.
setQuery
(
query
);
QNetworkRequest
request
(
url
);
...
...
@@ -224,15 +258,17 @@ void ElevationProvider::_downloadTiles(void)
QString
ElevationProvider
::
_uniqueTileId
(
const
QGeoCoordinate
&
coordinate
)
{
QGeoCoordinate
southEast
;
southEast
.
setLatitude
(
floor
(
coordinate
.
latitude
()
*
40.0
)
/
40.0
);
southEast
.
setLongitude
(
floor
(
coordinate
.
longitude
()
*
40.0
)
/
40.0
);
// Compute corners of the tile
QGeoCoordinate
southWest
;
southWest
.
setLatitude
(
floor
(
coordinate
.
latitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
southWest
.
setLongitude
(
floor
(
coordinate
.
longitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
QGeoCoordinate
northEast
;
northEast
.
setLatitude
(
ceil
(
coordinate
.
latitude
()
*
40.0
)
/
40.0
);
northEast
.
setLongitude
(
ceil
(
coordinate
.
longitude
()
*
40.0
)
/
40.0
);
northEast
.
setLatitude
(
ceil
(
coordinate
.
latitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
northEast
.
setLongitude
(
ceil
(
coordinate
.
longitude
()
/
TerrainTile
::
srtm1TileSize
)
*
TerrainTile
::
srtm1TileSize
);
QString
ret
=
QString
::
number
(
southEast
.
latitude
(),
'f'
,
6
)
+
"-"
+
QString
::
number
(
southEast
.
longitude
(),
'f'
,
6
)
+
"-"
+
QString
::
number
(
northEast
.
latitude
(),
'f'
,
6
)
+
"-"
+
QString
::
number
(
northEast
.
longitude
(),
'f'
,
6
);
// Generate uniquely identifying string
QString
ret
=
QString
::
number
(
southWest
.
latitude
(),
'f'
,
6
)
+
"_"
+
QString
::
number
(
southWest
.
longitude
(),
'f'
,
6
)
+
"_"
+
QString
::
number
(
northEast
.
latitude
(),
'f'
,
6
)
+
"_"
+
QString
::
number
(
northEast
.
longitude
(),
'f'
,
6
);
qCDebug
(
TerrainLog
)
<<
"Computing unique tile id for "
<<
coordinate
<<
ret
;
return
ret
;
...
...
src/Terrain.h
View file @
8b7553b5
...
...
@@ -44,13 +44,22 @@ public:
*/
bool
queryTerrainData
(
const
QList
<
QGeoCoordinate
>&
coordinates
);
/**
* Cache all data in rectangular region given by list of coordinates.
*
* @param coordinates
* @return true on successful scheduling for download
*/
bool
cacheTerrainTiles
(
const
QList
<
QGeoCoordinate
>&
coordinates
);
/**
* Cache all data in rectangular region given by south west and north east corner.
*
* @param southWest
* @param northEast
* @return true on successful scheduling for download
*/
bool
cacheTerrainTiles
(
const
Q
List
<
QGeoCoordinate
>&
coordinates
);
bool
cacheTerrainTiles
(
const
Q
GeoCoordinate
&
southWest
,
const
QGeoCoordinate
&
northEast
);
signals:
void
terrainData
(
bool
success
,
QList
<
float
>
altitudes
);
...
...
src/TerrainTile.cc
View file @
8b7553b5
...
...
@@ -7,7 +7,7 @@
QGC_LOGGING_CATEGORY
(
TerrainTileLog
,
"TerrainTileLog"
)
const
double
TerrainTile
::
_srtm1TileSize
=
0.025
;
const
double
TerrainTile
::
srtm1TileSize
=
0.025
;
const
char
*
TerrainTile
::
_jsonStatusKey
=
"status"
;
const
char
*
TerrainTile
::
_jsonDataKey
=
"data"
;
const
char
*
TerrainTile
::
_jsonBoundsKey
=
"bounds"
;
...
...
@@ -47,7 +47,7 @@ TerrainTile::TerrainTile(QJsonDocument document)
QString
errorString
;
QList
<
JsonHelper
::
KeyValidateInfo
>
rootVersionKeyInfoList
=
{
{
_jsonStatusKey
,
QJsonValue
::
String
,
true
},
{
_jsonDataKey
,
QJsonValue
::
String
,
true
},
{
_jsonDataKey
,
QJsonValue
::
Object
,
true
},
};
if
(
!
JsonHelper
::
validateKeys
(
rootObject
,
rootVersionKeyInfoList
,
errorString
))
{
qCDebug
(
TerrainTileLog
)
<<
"Error in reading json: "
<<
errorString
;
...
...
@@ -91,7 +91,7 @@ TerrainTile::TerrainTile(QJsonDocument document)
_northEast
.
setLongitude
(
neArray
[
1
].
toDouble
());
// Stats
const
QJsonObject
&
statsObject
=
dataObject
[
_json
Bound
sKey
].
toObject
();
const
QJsonObject
&
statsObject
=
dataObject
[
_json
Stat
sKey
].
toObject
();
QList
<
JsonHelper
::
KeyValidateInfo
>
statsVersionKeyInfoList
=
{
{
_jsonMaxElevationKey
,
QJsonValue
::
Double
,
true
},
{
_jsonMinElevationKey
,
QJsonValue
::
Double
,
true
},
...
...
@@ -107,17 +107,17 @@ TerrainTile::TerrainTile(QJsonDocument document)
// Carpet
const
QJsonArray
&
carpetArray
=
dataObject
[
_jsonCarpetKey
].
toArray
();
if
(
carpetArray
.
count
()
!=
_gridSize
)
{
qCDebug
(
TerrainTileLog
)
<<
"Expected array of "
<<
_
gridSize
<<
", instead got "
<<
carpetArray
.
count
();
if
(
carpetArray
.
count
()
<
gridSize
)
{
// TODO (birchera): We always get 91x91 points, figure out why and where the exact location of the elev values are.
qCDebug
(
TerrainTileLog
)
<<
"Expected array of "
<<
gridSize
<<
", instead got "
<<
carpetArray
.
count
();
return
;
}
for
(
int
i
=
0
;
i
<
_
gridSize
;
i
++
)
{
for
(
int
i
=
0
;
i
<
gridSize
;
i
++
)
{
const
QJsonArray
&
row
=
carpetArray
[
i
].
toArray
();
if
(
row
.
count
()
!=
_gridSize
)
{
qCDebug
(
TerrainTileLog
)
<<
"Expected row array of "
<<
_
gridSize
<<
", instead got "
<<
row
.
count
();
if
(
row
.
count
()
<
gridSize
)
{
// TODO (birchera): the same as above
qCDebug
(
TerrainTileLog
)
<<
"Expected row array of "
<<
gridSize
<<
", instead got "
<<
row
.
count
();
return
;
}
for
(
int
j
=
0
;
j
<
_
gridSize
;
j
++
)
{
for
(
int
j
=
0
;
j
<
gridSize
;
j
++
)
{
_data
[
i
][
j
]
=
row
[
j
].
toDouble
();
}
}
...
...
@@ -130,8 +130,8 @@ bool TerrainTile::isIn(const QGeoCoordinate& coordinate) const
qCDebug
(
TerrainTileLog
)
<<
"isIn requested, but tile not valid"
;
return
false
;
}
bool
ret
=
coordinate
.
latitude
()
>=
_southWest
.
l
ong
itude
()
&&
coordinate
.
longitude
()
>=
_southWest
.
longitude
()
&&
coordinate
.
latitude
()
<=
_northEast
.
l
ong
itude
()
&&
coordinate
.
longitude
()
<=
_northEast
.
longitude
();
bool
ret
=
coordinate
.
latitude
()
>=
_southWest
.
l
at
itude
()
&&
coordinate
.
longitude
()
>=
_southWest
.
longitude
()
&&
coordinate
.
latitude
()
<=
_northEast
.
l
at
itude
()
&&
coordinate
.
longitude
()
<=
_northEast
.
longitude
();
qCDebug
(
TerrainTileLog
)
<<
"Checking isIn: "
<<
coordinate
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
<<
": "
<<
ret
;
return
ret
;
}
...
...
@@ -141,13 +141,13 @@ float TerrainTile::elevation(const QGeoCoordinate& coordinate) const
if
(
_isValid
)
{
qCDebug
(
TerrainTileLog
)
<<
"elevation: "
<<
coordinate
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
;
// Get the index at resolution of 1 arc second
int
indexLat
=
std
::
round
((
coordinate
.
latitude
()
-
_southWest
.
latitude
())
*
_gridSize
/
_
srtm1TileSize
);
int
indexLon
=
std
::
round
((
coordinate
.
longitude
()
-
_southWest
.
longitude
())
*
_gridSize
/
_
srtm1TileSize
);
int
indexLat
=
std
::
round
((
coordinate
.
latitude
()
-
_southWest
.
latitude
())
*
gridSize
/
srtm1TileSize
);
int
indexLon
=
std
::
round
((
coordinate
.
longitude
()
-
_southWest
.
longitude
())
*
gridSize
/
srtm1TileSize
);
qCDebug
(
TerrainTileLog
)
<<
"indexLat:indexLon"
<<
indexLat
<<
indexLon
;
// TODO (birchera): Move this down to the next debug output, once this is all properly working.
Q_ASSERT
(
indexLat
>=
0
);
Q_ASSERT
(
indexLat
<
_
gridSize
);
Q_ASSERT
(
indexLat
<
gridSize
);
Q_ASSERT
(
indexLon
>=
0
);
Q_ASSERT
(
indexLon
<
_
gridSize
);
Q_ASSERT
(
indexLon
<
gridSize
);
qCDebug
(
TerrainTileLog
)
<<
"elevation"
<<
_data
[
indexLat
][
indexLon
];
return
_data
[
indexLat
][
indexLon
];
}
else
{
...
...
src/TerrainTile.h
View file @
8b7553b5
...
...
@@ -74,10 +74,10 @@ public:
QGeoCoordinate
centerCoordinate
(
void
)
const
;
/// tile grid size in lat and lon
static
const
int
_
gridSize
=
TERRAIN_TILE_SIZE
;
static
const
int
gridSize
=
TERRAIN_TILE_SIZE
;
/// size of a tile in degree
static
const
double
_
srtm1TileSize
;
static
const
double
srtm1TileSize
;
private:
QGeoCoordinate
_southWest
;
/// South west corner of the tile
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment