Skip to content

Commit 973ba4a

Browse files
committed
unproject test用
1 parent 5499628 commit 973ba4a

File tree

10 files changed

+199
-14
lines changed

10 files changed

+199
-14
lines changed

include/plateau/geometry/geo_coordinate.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace plateau::geometry {
3737
GeoCoordinate operator/(GeoCoordinate op) const;
3838
};
3939

40-
4140
/**
4241
* @enum CoordinateSystem
4342
*
@@ -99,4 +98,48 @@ namespace plateau::geometry {
9998
};
10099
}
101100
};
101+
102+
struct ReferencePointFactory {
103+
// EPSGごとの基準点取得
104+
static void GetReferencePoint(double epsg, GeoCoordinate& point) {
105+
// EPSG:10169は、日本測地系2011(JGD2011)に基づく平面直角座標系第VIII系を指します。この座標系の基準点は、緯度36度、経度138.5度に設定されています。
106+
if (epsg == 10169) {
107+
point = GeoCoordinate(36, 138.5, 0);
108+
return;
109+
}
110+
else if (epsg == 10162) {
111+
point = GeoCoordinate(33, 129.5, 0);
112+
return;
113+
}
114+
else if (epsg == 10163) {
115+
point = GeoCoordinate(33, 131, 0);
116+
return;
117+
}
118+
point = GeoCoordinate();
119+
}
120+
121+
static GeoCoordinate GetReferencePoint(double epsg) {
122+
// EPSG:10169は、日本測地系2011(JGD2011)に基づく平面直角座標系第VIII系を指します。この座標系の基準点は、緯度36度、経度138.5度に設定されています。
123+
if (epsg == 10169) {
124+
return GeoCoordinate(36, 138.5, 0);
125+
}
126+
else if (epsg == 10162) {
127+
return GeoCoordinate(33, 129.5, 0);
128+
}
129+
else if (epsg == 10163) {
130+
return GeoCoordinate(33, 131, 0);
131+
}
132+
return GeoCoordinate();
133+
}
134+
135+
// 極座標系・平面直角座標系判定
136+
static bool IsPolarCoordinateSystem(double epsg) {
137+
// 平面直角座標系の区分についてはこちらを参照してください :
138+
// https://www.mlit.go.jp/plateaudocument/toc9/toc9_08/toc9_08_04/
139+
if (epsg >= 10162 && epsg <= 10174) {
140+
return false;
141+
}
142+
return true;
143+
}
144+
};
102145
}

include/plateau/geometry/geo_reference.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace plateau::geometry {
2727
TVec3d projectWithoutAxisConvert(const TVec3d& lat_lon) const;
2828
TVec3d convertAxisToENU(const TVec3d& vertex) const;
2929
TVec3d convert(const TVec3d& lat_lon, const bool convert_axis = true, const bool project = true) const;
30+
TVec3d convert(const TVec3d& lat_lon, const bool convert_axis = true, const double epsg = 6697) const;
3031
static TVec3d convertAxisFromENUTo(CoordinateSystem axis, const TVec3d& vertex);
3132
static TVec3d convertAxisToENU(CoordinateSystem axis, const TVec3d& vertex);
3233

@@ -38,6 +39,7 @@ namespace plateau::geometry {
3839
void setZoneID(int value);
3940
float getUnitScale() const;
4041
CoordinateSystem getCoordinateSystem() const;
42+
TVec3d getOffset(const double epsg) const;
4143

4244
private:
4345
TVec3d reference_point_;

include/plateau/polygon_mesh/mesh_extract_options.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ namespace plateau::polygonMesh {
3838
attach_map_tile(true),
3939
map_tile_zoom_level(15),
4040
map_tile_url("https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{z}/{x}/{y}.jpg"),
41-
is_polar_coordinate_system(true)
41+
is_polar_coordinate_system(true),
42+
epsg_code(6697)
4243
{}
4344

4445
public:
@@ -117,5 +118,10 @@ namespace plateau::polygonMesh {
117118
* 極座標系か、平面直角座標系かを指定します。
118119
*/
119120
bool is_polar_coordinate_system;
121+
122+
/**
123+
* 平面直角座標系は、EPSGコードに応じて基準点を取得します。
124+
*/
125+
double epsg_code;
120126
};
121127
}

include/plateau/polygon_mesh/polygon_mesh_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace plateau::polygonMesh {
3737
*/
3838
static TVec3d cityObjPos(const citygml::CityObject& city_obj);
3939

40+
//static TVec3d cityObjPos(const citygml::CityObject& city_obj, const double epsg, int coordinate_zone_id);
41+
4042
/**
4143
* cityObjのポリゴンであり、頂点数が1以上であるものを検索します。
4244
* 最初に見つかったポリゴンを返します。なければ nullptr を返します。

src/geometry/geo_reference.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@ namespace plateau::geometry {
4141
return converted_point;
4242
}
4343

44+
TVec3d GeoReference::convert(const TVec3d& lat_lon, const bool convert_axis, const double epsg) const {
45+
//平面直角座標変換、座標軸変換をフラグに応じてスキップします。
46+
TVec3d point = lat_lon;
47+
48+
// 極座標系・平面直角座標系判定
49+
const bool project = ReferencePointFactory::IsPolarCoordinateSystem(epsg);
50+
// 平面直角座標系に変換
51+
if (project) {
52+
PolarToPlaneCartesian().project(point, zone_id_);
53+
if (!convert_axis) {
54+
// 座標軸変換をしない場合
55+
TVec3 converted_point = point / unit_scale_ - convertAxisToENU(coordinate_system_, reference_point_);
56+
return converted_point;
57+
}
58+
// 座標軸変換をする場合
59+
TVec3 converted_point = convertAxisFromENUTo(coordinate_system_, point);
60+
converted_point = converted_point / unit_scale_ - reference_point_;
61+
return converted_point;
62+
}
63+
64+
// 平面直角座標系の場合基準座標値をオフセット
65+
//GeoCoordinate ref_point;
66+
//ReferencePointFactory::GetReferencePoint(epsg, ref_point);
67+
//plateau::geometry::GeoReference geo_ref(zone_id_);
68+
//const auto& offset = geo_ref.project(ref_point);
69+
const auto& offset = getOffset(epsg);
70+
return point + offset;
71+
}
72+
73+
TVec3d GeoReference::getOffset(const double epsg) const {
74+
GeoCoordinate ref_point = ReferencePointFactory::GetReferencePoint(epsg);
75+
plateau::geometry::GeoReference geo_ref(zone_id_);
76+
return geo_ref.project(ref_point);
77+
}
78+
4479
TVec3d GeoReference::convertAxisToENU(const TVec3d& vertex) const {
4580
return convertAxisToENU(getCoordinateSystem(), vertex);
4681
}

src/polygon_mesh/area_mesh_factory.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,25 @@ namespace {
2424
if (!options.is_polar_coordinate_system) {
2525
// 平面直角座標系の判定
2626
plateau::geometry::GeoReference geo_ref(options.coordinate_zone_id, options.reference_point, options.unit_scale, options.mesh_axes);
27+
//plateau::geometry::GeoReference geo_ref(options.coordinate_zone_id);
2728
try {
2829
auto pos = PolygonMeshUtils::cityObjPos(city_obj);
29-
if (extent.contains(geo_ref.unproject(pos)))
30+
const auto unprojected = geo_ref.unproject(pos);
31+
if (extent.contains(unprojected))
3032
return false;
3133
}
3234
catch (std::invalid_argument& e) {}
33-
}
3435

35-
if (extent.contains(city_obj))
36-
return false;
36+
//Temp Debug =======================
37+
38+
//return false;
39+
40+
//Temp Debug =======================
41+
}
42+
else {
43+
if (extent.contains(city_obj))
44+
return false;
45+
}
3746
}
3847

3948
return true;

src/polygon_mesh/mesh_extractor.cpp

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,70 @@ namespace {
2828

2929
if (!options.is_polar_coordinate_system) {
3030
// 平面直角座標系の判定
31-
plateau::geometry::GeoReference geo_ref(options.coordinate_zone_id, options.reference_point, options.unit_scale, options.mesh_axes);
31+
32+
//plateau::geometry::GeoCoordinate refPoint = plateau::geometry::ReferencePointFactory::GetReferencePoint(options.epsg_code);
33+
//plateau::geometry::GeoReference geo_ref1(options.coordinate_zone_id);
34+
//const auto epsg_offset = geo_ref1.getOffset(options.epsg_code);
35+
//geo_ref1.setReferencePoint(epsg_offset);
36+
37+
plateau::geometry::GeoReference geo_ref2(options.coordinate_zone_id, options.reference_point, options.unit_scale, options.mesh_axes);
38+
const auto epsg_offset = geo_ref2.getOffset(options.epsg_code);
39+
40+
//const auto diff = options.reference_point - epsg_offset;
41+
//plateau::geometry::GeoReference geo_ref3(options.coordinate_zone_id, options.reference_point - diff , options.unit_scale, options.mesh_axes);
42+
43+
const auto meshcode_offset = GeoReference::convertAxisToENU(options.mesh_axes, options.reference_point);
44+
//const auto original_ref = geo_ref2.unproject(options.reference_point);
45+
46+
plateau::geometry::GeoReference geo_ref3(options.coordinate_zone_id, TVec3d(), options.unit_scale, options.mesh_axes);
47+
const auto original_ref = geo_ref3.unproject(options.reference_point);
48+
49+
plateau::geometry::GeoReference geo(options.coordinate_zone_id);
50+
GeoCoordinate ref_point = ReferencePointFactory::GetReferencePoint(options.epsg_code); //EPSGの基準点
51+
const auto prj = geo.project(ref_point);
52+
plateau::geometry::GeoReference geo_ref4(options.coordinate_zone_id, prj, options.unit_scale);
53+
54+
plateau::geometry::GeoReference geo2(options.coordinate_zone_id);
55+
GeoCoordinate ref_point2(37.4258, 138.7378, 0); //08EE751の中心
56+
const auto prj2 = geo2.project(ref_point2);
57+
plateau::geometry::GeoReference geo_ref5(options.coordinate_zone_id, prj2, options.unit_scale);
58+
59+
plateau::geometry::GeoReference geo3(options.coordinate_zone_id);
60+
GeoCoordinate ref_point3(36, 138.5, 0); //EPSG:10169 の基準点
61+
const auto prj3 = geo3.project(ref_point3);
62+
plateau::geometry::GeoReference geo_ref6(options.coordinate_zone_id, prj3, options.unit_scale);
63+
3264
try {
33-
auto pos = geo_ref.unproject(PolygonMeshUtils::cityObjPos(city_obj));
65+
const auto pos = PolygonMeshUtils::cityObjPos(city_obj);
66+
67+
const auto unprojected = geo_ref4.unproject(pos);
68+
69+
const auto unprojected1 = geo_ref2.unproject(pos + epsg_offset);
70+
//const auto unprojected2 = geo_ref2.unproject(epsg_offset - pos);
71+
//const auto unprojected2 = geo_ref2.unproject(pos);
72+
//const auto unprojected3 = geo_ref4.unproject(pos + epsg_offset);
73+
74+
const auto unprojected4 = geo_ref5.unproject(pos + epsg_offset);
75+
//const auto unprojected5 = geo_ref5.unproject(epsg_offset- pos);
76+
77+
const auto unprojected5 = geo_ref6.unproject(pos + epsg_offset);
78+
3479
for (const auto& extent : extents) {
35-
if (extent.contains(pos))
80+
if (extent.contains(unprojected1))
3681
return false;
3782
}
83+
84+
//auto pos = PolygonMeshUtils::cityObjPos(city_obj);
85+
//for (const auto& extent : extents) {
86+
// if (extent.contains(geo_ref.unproject(pos)))
87+
// return false;
88+
//}
3889
}
3990
catch (std::invalid_argument& e) {}
91+
92+
//Temp Debug =======================
93+
//return false;
94+
//Temp Debug =======================
4095
}
4196
else {
4297
for (const auto& extent : extents) {

src/polygon_mesh/mesh_factory.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace plateau::polygonMesh {
3232
*/
3333
void cityGmlPolygonToMesh(
3434
const Polygon& polygon, const std::string& gml_path,
35-
const GeoReference& geo_reference, Mesh& out_mesh, bool is_polar_coordinate_system) {
35+
const GeoReference& geo_reference, Mesh& out_mesh, double epsg) {
3636

3737
// マージ対象の情報を取得します。ここでの頂点は極座標です。
3838
const auto& vertices_lat_lon = polygon.getVertices();
@@ -54,7 +54,19 @@ namespace plateau::polygonMesh {
5454
auto& out_vertices = out_mesh.getVertices();
5555
out_vertices.reserve(vertices_lat_lon.size());
5656
for (const auto& lat_lon : vertices_lat_lon) {
57-
auto xyz = geo_reference.convert(lat_lon, false, is_polar_coordinate_system);
57+
58+
//auto xyz = geo_reference.convert(lat_lon, false, is_polar_coordinate_system);
59+
//if (!is_polar_coordinate_system) {
60+
// plateau::geometry::GeoCoordinate refPoint;
61+
// plateau::geometry::ReferencePointFactory::GetReferencePoint(epsg, refPoint);
62+
// plateau::geometry::GeoReference geo_ref(geo_reference.getZoneID());
63+
// const auto& offset = geo_ref.project(refPoint);
64+
// //xyz = xyz + GeoReference::convertAxisToENU(geo_reference.getCoordinateSystem(), geo_reference.getReferencePoint());
65+
// xyz = lat_lon + offset;
66+
//}
67+
68+
auto xyz = geo_reference.convert(lat_lon, false, epsg);
69+
5870
out_vertices.push_back(xyz);
5971
}
6072
assert(out_vertices.size() == vertices_lat_lon.size());
@@ -150,10 +162,17 @@ namespace plateau::polygonMesh {
150162
if (!options.is_polar_coordinate_system) {
151163
// 平面直角座標系の判定
152164
plateau::geometry::GeoReference geo_ref(options.coordinate_zone_id, options.reference_point, options.unit_scale, options.mesh_axes);
153-
if (extent.contains(geo_ref.unproject(vertex))) {
165+
//plateau::geometry::GeoReference geo_ref(options.coordinate_zone_id);
166+
const auto unprojected = geo_ref.unproject(vertex);
167+
if (extent.contains(unprojected)) {
154168
is_in_extent = true;
155169
break;
156170
}
171+
172+
//Temp Debug =======================
173+
//is_in_extent = true;
174+
//break;
175+
//Temp Debug =======================
157176
}
158177
else {
159178
if (extent.contains(vertex)) {
@@ -215,7 +234,7 @@ namespace plateau::polygonMesh {
215234
return;
216235

217236
Mesh mesh;
218-
cityGmlPolygonToMesh(polygon, gml_path, geo_reference_, mesh, options_.is_polar_coordinate_system);
237+
cityGmlPolygonToMesh(polygon, gml_path, geo_reference_, mesh, options_.epsg_code);
219238

220239
const auto from_axis = geometry::CoordinateSystem::ENU;
221240
const auto to_axis = options_.mesh_axes;

src/polygon_mesh/polygon_mesh_utils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <plateau/polygon_mesh/polygon_mesh_utils.h>
22
#include "plateau/polygon_mesh/mesh.h"
33
#include "plateau/geometry/geo_reference.h"
4+
#include "plateau/geometry/geo_coordinate.h"
45
#include "citygml/citymodel.h"
56
#include <plateau/dataset/gml_file.h>
67

@@ -55,6 +56,16 @@ namespace plateau::polygonMesh {
5556
throw std::invalid_argument("Could not find position of CityObject.");
5657
}
5758

59+
//TVec3d PolygonMeshUtils::cityObjPos(const citygml::CityObject& city_obj, const double epsg, int coordinate_zone_id) {
60+
// const auto is_polar = plateau::geometry::ReferencePointFactory::IsPolarCoordinateSystem(epsg);
61+
// const auto pos = cityObjPos(city_obj);
62+
// if (is_polar) {
63+
// return pos;
64+
// }
65+
// plateau::geometry::GeoReference geo_ref(coordinate_zone_id);
66+
// return geo_ref.unproject(pos);
67+
//}
68+
5869
TVec3d PolygonMeshUtils::getCenterPoint(const CityModel& city_model, int coordinate_zone_id) {
5970
auto& envelope = city_model.getEnvelope();
6071
if (!envelope.validBounds()) {

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/PolygonMesh/MeshExtractOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static ConvertGranularity ToConvertGranularity(this MeshGranularity g)
7272
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
7373
public struct MeshExtractOptions
7474
{
75-
public MeshExtractOptions(PlateauVector3d referencePoint, CoordinateSystem meshAxes, MeshGranularity meshGranularity, uint minLOD, uint maxLOD, bool exportAppearance, int gridCountOfSide, float unitScale, int coordinateZoneID, bool excludeCityObjectOutsideExtent, bool excludePolygonsOutsideExtent, bool enableTexturePacking, uint texturePackingResolution, bool attachMapTile, int mapTileZoomLevel, string mapTileURL, bool isPolarCoordinateSystem)
75+
public MeshExtractOptions(PlateauVector3d referencePoint, CoordinateSystem meshAxes, MeshGranularity meshGranularity, uint minLOD, uint maxLOD, bool exportAppearance, int gridCountOfSide, float unitScale, int coordinateZoneID, bool excludeCityObjectOutsideExtent, bool excludePolygonsOutsideExtent, bool enableTexturePacking, uint texturePackingResolution, bool attachMapTile, int mapTileZoomLevel, string mapTileURL, bool isPolarCoordinateSystem, double epsgCode)
7676
{
7777
this.ReferencePoint = referencePoint;
7878
this.MeshAxes = meshAxes;
@@ -91,6 +91,7 @@ public MeshExtractOptions(PlateauVector3d referencePoint, CoordinateSystem meshA
9191
this.MapTileZoomLevel = mapTileZoomLevel;
9292
this.mapTileURL = mapTileURL;
9393
this.IsPolarCoordinateSystem = isPolarCoordinateSystem;
94+
this.epsgCode = epsgCode;
9495

9596
// 上で全てのメンバー変数を設定できてますが、バリデーションをするため念のためメソッドやプロパティも呼びます。
9697
SetLODRange(minLOD, maxLOD);
@@ -231,6 +232,8 @@ public string MapTileURL
231232
/// </summary>
232233
[MarshalAs(UnmanagedType.U1)] public bool IsPolarCoordinateSystem;
233234

235+
public double epsgCode;
236+
234237
/// <summary> デフォルト値の設定を返します。 </summary>
235238
internal static MeshExtractOptions DefaultValue()
236239
{

0 commit comments

Comments
 (0)