Skip to content

Commit 2f3cd4b

Browse files
committed
unordered mapに変更
1 parent 8df6520 commit 2f3cd4b

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

include/plateau/geometry/geo_coordinate.h

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "citygml/vecs.hpp"
44
#include "citygml/cityobject.h"
55
#include <array>
6-
#include <set>
6+
#include <unordered_map>
77
#include <utility>
88

99
namespace plateau::geometry {
@@ -109,65 +109,53 @@ namespace plateau::geometry {
109109
}
110110
};
111111

112-
/**
113-
* 平面直角座標系の判定、平面直角座標の基準点取得
114-
*/
112+
/**
113+
* 平面直角座標系の判定、平面直角座標の基準点取得
114+
*/
115115
struct CoordinateReferenceFactory {
116116
static constexpr int default_epsg = 6697;
117-
118117
// EPSGとZone IDのマッピング
119-
static const std::set<std::pair<int, int>> epsg_to_zone;
120-
118+
static const std::unordered_map<int, int> epsg_to_zone;
121119
// Zone IDごとの座標データ
122-
static const std::set<std::pair<int, std::array<double, 3>>> zone_to_point;
123-
120+
static const std::unordered_map<int, std::array<double, 3>> zone_to_point;
124121
// EPSGごとのzone取得
125-
static const int GetZoneId(int epsg) {
126-
for (const auto& pair : epsg_to_zone) {
127-
if (pair.first == epsg) {
128-
return pair.second;
129-
}
122+
static int GetZoneId(int epsg) {
123+
auto it = epsg_to_zone.find(epsg);
124+
if (it != epsg_to_zone.end()) {
125+
return it->second;
130126
}
131127
return 0;
132128
}
133-
134129
// EPSGごとの基準点取得
135130
static GeoCoordinate GetOriginPoint(int epsg) {
136131
const int zone = GetZoneId(epsg);
137132
if (zone != 0) {
138-
for (const auto& pair : zone_to_point) {
139-
if (pair.first == zone) {
140-
const auto& coords = pair.second;
141-
return GeoCoordinate(coords[0], coords[1], coords[2]);
142-
}
133+
auto it = zone_to_point.find(zone);
134+
if (it != zone_to_point.end()) {
135+
const auto& coords = it->second;
136+
return GeoCoordinate(coords[0], coords[1], coords[2]);
143137
}
144138
}
145139
return GeoCoordinate();
146140
}
147-
148141
// 極座標系・平面直角座標系判定
149-
// 平面直角座標系の区分についてはこちらを参照してください :
150-
// https://www.mlit.go.jp/plateaudocument/toc9/toc9_08/toc9_08_04/
151-
// “該当範囲でなければ極座標” と単純化していますが、
152-
// EPSG 4301(JGD2000) 等の別 CRS を誤って極座標と判定する恐れがあります。
153142
static bool IsPolarCoordinateSystem(int epsg) {
154-
return !(epsg >= 10162 && epsg <= 10174);
143+
// 平面直角座標系(EPSG 10162~10174)かどうかを明示的に確認
144+
return epsg_to_zone.find(epsg) == epsg_to_zone.end();
155145
}
156146
};
157-
158147
// EPSGとZone IDのマッピング
159-
inline const std::set<std::pair<int, int>> CoordinateReferenceFactory::epsg_to_zone = {
148+
inline const std::unordered_map<int, int> CoordinateReferenceFactory::epsg_to_zone = {
160149
{10162, 1}, {10163, 2}, {10164, 3}, {10165, 4}, {10166, 5},
161150
{10167, 6}, {10168, 7}, {10169, 8}, {10170, 9}, {10171, 10},
162151
{10172, 11}, {10173, 12}, {10174, 13}
163152
};
164-
165153
// Zone IDごとの座標データ
166-
inline const std::set<std::pair<int, std::array<double, 3>>> CoordinateReferenceFactory::zone_to_point = {
167-
{1, {33.0, 129.5, 0.0}}, {2, {33.0, 131.0, 0.0}}, {3, {36.0, 132.166667, 0.0}},
168-
{4, {33.0, 133.5, 0.0}}, {5, {36.0, 134.333333, 0.0}}, {6, {36.0, 136.0, 0.0}},
169-
{7, {36.0, 137.166667, 0.0}}, {8, {36.0, 138.5, 0.0}}, {9, {35.0, 139.833333, 0.0}},
170-
{10, {40.0, 140.833333, 0.0}}, {11, {44.0, 140.25, 0.0}}, {12, {44.0, 142.0, 0.0}},
154+
inline const std::unordered_map<int, std::array<double, 3>> CoordinateReferenceFactory::zone_to_point = {
155+
{1, {33.0, 129.5, 0.0}}, {2, {33.0, 131.0, 0.0}}, {3, {36.0, 132.166667, 0.0}},
156+
{4, {33.0, 133.5, 0.0}}, {5, {36.0, 134.333333, 0.0}}, {6, {36.0, 136.0, 0.0}},
157+
{7, {36.0, 137.166667, 0.0}}, {8, {36.0, 138.5, 0.0}}, {9, {35.0, 139.833333, 0.0}},
158+
{10, {40.0, 140.833333, 0.0}}, {11, {44.0, 140.25, 0.0}}, {12, {44.0, 142.0, 0.0}},
171159
{13, {43.0, 144.0, 0.0}}
172160
};
173161
}

0 commit comments

Comments
 (0)