Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qgroundcontrol
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Valentin Platzgummer
qgroundcontrol
Commits
6467f653
Commit
6467f653
authored
7 years ago
by
Andreas Bircher
Browse files
Options
Downloads
Patches
Plain Diff
correct localization of the data points
Conflicts: src/ElevationProfiler.cc
parent
f632bb74
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TerrainTile.cc
+48
-16
48 additions, 16 deletions
src/TerrainTile.cc
src/TerrainTile.h
+12
-4
12 additions, 4 deletions
src/TerrainTile.h
with
60 additions
and
20 deletions
src/TerrainTile.cc
+
48
−
16
View file @
6467f653
...
@@ -23,6 +23,9 @@ TerrainTile::TerrainTile()
...
@@ -23,6 +23,9 @@ TerrainTile::TerrainTile()
:
_minElevation
(
-
1.0
)
:
_minElevation
(
-
1.0
)
,
_maxElevation
(
-
1.0
)
,
_maxElevation
(
-
1.0
)
,
_avgElevation
(
-
1.0
)
,
_avgElevation
(
-
1.0
)
,
_data
(
NULL
)
,
_gridSizeLat
(
-
1
)
,
_gridSizeLon
(
-
1
)
,
_isValid
(
false
)
,
_isValid
(
false
)
{
{
...
@@ -30,6 +33,13 @@ TerrainTile::TerrainTile()
...
@@ -30,6 +33,13 @@ TerrainTile::TerrainTile()
TerrainTile
::~
TerrainTile
()
TerrainTile
::~
TerrainTile
()
{
{
if
(
_data
)
{
for
(
int
i
=
0
;
i
<
_gridSizeLat
;
i
++
)
{
delete
_data
[
i
];
delete
_data
;
_data
=
NULL
;
}
}
}
}
TerrainTile
::
TerrainTile
(
QJsonDocument
document
)
TerrainTile
::
TerrainTile
(
QJsonDocument
document
)
...
@@ -107,17 +117,25 @@ TerrainTile::TerrainTile(QJsonDocument document)
...
@@ -107,17 +117,25 @@ TerrainTile::TerrainTile(QJsonDocument document)
// Carpet
// Carpet
const
QJsonArray
&
carpetArray
=
dataObject
[
_jsonCarpetKey
].
toArray
();
const
QJsonArray
&
carpetArray
=
dataObject
[
_jsonCarpetKey
].
toArray
();
if
(
carpetArray
.
count
()
<
gridSize
)
{
// TODO (birchera): We always get 91x91 points, figure out why and where the exact location of the elev values are.
_gridSizeLat
=
carpetArray
.
count
();
qCDebug
(
TerrainTileLog
)
<<
"Expected array of "
<<
gridSize
<<
", instead got "
<<
carpetArray
.
count
();
qCDebug
(
TerrainTileLog
)
<<
"Received tile has size in latitude direction: "
<<
carpetArray
.
count
();
return
;
for
(
int
i
=
0
;
i
<
_gridSizeLat
;
i
++
)
{
}
for
(
int
i
=
0
;
i
<
gridSize
;
i
++
)
{
const
QJsonArray
&
row
=
carpetArray
[
i
].
toArray
();
const
QJsonArray
&
row
=
carpetArray
[
i
].
toArray
();
if
(
row
.
count
()
<
gridSize
)
{
// TODO (birchera): the same as above
if
(
i
==
0
)
{
qCDebug
(
TerrainTileLog
)
<<
"Expected row array of "
<<
gridSize
<<
", instead got "
<<
row
.
count
();
_gridSizeLon
=
row
.
count
();
qCDebug
(
TerrainTileLog
)
<<
"Received tile has size in longitued direction: "
<<
row
.
count
();
if
(
_gridSizeLon
>
0
)
{
_data
=
new
float
*
[
_gridSizeLat
];
}
for
(
int
k
=
0
;
k
<
_gridSizeLat
;
k
++
)
{
_data
[
k
]
=
new
float
[
_gridSizeLon
];
}
}
if
(
row
.
count
()
<
_gridSizeLon
)
{
qCDebug
(
TerrainTileLog
)
<<
"Expected row array of "
<<
_gridSizeLon
<<
", instead got "
<<
row
.
count
();
return
;
return
;
}
}
for
(
int
j
=
0
;
j
<
gridSize
;
j
++
)
{
for
(
int
j
=
0
;
j
<
_
gridSize
Lon
;
j
++
)
{
_data
[
i
][
j
]
=
row
[
j
].
toDouble
();
_data
[
i
][
j
]
=
row
[
j
].
toDouble
();
}
}
}
}
...
@@ -141,14 +159,10 @@ float TerrainTile::elevation(const QGeoCoordinate& coordinate) const
...
@@ -141,14 +159,10 @@ float TerrainTile::elevation(const QGeoCoordinate& coordinate) const
if
(
_isValid
)
{
if
(
_isValid
)
{
qCDebug
(
TerrainTileLog
)
<<
"elevation: "
<<
coordinate
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
;
qCDebug
(
TerrainTileLog
)
<<
"elevation: "
<<
coordinate
<<
" , in sw "
<<
_southWest
<<
" , ne "
<<
_northEast
;
// Get the index at resolution of 1 arc second
// Get the index at resolution of 1 arc second
int
indexLat
=
qRound
(
static_cast
<
qreal
>
((
coordinate
.
latitude
()
-
_southWest
.
latitude
())
*
(
gridSize
-
1
)
/
QGCMapEngine
::
srtm1TileSize
));
int
indexLat
=
_latToDataIndex
(
coordinate
.
latitude
());
int
indexLon
=
qRound
(
static_cast
<
qreal
>
((
coordinate
.
longitude
()
-
_southWest
.
longitude
())
*
(
gridSize
-
1
)
/
QGCMapEngine
::
srtm1TileSize
));
int
indexLon
=
_lonToDataIndex
(
coordinate
.
longitude
());
qCDebug
(
TerrainTileLog
)
<<
"indexLat:indexLon"
<<
indexLat
<<
indexLon
;
// TODO (birchera): Move this down to the next debug output, once this is all properly working.
qCDebug
(
TerrainTileLog
)
<<
"indexLat:indexLon"
<<
indexLat
<<
indexLon
;
Q_ASSERT
(
indexLat
>=
0
);
qCDebug
(
TerrainTileLog
)
<<
"indexLat:indexLon"
<<
indexLat
<<
indexLon
<<
"elevation"
<<
_data
[
indexLat
][
indexLon
];
Q_ASSERT
(
indexLat
<
gridSize
);
Q_ASSERT
(
indexLon
>=
0
);
Q_ASSERT
(
indexLon
<
gridSize
);
qCDebug
(
TerrainTileLog
)
<<
"elevation"
<<
_data
[
indexLat
][
indexLon
];
return
_data
[
indexLat
][
indexLon
];
return
_data
[
indexLat
][
indexLon
];
}
else
{
}
else
{
qCDebug
(
TerrainTileLog
)
<<
"Asking for elevation, but no valid data."
;
qCDebug
(
TerrainTileLog
)
<<
"Asking for elevation, but no valid data."
;
...
@@ -160,3 +174,21 @@ QGeoCoordinate TerrainTile::centerCoordinate(void) const
...
@@ -160,3 +174,21 @@ QGeoCoordinate TerrainTile::centerCoordinate(void) const
{
{
return
_southWest
.
atDistanceAndAzimuth
(
_southWest
.
distanceTo
(
_northEast
)
/
2.0
,
_southWest
.
azimuthTo
(
_northEast
));
return
_southWest
.
atDistanceAndAzimuth
(
_southWest
.
distanceTo
(
_northEast
)
/
2.0
,
_southWest
.
azimuthTo
(
_northEast
));
}
}
int
TerrainTile
::
_latToDataIndex
(
double
latitude
)
const
{
if
(
isValid
()
&&
_southWest
.
isValid
()
&&
_northEast
.
isValid
())
{
return
qRound
((
latitude
-
_southWest
.
latitude
())
/
(
_northEast
.
latitude
()
-
_southWest
.
latitude
())
*
(
_gridSizeLat
-
1
));
}
else
{
return
-
1
;
}
}
int
TerrainTile
::
_lonToDataIndex
(
double
longitude
)
const
{
if
(
isValid
()
&&
_southWest
.
isValid
()
&&
_northEast
.
isValid
())
{
return
qRound
((
longitude
-
_southWest
.
longitude
())
/
(
_northEast
.
longitude
()
-
_southWest
.
longitude
())
*
(
_gridSizeLon
-
1
));
}
else
{
return
-
1
;
}
}
This diff is collapsed.
Click to expand it.
src/TerrainTile.h
+
12
−
4
View file @
6467f653
...
@@ -9,6 +9,12 @@
...
@@ -9,6 +9,12 @@
Q_DECLARE_LOGGING_CATEGORY
(
TerrainTileLog
)
Q_DECLARE_LOGGING_CATEGORY
(
TerrainTileLog
)
/**
* @brief The TerrainTile class
*
* Implements an interface for https://developers.airmap.com/v2.0/docs/elevation-api
*/
class
TerrainTile
class
TerrainTile
{
{
public:
public:
...
@@ -73,10 +79,10 @@ public:
...
@@ -73,10 +79,10 @@ public:
*/
*/
QGeoCoordinate
centerCoordinate
(
void
)
const
;
QGeoCoordinate
centerCoordinate
(
void
)
const
;
/// tile grid size in lat and lon
static
const
int
gridSize
=
TERRAIN_TILE_SIZE
;
private
:
private
:
inline
int
_latToDataIndex
(
double
latitude
)
const
;
inline
int
_lonToDataIndex
(
double
longitude
)
const
;
QGeoCoordinate
_southWest
;
/// South west corner of the tile
QGeoCoordinate
_southWest
;
/// South west corner of the tile
QGeoCoordinate
_northEast
;
/// North east corner of the tile
QGeoCoordinate
_northEast
;
/// North east corner of the tile
...
@@ -84,7 +90,9 @@ private:
...
@@ -84,7 +90,9 @@ private:
float
_maxElevation
;
/// Maximum elevation in tile
float
_maxElevation
;
/// Maximum elevation in tile
float
_avgElevation
;
/// Average elevation of the tile
float
_avgElevation
;
/// Average elevation of the tile
float
_data
[
TERRAIN_TILE_SIZE
][
TERRAIN_TILE_SIZE
];
/// elevation data
float
**
_data
;
/// 2D elevation data array
int
_gridSizeLat
;
/// data grid size in latitude direction
int
_gridSizeLon
;
/// data grid size in longitude direction
bool
_isValid
;
/// data loaded is valid
bool
_isValid
;
/// data loaded is valid
// Json keys
// Json keys
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment