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
36748f71
Commit
36748f71
authored
Nov 10, 2019
by
Matej Frančeškin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added MGRS coordinate conversion methods
parent
57962f3a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
16 deletions
+80
-16
QGCGeo.cc
src/Geo/QGCGeo.cc
+53
-11
QGCGeo.h
src/Geo/QGCGeo.h
+26
-2
SHPFileHelper.cc
src/SHPFileHelper.cc
+1
-3
No files found.
src/Geo/QGCGeo.cc
View file @
36748f71
...
...
@@ -8,23 +8,19 @@
****************************************************************************/
#include <QDebug>
#include <QString>
#include <cmath>
#include <limits>
#include "QGCGeo.h"
#include "UTMUPS.hpp"
#include "MGRS.hpp"
// These defines are private
#define M_DEG_TO_RAD (M_PI / 180.0)
#define M_RAD_TO_DEG (180.0 / M_PI)
#define CONSTANTS_ONE_G 9.80665f
/* m/s^2 */
#define CONSTANTS_AIR_DENSITY_SEA_LEVEL_15C 1.225f
/* kg/m^3 */
#define CONSTANTS_AIR_GAS_CONST 287.1f
/* J/(kg * K) */
#define CONSTANTS_ABSOLUTE_NULL_CELSIUS -273.15f
/* °C */
#define CONSTANTS_RADIUS_OF_EARTH 6371000
/* meters (m) */
#define CONSTANTS_RADIUS_OF_EARTH 6371000 // meters (m)
static
const
double
epsilon
=
std
::
numeric_limits
<
double
>::
epsilon
();
...
...
@@ -90,17 +86,63 @@ void convertNedToGeo(double x, double y, double z, QGeoCoordinate origin, QGeoCo
}
int
convertGeoToUTM
(
const
QGeoCoordinate
&
coord
,
double
&
easting
,
double
&
northing
)
{
try
{
int
zone
;
bool
northp
;
GeographicLib
::
UTMUPS
::
Forward
(
coord
.
latitude
(),
coord
.
longitude
(),
zone
,
northp
,
easting
,
northing
);
return
zone
;
}
catch
(...)
{
return
0
;
}
}
bool
convertUTMToGeo
(
double
easting
,
double
northing
,
int
zone
,
bool
southhemi
,
QGeoCoordinate
&
coord
)
{
double
lat
,
lon
;
try
{
GeographicLib
::
UTMUPS
::
Reverse
(
zone
,
!
southhemi
,
easting
,
northing
,
lat
,
lon
);
}
catch
(...)
{
return
false
;
}
coord
.
setLatitude
(
lat
);
coord
.
setLongitude
(
lon
);
return
true
;
}
QString
convertGeoToMGRS
(
const
QGeoCoordinate
&
coord
)
{
int
zone
;
bool
northp
;
GeographicLib
::
UTMUPS
::
Forward
(
coord
.
latitude
(),
coord
.
longitude
(),
zone
,
northp
,
easting
,
northing
);
return
zone
;
double
x
,
y
;
std
::
string
mgrs
;
try
{
GeographicLib
::
UTMUPS
::
Forward
(
coord
.
latitude
(),
coord
.
longitude
(),
zone
,
northp
,
x
,
y
);
GeographicLib
::
MGRS
::
Forward
(
zone
,
northp
,
x
,
y
,
coord
.
latitude
(),
5
,
mgrs
);
}
catch
(...)
{
mgrs
=
""
;
}
return
QString
::
fromStdString
(
mgrs
);
}
void
convertUTMToGeo
(
double
easting
,
double
northing
,
int
zone
,
bool
southhemi
,
QGeoCoordinate
&
coord
)
bool
convertMGRSToGeo
(
QString
mgrs
,
QGeoCoordinate
&
coord
)
{
int
zone
,
prec
;
bool
northp
;
double
x
,
y
;
double
lat
,
lon
;
GeographicLib
::
UTMUPS
::
Reverse
(
zone
,
!
southhemi
,
easting
,
northing
,
lat
,
lon
);
try
{
GeographicLib
::
MGRS
::
Reverse
(
mgrs
.
simplified
().
replace
(
" "
,
""
).
toStdString
(),
zone
,
northp
,
x
,
y
,
prec
);
GeographicLib
::
UTMUPS
::
Reverse
(
zone
,
northp
,
x
,
y
,
lat
,
lon
);
}
catch
(...)
{
return
false
;
}
coord
.
setLatitude
(
lat
);
coord
.
setLongitude
(
lon
);
return
true
;
}
src/Geo/QGCGeo.h
View file @
36748f71
...
...
@@ -58,6 +58,7 @@ void convertNedToGeo(double x, double y, double z, QGeoCoordinate origin, QGeoCo
//
// Returns:
// The UTM zone used for calculating the values of x and y.
// If conversion failed the function returns 0
int
convertGeoToUTM
(
const
QGeoCoordinate
&
coord
,
double
&
easting
,
double
&
northing
);
// UTMXYToLatLon
...
...
@@ -78,7 +79,30 @@ int convertGeoToUTM(const QGeoCoordinate& coord, double& easting, double& northi
// lon - The longitude of the point, in radians.
//
// Returns:
// The function does not return a value.
void
convertUTMToGeo
(
double
easting
,
double
northing
,
int
zone
,
bool
southhemi
,
QGeoCoordinate
&
coord
);
// The function returns true if conversion succeeded.
bool
convertUTMToGeo
(
double
easting
,
double
northing
,
int
zone
,
bool
southhemi
,
QGeoCoordinate
&
coord
);
// Converts a latitude/longitude pair to MGRS string
//
// Inputs:
// coord - Latitude, Longiture coordinate
//
// Returns:
// The MGRS coordinate string
// If conversion fails the function returns empty string
QString
convertGeoToMGRS
(
const
QGeoCoordinate
&
coord
);
// Converts MGRS string to a latitude/longitude pair.
//
// Inputs:
// mgrs - MGRS coordinate string
//
// Outputs:
// lat - The latitude of the point, in radians.
// lon - The longitude of the point, in radians.
//
// Returns:
// The function returns true if conversion succeeded.
bool
convertMGRSToGeo
(
QString
mgrs
,
QGeoCoordinate
&
coord
);
#endif // QGCGEO_H
src/SHPFileHelper.cc
View file @
36748f71
...
...
@@ -142,9 +142,7 @@ bool SHPFileHelper::loadPolygonFromFile(const QString& shpFile, QList<QGeoCoordi
for
(
int
i
=
0
;
i
<
shpObject
->
nVertices
;
i
++
)
{
QGeoCoordinate
coord
;
if
(
utmZone
)
{
convertUTMToGeo
(
shpObject
->
padfX
[
i
],
shpObject
->
padfY
[
i
],
utmZone
,
utmSouthernHemisphere
,
coord
);
}
else
{
if
(
!
utmZone
||
!
convertUTMToGeo
(
shpObject
->
padfX
[
i
],
shpObject
->
padfY
[
i
],
utmZone
,
utmSouthernHemisphere
,
coord
))
{
coord
.
setLatitude
(
shpObject
->
padfY
[
i
]);
coord
.
setLongitude
(
shpObject
->
padfX
[
i
]);
}
...
...
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