|
| 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 <autoware/geography_utils/projection.hpp> |
| 16 | + |
| 17 | +#include <gtest/gtest.h> |
| 18 | + |
| 19 | +#include <stdexcept> |
| 20 | +#include <string> |
| 21 | + |
| 22 | +TEST(GeographyUtilsProjection, ProjectForwardToMGRS) |
| 23 | +{ |
| 24 | + // source point |
| 25 | + geographic_msgs::msg::GeoPoint geo_point; |
| 26 | + geo_point.latitude = 35.62426; |
| 27 | + geo_point.longitude = 139.74252; |
| 28 | + geo_point.altitude = 10.0; |
| 29 | + |
| 30 | + // target point |
| 31 | + geometry_msgs::msg::Point local_point; |
| 32 | + local_point.x = 86128.0; |
| 33 | + local_point.y = 43002.0; |
| 34 | + local_point.z = 10.0; |
| 35 | + |
| 36 | + // projector info |
| 37 | + autoware_map_msgs::msg::MapProjectorInfo projector_info; |
| 38 | + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::MGRS; |
| 39 | + projector_info.mgrs_grid = "54SUE"; |
| 40 | + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; |
| 41 | + |
| 42 | + // conversion |
| 43 | + const geometry_msgs::msg::Point converted_point = |
| 44 | + autoware::geography_utils::project_forward(geo_point, projector_info); |
| 45 | + |
| 46 | + EXPECT_NEAR(converted_point.x, local_point.x, 1.0); |
| 47 | + EXPECT_NEAR(converted_point.y, local_point.y, 1.0); |
| 48 | + EXPECT_NEAR(converted_point.z, local_point.z, 1.0); |
| 49 | +} |
| 50 | + |
| 51 | +TEST(GeographyUtilsProjection, ProjectReverseFromMGRS) |
| 52 | +{ |
| 53 | + // source point |
| 54 | + geometry_msgs::msg::Point local_point; |
| 55 | + local_point.x = 86128.0; |
| 56 | + local_point.y = 43002.0; |
| 57 | + local_point.z = 10.0; |
| 58 | + |
| 59 | + // target point |
| 60 | + geographic_msgs::msg::GeoPoint geo_point; |
| 61 | + geo_point.latitude = 35.62426; |
| 62 | + geo_point.longitude = 139.74252; |
| 63 | + geo_point.altitude = 10.0; |
| 64 | + |
| 65 | + // projector info |
| 66 | + autoware_map_msgs::msg::MapProjectorInfo projector_info; |
| 67 | + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::MGRS; |
| 68 | + projector_info.mgrs_grid = "54SUE"; |
| 69 | + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; |
| 70 | + |
| 71 | + // conversion |
| 72 | + const geographic_msgs::msg::GeoPoint converted_point = |
| 73 | + autoware::geography_utils::project_reverse(local_point, projector_info); |
| 74 | + |
| 75 | + EXPECT_NEAR(converted_point.latitude, geo_point.latitude, 0.0001); |
| 76 | + EXPECT_NEAR(converted_point.longitude, geo_point.longitude, 0.0001); |
| 77 | + EXPECT_NEAR(converted_point.altitude, geo_point.altitude, 0.0001); |
| 78 | +} |
| 79 | + |
| 80 | +TEST(GeographyUtilsProjection, ProjectForwardAndReverseMGRS) |
| 81 | +{ |
| 82 | + // source point |
| 83 | + geographic_msgs::msg::GeoPoint geo_point; |
| 84 | + geo_point.latitude = 35.62426; |
| 85 | + geo_point.longitude = 139.74252; |
| 86 | + geo_point.altitude = 10.0; |
| 87 | + |
| 88 | + // projector info |
| 89 | + autoware_map_msgs::msg::MapProjectorInfo projector_info; |
| 90 | + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::MGRS; |
| 91 | + projector_info.mgrs_grid = "54SUE"; |
| 92 | + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; |
| 93 | + |
| 94 | + // conversion |
| 95 | + const geometry_msgs::msg::Point converted_local_point = |
| 96 | + autoware::geography_utils::project_forward(geo_point, projector_info); |
| 97 | + const geographic_msgs::msg::GeoPoint converted_geo_point = |
| 98 | + autoware::geography_utils::project_reverse(converted_local_point, projector_info); |
| 99 | + |
| 100 | + EXPECT_NEAR(converted_geo_point.latitude, geo_point.latitude, 0.0001); |
| 101 | + EXPECT_NEAR(converted_geo_point.longitude, geo_point.longitude, 0.0001); |
| 102 | + EXPECT_NEAR(converted_geo_point.altitude, geo_point.altitude, 0.0001); |
| 103 | +} |
| 104 | + |
| 105 | +TEST(GeographyUtilsProjection, ProjectForwardToLocalCartesianUTMOrigin) |
| 106 | +{ |
| 107 | + // source point |
| 108 | + geographic_msgs::msg::GeoPoint geo_point; |
| 109 | + geo_point.latitude = 35.62406; |
| 110 | + geo_point.longitude = 139.74252; |
| 111 | + geo_point.altitude = 10.0; |
| 112 | + |
| 113 | + // target point |
| 114 | + geometry_msgs::msg::Point local_point; |
| 115 | + local_point.x = 0.0; |
| 116 | + local_point.y = -22.18; |
| 117 | + local_point.z = 20.0; |
| 118 | + |
| 119 | + // projector info |
| 120 | + autoware_map_msgs::msg::MapProjectorInfo projector_info; |
| 121 | + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::LOCAL_CARTESIAN_UTM; |
| 122 | + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; |
| 123 | + projector_info.map_origin.latitude = 35.62426; |
| 124 | + projector_info.map_origin.longitude = 139.74252; |
| 125 | + projector_info.map_origin.altitude = -10.0; |
| 126 | + |
| 127 | + // conversion |
| 128 | + const geometry_msgs::msg::Point converted_point = |
| 129 | + autoware::geography_utils::project_forward(geo_point, projector_info); |
| 130 | + |
| 131 | + EXPECT_NEAR(converted_point.x, local_point.x, 1.0); |
| 132 | + EXPECT_NEAR(converted_point.y, local_point.y, 1.0); |
| 133 | + EXPECT_NEAR(converted_point.z, local_point.z, 1.0); |
| 134 | +} |
| 135 | + |
| 136 | +TEST(GeographyUtilsProjection, ProjectForwardAndReverseLocalCartesianUTMOrigin) |
| 137 | +{ |
| 138 | + // source point |
| 139 | + geographic_msgs::msg::GeoPoint geo_point; |
| 140 | + geo_point.latitude = 35.62426; |
| 141 | + geo_point.longitude = 139.74252; |
| 142 | + geo_point.altitude = 10.0; |
| 143 | + |
| 144 | + // projector info |
| 145 | + autoware_map_msgs::msg::MapProjectorInfo projector_info; |
| 146 | + projector_info.projector_type = autoware_map_msgs::msg::MapProjectorInfo::LOCAL_CARTESIAN_UTM; |
| 147 | + projector_info.vertical_datum = autoware_map_msgs::msg::MapProjectorInfo::WGS84; |
| 148 | + projector_info.map_origin.latitude = 35.0; |
| 149 | + projector_info.map_origin.longitude = 139.0; |
| 150 | + projector_info.map_origin.altitude = 0.0; |
| 151 | + |
| 152 | + // conversion |
| 153 | + const geometry_msgs::msg::Point converted_local_point = |
| 154 | + autoware::geography_utils::project_forward(geo_point, projector_info); |
| 155 | + const geographic_msgs::msg::GeoPoint converted_geo_point = |
| 156 | + autoware::geography_utils::project_reverse(converted_local_point, projector_info); |
| 157 | + |
| 158 | + EXPECT_NEAR(converted_geo_point.latitude, geo_point.latitude, 0.0001); |
| 159 | + EXPECT_NEAR(converted_geo_point.longitude, geo_point.longitude, 0.0001); |
| 160 | + EXPECT_NEAR(converted_geo_point.altitude, geo_point.altitude, 0.0001); |
| 161 | +} |
0 commit comments