Apollo
10.0
自动驾驶开放平台
coordinate_convert_tool.cc
浏览该文件的文档.
1
/* Copyright 2017 The Apollo Authors. All Rights Reserved.
2
3
Licensed under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License.
5
You may obtain a copy of the License at
6
7
http://www.apache.org/licenses/LICENSE-2.0
8
9
Unless required by applicable law or agreed to in writing, software
10
distributed under the License is distributed on an "AS IS" BASIS,
11
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
See the License for the specific language governing permissions and
13
limitations under the License.
14
=========================================================================*/
15
#include "
modules/map/hdmap/adapter/xml_parser/coordinate_convert_tool.h
"
16
17
#include "glog/logging.h"
18
19
namespace
apollo
{
20
namespace
hdmap {
21
namespace
adapter {
22
23
CoordinateConvertTool::CoordinateConvertTool
()
24
: pj_from_(nullptr), pj_to_(nullptr) {}
25
26
CoordinateConvertTool::~CoordinateConvertTool
() {
27
if
(pj_from_) {
28
pj_free(pj_from_);
29
pj_from_ =
nullptr
;
30
}
31
32
if
(pj_to_) {
33
pj_free(pj_to_);
34
pj_to_ =
nullptr
;
35
}
36
}
37
38
CoordinateConvertTool
*
CoordinateConvertTool::GetInstance
() {
39
static
CoordinateConvertTool
instance;
40
return
&instance;
41
}
42
43
Status
CoordinateConvertTool::SetConvertParam
(
const
std::string& source_param,
44
const
std::string& dst_param) {
45
source_convert_param_ = source_param;
46
dst_convert_param_ = dst_param;
47
if
(pj_from_) {
48
pj_free(pj_from_);
49
pj_from_ =
nullptr
;
50
}
51
52
if
(pj_to_) {
53
pj_free(pj_to_);
54
pj_to_ =
nullptr
;
55
}
56
57
if
(!(pj_from_ = pj_init_plus(source_convert_param_.c_str()))) {
58
std::string err_msg =
"Fail to pj_init_plus "
+ source_convert_param_;
59
return
Status
(
apollo::common::ErrorCode::HDMAP_DATA_ERROR
, err_msg);
60
}
61
62
if
(!(pj_to_ = pj_init_plus(dst_convert_param_.c_str()))) {
63
std::string err_msg =
"Fail to pj_init_plus "
+ dst_convert_param_;
64
pj_free(pj_from_);
65
pj_from_ =
nullptr
;
66
return
Status
(
apollo::common::ErrorCode::HDMAP_DATA_ERROR
, err_msg);
67
}
68
69
return
Status::OK
();
70
}
71
72
Status
CoordinateConvertTool::CoordiateConvert
(
const
double
longitude,
73
const
double
latitude,
74
const
double
height_ellipsoid,
75
double
* utm_x,
double
* utm_y,
76
double
* utm_z) {
77
CHECK_NOTNULL(utm_x);
78
CHECK_NOTNULL(utm_y);
79
CHECK_NOTNULL(utm_z);
80
if
(!pj_from_ || !pj_to_) {
81
std::string err_msg =
"no transform param"
;
82
return
Status
(
apollo::common::ErrorCode::HDMAP_DATA_ERROR
, err_msg);
83
}
84
85
double
gps_longitude = longitude;
86
double
gps_latitude = latitude;
87
double
gps_alt = height_ellipsoid;
88
89
if
(pj_is_latlong(pj_from_)) {
90
gps_longitude *=
DEG_TO_RAD
;
91
gps_latitude *=
DEG_TO_RAD
;
92
gps_alt = height_ellipsoid;
93
}
94
95
if
(0 != pj_transform(pj_from_, pj_to_, 1, 1, &gps_longitude, &gps_latitude,
96
&gps_alt)) {
97
std::string err_msg =
"fail to transform coordinate"
;
98
return
Status
(
apollo::common::ErrorCode::HDMAP_DATA_ERROR
, err_msg);
99
}
100
101
if
(pj_is_latlong(pj_to_)) {
102
gps_longitude *=
RAD_TO_DEG
;
103
gps_latitude *=
RAD_TO_DEG
;
104
}
105
106
*utm_x = gps_longitude;
107
*utm_y = gps_latitude;
108
*utm_z = gps_alt;
109
110
return
Status::OK
();
111
}
112
113
}
// namespace adapter
114
}
// namespace hdmap
115
}
// namespace apollo
apollo::common::Status
A general class to denote the return status of an API call.
Definition
status.h:43
apollo::common::Status::OK
static Status OK()
generate a success status.
Definition
status.h:60
apollo::hdmap::adapter::CoordinateConvertTool
Definition
coordinate_convert_tool.h:28
apollo::hdmap::adapter::CoordinateConvertTool::SetConvertParam
Status SetConvertParam(const std::string &source_param, const std::string &dst_param)
Definition
coordinate_convert_tool.cc:43
apollo::hdmap::adapter::CoordinateConvertTool::GetInstance
static CoordinateConvertTool * GetInstance()
Definition
coordinate_convert_tool.cc:38
apollo::hdmap::adapter::CoordinateConvertTool::CoordinateConvertTool
CoordinateConvertTool()
Definition
coordinate_convert_tool.cc:23
apollo::hdmap::adapter::CoordinateConvertTool::CoordiateConvert
Status CoordiateConvert(const double longitude, const double latitude, const double height_ellipsoid, double *utm_x, double *utm_y, double *utm_z)
Definition
coordinate_convert_tool.cc:72
apollo::hdmap::adapter::CoordinateConvertTool::~CoordinateConvertTool
~CoordinateConvertTool()
Definition
coordinate_convert_tool.cc:26
coordinate_convert_tool.h
DEG_TO_RAD
#define DEG_TO_RAD
Definition
lslidar_parser.h:65
RAD_TO_DEG
#define RAD_TO_DEG
Definition
lslidar_parser.h:66
apollo::common::HDMAP_DATA_ERROR
@ HDMAP_DATA_ERROR
Definition
error_code.proto:48
apollo
class register implement
Definition
arena_queue.h:37
modules
map
hdmap
adapter
xml_parser
coordinate_convert_tool.cc