Skip to content

Commit 54ea3cc

Browse files
committed
feat: copy autoware_geography_utils from autoware.universe
Signed-off-by: Ryohsuke Mitsudome <ryohsuke.mitsudome@tier4.jp>
1 parent df9cd36 commit 54ea3cc

13 files changed

+673
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Changelog for package autoware_geography_utils
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
0.38.0 (2024-11-08)
6+
-------------------
7+
* unify package.xml version to 0.37.0
8+
* refactor(geography_utils): prefix package and namespace with autoware (`#7790 <https://github.com/autowarefoundation/autoware.universe/issues/7790>`_)
9+
* refactor(geography_utils): prefix package and namespace with autoware
10+
* move headers to include/autoware/
11+
---------
12+
* Contributors: Esteve Fernandez, Yutaka Kondo
13+
14+
0.26.0 (2024-04-03)
15+
-------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(autoware_geography_utils)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
# GeographicLib
8+
find_package(PkgConfig)
9+
find_path(GeographicLib_INCLUDE_DIR GeographicLib/Config.h
10+
PATH_SUFFIXES GeographicLib
11+
)
12+
set(GeographicLib_INCLUDE_DIRS ${GeographicLib_INCLUDE_DIR})
13+
find_library(GeographicLib_LIBRARIES NAMES Geographic)
14+
15+
ament_auto_add_library(${PROJECT_NAME} SHARED
16+
src/height.cpp
17+
src/projection.cpp
18+
src/lanelet2_projector.cpp
19+
)
20+
21+
target_link_libraries(${PROJECT_NAME}
22+
${GeographicLib_LIBRARIES}
23+
)
24+
25+
if(BUILD_TESTING)
26+
find_package(ament_cmake_ros REQUIRED)
27+
28+
file(GLOB_RECURSE test_files test/*.cpp)
29+
30+
ament_add_ros_isolated_gtest(test_${PROJECT_NAME} ${test_files})
31+
32+
target_link_libraries(test_${PROJECT_NAME}
33+
${PROJECT_NAME}
34+
)
35+
endif()
36+
37+
ament_auto_package()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# geography_utils
2+
3+
## Purpose
4+
5+
This package contains geography-related functions used by other packages, so please refer to them as needed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2023 TIER IV, Inc.
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+
#ifndef AUTOWARE__GEOGRAPHY_UTILS__HEIGHT_HPP_
16+
#define AUTOWARE__GEOGRAPHY_UTILS__HEIGHT_HPP_
17+
18+
#include <string>
19+
20+
namespace autoware::geography_utils
21+
{
22+
23+
typedef double (*HeightConversionFunction)(
24+
const double height, const double latitude, const double longitude);
25+
double convert_wgs84_to_egm2008(const double height, const double latitude, const double longitude);
26+
double convert_egm2008_to_wgs84(const double height, const double latitude, const double longitude);
27+
double convert_height(
28+
const double height, const double latitude, const double longitude,
29+
const std::string & source_vertical_datum, const std::string & target_vertical_datum);
30+
31+
} // namespace autoware::geography_utils
32+
33+
#endif // AUTOWARE__GEOGRAPHY_UTILS__HEIGHT_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2023 TIER IV, Inc.
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+
#ifndef AUTOWARE__GEOGRAPHY_UTILS__LANELET2_PROJECTOR_HPP_
16+
#define AUTOWARE__GEOGRAPHY_UTILS__LANELET2_PROJECTOR_HPP_
17+
18+
#include <autoware_map_msgs/msg/map_projector_info.hpp>
19+
20+
#include <lanelet2_io/Projection.h>
21+
22+
#include <memory>
23+
24+
namespace autoware::geography_utils
25+
{
26+
using MapProjectorInfo = autoware_map_msgs::msg::MapProjectorInfo;
27+
28+
std::unique_ptr<lanelet::Projector> get_lanelet2_projector(const MapProjectorInfo & projector_info);
29+
30+
} // namespace autoware::geography_utils
31+
32+
#endif // AUTOWARE__GEOGRAPHY_UTILS__LANELET2_PROJECTOR_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2023 TIER IV, Inc.
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+
#ifndef AUTOWARE__GEOGRAPHY_UTILS__PROJECTION_HPP_
16+
#define AUTOWARE__GEOGRAPHY_UTILS__PROJECTION_HPP_
17+
18+
#include <autoware_map_msgs/msg/map_projector_info.hpp>
19+
#include <geographic_msgs/msg/geo_point.hpp>
20+
#include <geometry_msgs/msg/point.hpp>
21+
22+
namespace autoware::geography_utils
23+
{
24+
using MapProjectorInfo = autoware_map_msgs::msg::MapProjectorInfo;
25+
using GeoPoint = geographic_msgs::msg::GeoPoint;
26+
using LocalPoint = geometry_msgs::msg::Point;
27+
28+
LocalPoint project_forward(const GeoPoint & geo_point, const MapProjectorInfo & projector_info);
29+
GeoPoint project_reverse(const LocalPoint & local_point, const MapProjectorInfo & projector_info);
30+
31+
} // namespace autoware::geography_utils
32+
33+
#endif // AUTOWARE__GEOGRAPHY_UTILS__PROJECTION_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>autoware_geography_utils</name>
5+
<version>0.38.0</version>
6+
<description>The autoware_geography_utils package</description>
7+
<maintainer email="yamato.ando@tier4.jp">Yamato Ando</maintainer>
8+
<maintainer email="masahiro.sakamoto@tier4.jp">Masahiro Sakamoto</maintainer>
9+
<maintainer email="anh.nguyen.2@tier4.jp">NGUYEN Viet Anh</maintainer>
10+
<maintainer email="taiki.yamada@tier4.jp">Taiki Yamada</maintainer>
11+
<maintainer email="shintaro.sakoda@tier4.jp">Shintaro Sakoda</maintainer>
12+
<maintainer email="ryu.yamamoto@tier4.jp">Ryu Yamamoto</maintainer>
13+
<license>Apache License 2.0</license>
14+
<author email="koji.minoda@tier4.jp">Koji Minoda</author>
15+
16+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
17+
<buildtool_depend>autoware_cmake</buildtool_depend>
18+
19+
<depend>autoware_lanelet2_extension</depend>
20+
<depend>autoware_map_msgs</depend>
21+
<depend>geographic_msgs</depend>
22+
<depend>geographiclib</depend>
23+
<depend>geometry_msgs</depend>
24+
<depend>lanelet2_io</depend>
25+
26+
<test_depend>ament_cmake_ros</test_depend>
27+
<test_depend>ament_lint_auto</test_depend>
28+
<test_depend>autoware_lint_common</test_depend>
29+
30+
<export>
31+
<build_type>ament_cmake</build_type>
32+
</export>
33+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2023 TIER IV, Inc.
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 <GeographicLib/Geoid.hpp>
16+
#include <autoware/geography_utils/height.hpp>
17+
18+
#include <map>
19+
#include <stdexcept>
20+
#include <string>
21+
#include <utility>
22+
23+
namespace autoware::geography_utils
24+
{
25+
26+
double convert_wgs84_to_egm2008(const double height, const double latitude, const double longitude)
27+
{
28+
GeographicLib::Geoid egm2008("egm2008-1");
29+
// cSpell: ignore ELLIPSOIDTOGEOID
30+
return egm2008.ConvertHeight(latitude, longitude, height, GeographicLib::Geoid::ELLIPSOIDTOGEOID);
31+
}
32+
33+
double convert_egm2008_to_wgs84(const double height, const double latitude, const double longitude)
34+
{
35+
GeographicLib::Geoid egm2008("egm2008-1");
36+
// cSpell: ignore GEOIDTOELLIPSOID
37+
return egm2008.ConvertHeight(latitude, longitude, height, GeographicLib::Geoid::GEOIDTOELLIPSOID);
38+
}
39+
40+
double convert_height(
41+
const double height, const double latitude, const double longitude,
42+
const std::string & source_vertical_datum, const std::string & target_vertical_datum)
43+
{
44+
if (source_vertical_datum == target_vertical_datum) {
45+
return height;
46+
}
47+
std::map<std::pair<std::string, std::string>, HeightConversionFunction> conversion_map;
48+
conversion_map[{"WGS84", "EGM2008"}] = convert_wgs84_to_egm2008;
49+
conversion_map[{"EGM2008", "WGS84"}] = convert_egm2008_to_wgs84;
50+
51+
auto key = std::make_pair(source_vertical_datum, target_vertical_datum);
52+
if (conversion_map.find(key) != conversion_map.end()) {
53+
return conversion_map[key](height, latitude, longitude);
54+
} else {
55+
std::string error_message =
56+
"Invalid conversion types: " + std::string(source_vertical_datum.c_str()) + " to " +
57+
std::string(target_vertical_datum.c_str());
58+
59+
throw std::invalid_argument(error_message);
60+
}
61+
}
62+
63+
} // namespace autoware::geography_utils
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2023 TIER IV, Inc.
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 <GeographicLib/Geoid.hpp>
16+
#include <autoware/geography_utils/lanelet2_projector.hpp>
17+
#include <autoware_lanelet2_extension/projection/mgrs_projector.hpp>
18+
#include <autoware_lanelet2_extension/projection/transverse_mercator_projector.hpp>
19+
20+
#include <lanelet2_projection/UTM.h>
21+
22+
namespace autoware::geography_utils
23+
{
24+
25+
std::unique_ptr<lanelet::Projector> get_lanelet2_projector(const MapProjectorInfo & projector_info)
26+
{
27+
if (projector_info.projector_type == MapProjectorInfo::LOCAL_CARTESIAN_UTM) {
28+
lanelet::GPSPoint position{
29+
projector_info.map_origin.latitude, projector_info.map_origin.longitude,
30+
projector_info.map_origin.altitude};
31+
lanelet::Origin origin{position};
32+
lanelet::projection::UtmProjector projector{origin};
33+
return std::make_unique<lanelet::projection::UtmProjector>(projector);
34+
35+
} else if (projector_info.projector_type == MapProjectorInfo::MGRS) {
36+
lanelet::projection::MGRSProjector projector{};
37+
projector.setMGRSCode(projector_info.mgrs_grid);
38+
return std::make_unique<lanelet::projection::MGRSProjector>(projector);
39+
40+
} else if (projector_info.projector_type == MapProjectorInfo::TRANSVERSE_MERCATOR) {
41+
lanelet::GPSPoint position{
42+
projector_info.map_origin.latitude, projector_info.map_origin.longitude,
43+
projector_info.map_origin.altitude};
44+
lanelet::Origin origin{position};
45+
lanelet::projection::TransverseMercatorProjector projector{origin};
46+
return std::make_unique<lanelet::projection::TransverseMercatorProjector>(projector);
47+
}
48+
const std::string error_msg =
49+
"Invalid map projector type: " + projector_info.projector_type +
50+
". Currently supported types: MGRS, LocalCartesianUTM, and TransverseMercator";
51+
throw std::invalid_argument(error_msg);
52+
}
53+
54+
} // namespace autoware::geography_utils

0 commit comments

Comments
 (0)