Skip to content

Commit f2babb3

Browse files
authored
Merge pull request #171 from Geode-solutions/fix/crs-info-python
fix(Python): simplify GeographicCoordinateSystemInfo
2 parents fc0b53d + 5fe0c02 commit f2babb3

7 files changed

Lines changed: 130 additions & 120 deletions

File tree

bindings/python/src/explicit/geometry/crs.hpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,13 @@
2626
#include <geode/geosciences/explicit/geometry/geographic_coordinate_system.hpp>
2727

2828
#define PYTHON_CRS( dimension ) \
29-
const auto info##dimension = \
30-
"GeographicCoordinateSystemInfo" + std::to_string( dimension ) + "D"; \
31-
pybind11::class_< GeographicCoordinateSystem##dimension##D::Info >( \
32-
module, info##dimension.c_str() ) \
33-
.def( pybind11::init< std::string, std::string, std::string >() ) \
34-
.def( "authority_code", \
35-
&GeographicCoordinateSystem##dimension##D::Info::authority_code ) \
36-
.def( "string", \
37-
&GeographicCoordinateSystem##dimension##D::Info::string ) \
38-
.def_readwrite( "authority", \
39-
&GeographicCoordinateSystem##dimension##D::Info::authority ) \
40-
.def_readwrite( \
41-
"code", &GeographicCoordinateSystem##dimension##D::Info::code ) \
42-
.def_readwrite( \
43-
"name", &GeographicCoordinateSystem##dimension##D::Info::name ); \
4429
const auto name##dimension = \
4530
"GeographicCoordinateSystem" + std::to_string( dimension ) + "D"; \
4631
pybind11::class_< GeographicCoordinateSystem##dimension##D, \
4732
CoordinateReferenceSystem##dimension##D >( \
4833
module, name##dimension.c_str() ) \
4934
.def( pybind11::init< AttributeManager&, \
50-
GeographicCoordinateSystem##dimension##D::Info >() ) \
35+
GeographicCoordinateSystemInfo >() ) \
5136
.def( "type_name_static", \
5237
&GeographicCoordinateSystem##dimension##D::type_name_static ) \
5338
.def( "info", &GeographicCoordinateSystem##dimension##D::info ) \
@@ -61,6 +46,16 @@ namespace geode
6146
{
6247
void define_crs( pybind11::module& module )
6348
{
49+
pybind11::class_< GeographicCoordinateSystemInfo >(
50+
module, "GeographicCoordinateSystemInfo" )
51+
.def( pybind11::init< std::string, std::string, std::string >() )
52+
.def( "authority_code",
53+
&GeographicCoordinateSystemInfo::authority_code )
54+
.def( "string", &GeographicCoordinateSystemInfo::string )
55+
.def_readwrite(
56+
"authority", &GeographicCoordinateSystemInfo::authority )
57+
.def_readwrite( "code", &GeographicCoordinateSystemInfo::code )
58+
.def_readwrite( "name", &GeographicCoordinateSystemInfo::name );
6459
PYTHON_CRS( 2 );
6560
PYTHON_CRS( 3 );
6661
}

bindings/python/tests/explicit/test-py-geographic-coordinate-system.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
import os
2323
import sys
2424
import platform
25+
2526
if sys.version_info >= (3, 8, 0) and platform.system() == "Windows":
26-
for path in [x.strip() for x in os.environ['PATH'].split(';') if x]:
27+
for path in [x.strip() for x in os.environ["PATH"].split(";") if x]:
2728
os.add_dll_directory(path)
2829

2930
import opengeode
3031
import opengeode_geosciences_py_explicit as geosciences
3132

32-
if __name__ == '__main__':
33+
if __name__ == "__main__":
3334
geosciences.GeosciencesExplicitLibrary.initialize()
3435

3536
infos = geosciences.GeographicCoordinateSystem3D.geographic_coordinate_systems()
@@ -41,17 +42,20 @@
4142
manager.resize(nb_points)
4243

4344
lambert1 = geosciences.GeographicCoordinateSystem3D(
44-
manager, geosciences.GeographicCoordinateSystemInfo3D("EPSG", "27571", "I"))
45+
manager, geosciences.GeographicCoordinateSystemInfo("EPSG", "27571", "I")
46+
)
4547
for p in range(nb_points):
4648
lambert1.set_point(p, opengeode.Point3D([p, p, p]))
4749
lambert2 = geosciences.GeographicCoordinateSystem3D(
48-
manager, geosciences.GeographicCoordinateSystemInfo3D("EPSG", "27572", "II"))
50+
manager, geosciences.GeographicCoordinateSystemInfo("EPSG", "27572", "II")
51+
)
4952
lambert2.import_coordinates(lambert1)
5053
answers = [
5154
opengeode.Point3D([4273.64251995017, 1302920.55457198, 0]),
5255
opengeode.Point3D([4274.63159306906, 1302921.55102308, 1]),
5356
opengeode.Point3D([4275.62066620018, 1302922.54747419, 2]),
54-
opengeode.Point3D([4276.60973934352, 1302923.5439253, 3])]
57+
opengeode.Point3D([4276.60973934352, 1302923.5439253, 3]),
58+
]
5559
for p in range(nb_points):
5660
if not lambert2.point(p).inexact_equal(answers[p]):
5761
raise ValueError("[Test] Wrong coordinate conversion")

commitlint.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default {
1+
const Configuration = {
22
extends: ["@commitlint/config-angular"],
33
rules: {
44
"scope-empty": [2, "never"],
@@ -12,5 +12,8 @@ export default {
1212
"subject-full-stop": [0],
1313
"type-case": [0],
1414
"type-empty": [0],
15+
"type-enum": [2, "always", ["feat", "fix", "perf"]],
1516
},
1617
}
18+
19+
export default Configuration

include/geode/geosciences/explicit/geometry/geographic_coordinate_system.hpp

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,60 +36,57 @@ namespace geode
3636

3737
namespace geode
3838
{
39-
template < index_t dimension >
40-
class GeographicCoordinateSystem
41-
: public AttributeCoordinateReferenceSystem< dimension >
39+
struct opengeode_geosciences_explicit_api GeographicCoordinateSystemInfo
4240
{
43-
friend class bitsery::Access;
41+
GeographicCoordinateSystemInfo( std::string authority_in,
42+
std::string code_in,
43+
std::string name_in );
44+
GeographicCoordinateSystemInfo();
45+
~GeographicCoordinateSystemInfo();
4446

45-
public:
46-
struct Info
47+
[[nodiscard]] std::string authority_code() const
48+
{
49+
return absl::StrCat( authority, ":", code );
50+
}
51+
52+
[[nodiscard]] std::string string() const
53+
{
54+
return absl::StrCat( "(", authority_code(), " -> ", name, ")" );
55+
}
56+
57+
template < typename Archive >
58+
void serialize( Archive& archive )
4759
{
48-
Info( std::string authority_in,
49-
std::string code_in,
50-
std::string name_in )
51-
: authority{ std::move( authority_in ) },
52-
code{ std::move( code_in ) },
53-
name{ std::move( name_in ) }
54-
{
55-
}
56-
Info() = default;
57-
58-
[[nodiscard]] std::string authority_code() const
59-
{
60-
return absl::StrCat( authority, ":", code );
61-
}
62-
63-
[[nodiscard]] std::string string() const
64-
{
65-
return absl::StrCat( "(", authority_code(), " -> ", name, ")" );
66-
}
67-
68-
template < typename Archive >
69-
void serialize( Archive& archive )
70-
{
71-
archive.ext( *this,
72-
Growable< Archive, Info >{ { []( Archive& a, Info& info ) {
60+
archive.ext( *this,
61+
Growable< Archive, GeographicCoordinateSystemInfo >{
62+
{ []( Archive& a, GeographicCoordinateSystemInfo& info ) {
7363
a.text1b( info.authority, info.authority.max_size() );
7464
a.text1b( info.code, info.code.max_size() );
7565
a.text1b( info.name, info.name.max_size() );
7666
} } } );
77-
}
67+
}
68+
69+
std::string authority;
70+
std::string code;
71+
std::string name;
72+
};
7873

79-
std::string authority;
80-
std::string code;
81-
std::string name;
82-
};
74+
template < index_t dimension >
75+
class GeographicCoordinateSystem
76+
: public AttributeCoordinateReferenceSystem< dimension >
77+
{
78+
friend class bitsery::Access;
8379

8480
public:
85-
GeographicCoordinateSystem( AttributeManager& manager, Info info );
81+
GeographicCoordinateSystem(
82+
AttributeManager& manager, GeographicCoordinateSystemInfo info );
8683
~GeographicCoordinateSystem();
8784

8885
[[nodiscard]] static GeographicCoordinateSystem< dimension >
8986
create_from_attribute(
9087
const AttributeCoordinateReferenceSystem< dimension >& crs,
9188
AttributeManager& manager,
92-
Info info );
89+
GeographicCoordinateSystemInfo info );
9390

9491
[[nodiscard]] static CRSType type_name_static()
9592
{
@@ -101,9 +98,9 @@ namespace geode
10198
return type_name_static();
10299
}
103100

104-
[[nodiscard]] const Info& info() const;
101+
[[nodiscard]] const GeographicCoordinateSystemInfo& info() const;
105102

106-
[[nodiscard]] static absl::FixedArray< Info >
103+
[[nodiscard]] static absl::FixedArray< GeographicCoordinateSystemInfo >
107104
geographic_coordinate_systems();
108105

109106
void import_coordinates(

include/geode/geosciences/explicit/geometry/geographic_coordinate_system_helper.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,79 +49,79 @@ namespace geode
4949
const EdgedCurve< dimension >& mesh,
5050
EdgedCurveBuilder< dimension >& builder,
5151
std::string_view crs_name,
52-
typename GeographicCoordinateSystem< dimension >::Info info );
52+
GeographicCoordinateSystemInfo info );
5353

5454
template < index_t dimension >
5555
void assign_point_set_geographic_coordinate_system_info(
5656
const PointSet< dimension >& mesh,
5757
PointSetBuilder< dimension >& builder,
5858
std::string_view crs_name,
59-
typename GeographicCoordinateSystem< dimension >::Info info );
59+
GeographicCoordinateSystemInfo info );
6060

6161
template < index_t dimension >
6262
void assign_solid_mesh_geographic_coordinate_system_info(
6363
const SolidMesh< dimension >& mesh,
6464
SolidMeshBuilder< dimension >& builder,
6565
std::string_view crs_name,
66-
typename GeographicCoordinateSystem< dimension >::Info info );
66+
GeographicCoordinateSystemInfo info );
6767

6868
template < index_t dimension >
6969
void assign_surface_mesh_geographic_coordinate_system_info(
7070
const SurfaceMesh< dimension >& mesh,
7171
SurfaceMeshBuilder< dimension >& builder,
7272
std::string_view crs_name,
73-
typename GeographicCoordinateSystem< dimension >::Info info );
73+
GeographicCoordinateSystemInfo info );
7474

7575
void opengeode_geosciences_explicit_api
7676
assign_brep_geographic_coordinate_system_info( const BRep& brep,
7777
BRepBuilder& builder,
7878
std::string_view crs_name,
79-
const GeographicCoordinateSystem3D::Info& info );
79+
const GeographicCoordinateSystemInfo& info );
8080

8181
void opengeode_geosciences_explicit_api
8282
assign_section_geographic_coordinate_system_info(
8383
const Section& section,
8484
SectionBuilder& builder,
8585
std::string_view crs_name,
86-
const GeographicCoordinateSystem2D::Info& info );
86+
const GeographicCoordinateSystemInfo& info );
8787

8888
template < index_t dimension >
8989
void convert_edged_curve_coordinate_reference_system(
9090
const EdgedCurve< dimension >& mesh,
9191
EdgedCurveBuilder< dimension >& builder,
9292
std::string_view crs_name,
93-
typename GeographicCoordinateSystem< dimension >::Info info );
93+
GeographicCoordinateSystemInfo info );
9494

9595
template < index_t dimension >
9696
void convert_point_set_coordinate_reference_system(
9797
const PointSet< dimension >& mesh,
9898
PointSetBuilder< dimension >& builder,
9999
std::string_view crs_name,
100-
typename GeographicCoordinateSystem< dimension >::Info info );
100+
GeographicCoordinateSystemInfo info );
101101

102102
template < index_t dimension >
103103
void convert_solid_mesh_coordinate_reference_system(
104104
const SolidMesh< dimension >& mesh,
105105
SolidMeshBuilder< dimension >& builder,
106106
std::string_view crs_name,
107-
typename GeographicCoordinateSystem< dimension >::Info info );
107+
GeographicCoordinateSystemInfo info );
108108

109109
template < index_t dimension >
110110
void convert_surface_mesh_coordinate_reference_system(
111111
const SurfaceMesh< dimension >& mesh,
112112
SurfaceMeshBuilder< dimension >& builder,
113113
std::string_view crs_name,
114-
typename GeographicCoordinateSystem< dimension >::Info info );
114+
GeographicCoordinateSystemInfo info );
115115

116116
void opengeode_geosciences_explicit_api
117117
convert_brep_coordinate_reference_system( const BRep& brep,
118118
BRepBuilder& builder,
119119
std::string_view crs_name,
120-
const GeographicCoordinateSystem3D::Info& info );
120+
const GeographicCoordinateSystemInfo& info );
121121

122122
void opengeode_geosciences_explicit_api
123123
convert_section_coordinate_reference_system( const Section& section,
124124
SectionBuilder& builder,
125125
std::string_view crs_name,
126-
const GeographicCoordinateSystem2D::Info& info );
126+
const GeographicCoordinateSystemInfo& info );
127127
} // namespace geode

src/geode/geosciences/explicit/geometry/geographic_coordinate_system.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,32 @@
3333

3434
namespace geode
3535
{
36+
37+
GeographicCoordinateSystemInfo::GeographicCoordinateSystemInfo(
38+
std::string authority_in, std::string code_in, std::string name_in )
39+
: authority{ std::move( authority_in ) },
40+
code{ std::move( code_in ) },
41+
name{ std::move( name_in ) }
42+
{
43+
}
44+
45+
GeographicCoordinateSystemInfo::GeographicCoordinateSystemInfo() = default;
46+
47+
GeographicCoordinateSystemInfo::~GeographicCoordinateSystemInfo() = default;
48+
3649
template < index_t dimension >
3750
class GeographicCoordinateSystem< dimension >::Impl
3851
{
3952
friend class bitsery::Access;
4053

4154
public:
42-
Impl( Info info ) : info_{ std::move( info ) } {}
55+
Impl( GeographicCoordinateSystemInfo info ) : info_{ std::move( info ) }
56+
{
57+
}
4358

4459
Impl() = default;
4560

46-
const Info& info() const
61+
const GeographicCoordinateSystemInfo& info() const
4762
{
4863
return info_;
4964
}
@@ -91,29 +106,28 @@ namespace geode
91106
}
92107

93108
private:
94-
Info info_;
109+
GeographicCoordinateSystemInfo info_;
95110
};
96111

97112
template < index_t dimension >
98-
GeographicCoordinateSystem< dimension >::GeographicCoordinateSystem()
99-
{
100-
}
113+
GeographicCoordinateSystem< dimension >::GeographicCoordinateSystem() =
114+
default;
101115

102116
template < index_t dimension >
103117
GeographicCoordinateSystem< dimension >::GeographicCoordinateSystem(
104-
AttributeManager& manager, Info info )
118+
AttributeManager& manager, GeographicCoordinateSystemInfo info )
105119
: AttributeCoordinateReferenceSystem< dimension >{ manager, info.name },
106120
impl_{ std::move( info ) }
107121
{
108122
}
109123

110124
template < index_t dimension >
111-
GeographicCoordinateSystem< dimension >::~GeographicCoordinateSystem()
112-
{
113-
}
125+
GeographicCoordinateSystem< dimension >::~GeographicCoordinateSystem() =
126+
default;
114127

115128
template < index_t dimension >
116-
auto GeographicCoordinateSystem< dimension >::info() const -> const Info&
129+
const GeographicCoordinateSystemInfo&
130+
GeographicCoordinateSystem< dimension >::info() const
117131
{
118132
return impl_->info();
119133
}
@@ -133,14 +147,13 @@ namespace geode
133147
}
134148

135149
template < index_t dimension >
136-
auto
150+
absl::FixedArray< GeographicCoordinateSystemInfo >
137151
GeographicCoordinateSystem< dimension >::geographic_coordinate_systems()
138-
-> absl::FixedArray< Info >
139152
{
140153
int nb_crs{ 0 };
141154
auto** gdal_list =
142155
OSRGetCRSInfoListFromDatabase( nullptr, nullptr, &nb_crs );
143-
absl::FixedArray< Info > infos( nb_crs );
156+
absl::FixedArray< GeographicCoordinateSystemInfo > infos( nb_crs );
144157
for( const auto i : Range{ nb_crs } )
145158
{
146159
const auto* gdal_crs = gdal_list[i];

0 commit comments

Comments
 (0)