Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions bindings/python/src/explicit/geometry/crs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,13 @@
#include <geode/geosciences/explicit/geometry/geographic_coordinate_system.hpp>

#define PYTHON_CRS( dimension ) \
const auto info##dimension = \
"GeographicCoordinateSystemInfo" + std::to_string( dimension ) + "D"; \
pybind11::class_< GeographicCoordinateSystem##dimension##D::Info >( \
module, info##dimension.c_str() ) \
.def( pybind11::init< std::string, std::string, std::string >() ) \
.def( "authority_code", \
&GeographicCoordinateSystem##dimension##D::Info::authority_code ) \
.def( "string", \
&GeographicCoordinateSystem##dimension##D::Info::string ) \
.def_readwrite( "authority", \
&GeographicCoordinateSystem##dimension##D::Info::authority ) \
.def_readwrite( \
"code", &GeographicCoordinateSystem##dimension##D::Info::code ) \
.def_readwrite( \
"name", &GeographicCoordinateSystem##dimension##D::Info::name ); \
const auto name##dimension = \
"GeographicCoordinateSystem" + std::to_string( dimension ) + "D"; \
pybind11::class_< GeographicCoordinateSystem##dimension##D, \
CoordinateReferenceSystem##dimension##D >( \
module, name##dimension.c_str() ) \
.def( pybind11::init< AttributeManager&, \
GeographicCoordinateSystem##dimension##D::Info >() ) \
GeographicCoordinateSystemInfo >() ) \
.def( "type_name_static", \
&GeographicCoordinateSystem##dimension##D::type_name_static ) \
.def( "info", &GeographicCoordinateSystem##dimension##D::info ) \
Expand All @@ -61,6 +46,16 @@ namespace geode
{
void define_crs( pybind11::module& module )
{
pybind11::class_< GeographicCoordinateSystemInfo >(
module, "GeographicCoordinateSystemInfo" )
.def( pybind11::init< std::string, std::string, std::string >() )
.def( "authority_code",
&GeographicCoordinateSystemInfo::authority_code )
.def( "string", &GeographicCoordinateSystemInfo::string )
.def_readwrite(
"authority", &GeographicCoordinateSystemInfo::authority )
.def_readwrite( "code", &GeographicCoordinateSystemInfo::code )
.def_readwrite( "name", &GeographicCoordinateSystemInfo::name );
PYTHON_CRS( 2 );
PYTHON_CRS( 3 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import os
import sys
import platform

if sys.version_info >= (3, 8, 0) and platform.system() == "Windows":
for path in [x.strip() for x in os.environ['PATH'].split(';') if x]:
for path in [x.strip() for x in os.environ["PATH"].split(";") if x]:
os.add_dll_directory(path)

import opengeode
import opengeode_geosciences_py_explicit as geosciences

if __name__ == '__main__':
if __name__ == "__main__":
geosciences.GeosciencesExplicitLibrary.initialize()

infos = geosciences.GeographicCoordinateSystem3D.geographic_coordinate_systems()
Expand All @@ -41,17 +42,20 @@
manager.resize(nb_points)

lambert1 = geosciences.GeographicCoordinateSystem3D(
manager, geosciences.GeographicCoordinateSystemInfo3D("EPSG", "27571", "I"))
manager, geosciences.GeographicCoordinateSystemInfo("EPSG", "27571", "I")
)
for p in range(nb_points):
lambert1.set_point(p, opengeode.Point3D([p, p, p]))
lambert2 = geosciences.GeographicCoordinateSystem3D(
manager, geosciences.GeographicCoordinateSystemInfo3D("EPSG", "27572", "II"))
manager, geosciences.GeographicCoordinateSystemInfo("EPSG", "27572", "II")
)
lambert2.import_coordinates(lambert1)
answers = [
opengeode.Point3D([4273.64251995017, 1302920.55457198, 0]),
opengeode.Point3D([4274.63159306906, 1302921.55102308, 1]),
opengeode.Point3D([4275.62066620018, 1302922.54747419, 2]),
opengeode.Point3D([4276.60973934352, 1302923.5439253, 3])]
opengeode.Point3D([4276.60973934352, 1302923.5439253, 3]),
]
for p in range(nb_points):
if not lambert2.point(p).inexact_equal(answers[p]):
raise ValueError("[Test] Wrong coordinate conversion")
5 changes: 4 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
const Configuration = {
extends: ["@commitlint/config-angular"],
rules: {
"scope-empty": [2, "never"],
Expand All @@ -12,5 +12,8 @@ export default {
"subject-full-stop": [0],
"type-case": [0],
"type-empty": [0],
"type-enum": [2, "always", ["feat", "fix", "perf"]],
},
}

export default Configuration
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,57 @@ namespace geode

namespace geode
{
template < index_t dimension >
class GeographicCoordinateSystem
: public AttributeCoordinateReferenceSystem< dimension >
struct opengeode_geosciences_explicit_api GeographicCoordinateSystemInfo
{
friend class bitsery::Access;
GeographicCoordinateSystemInfo( std::string authority_in,
std::string code_in,
std::string name_in );
GeographicCoordinateSystemInfo();
~GeographicCoordinateSystemInfo();

public:
struct Info
[[nodiscard]] std::string authority_code() const
{
return absl::StrCat( authority, ":", code );
}

[[nodiscard]] std::string string() const
{
return absl::StrCat( "(", authority_code(), " -> ", name, ")" );
}

template < typename Archive >
void serialize( Archive& archive )
{
Info( std::string authority_in,
std::string code_in,
std::string name_in )
: authority{ std::move( authority_in ) },
code{ std::move( code_in ) },
name{ std::move( name_in ) }
{
}
Info() = default;

[[nodiscard]] std::string authority_code() const
{
return absl::StrCat( authority, ":", code );
}

[[nodiscard]] std::string string() const
{
return absl::StrCat( "(", authority_code(), " -> ", name, ")" );
}

template < typename Archive >
void serialize( Archive& archive )
{
archive.ext( *this,
Growable< Archive, Info >{ { []( Archive& a, Info& info ) {
archive.ext( *this,
Growable< Archive, GeographicCoordinateSystemInfo >{
{ []( Archive& a, GeographicCoordinateSystemInfo& info ) {
a.text1b( info.authority, info.authority.max_size() );
a.text1b( info.code, info.code.max_size() );
a.text1b( info.name, info.name.max_size() );
} } } );
}
}

std::string authority;
std::string code;
std::string name;
};

std::string authority;
std::string code;
std::string name;
};
template < index_t dimension >
class GeographicCoordinateSystem
: public AttributeCoordinateReferenceSystem< dimension >
{
friend class bitsery::Access;

public:
GeographicCoordinateSystem( AttributeManager& manager, Info info );
GeographicCoordinateSystem(
AttributeManager& manager, GeographicCoordinateSystemInfo info );
~GeographicCoordinateSystem();

[[nodiscard]] static GeographicCoordinateSystem< dimension >
create_from_attribute(
const AttributeCoordinateReferenceSystem< dimension >& crs,
AttributeManager& manager,
Info info );
GeographicCoordinateSystemInfo info );

[[nodiscard]] static CRSType type_name_static()
{
Expand All @@ -101,9 +98,9 @@ namespace geode
return type_name_static();
}

[[nodiscard]] const Info& info() const;
[[nodiscard]] const GeographicCoordinateSystemInfo& info() const;

[[nodiscard]] static absl::FixedArray< Info >
[[nodiscard]] static absl::FixedArray< GeographicCoordinateSystemInfo >
geographic_coordinate_systems();

void import_coordinates(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,79 +49,79 @@ namespace geode
const EdgedCurve< dimension >& mesh,
EdgedCurveBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

template < index_t dimension >
void assign_point_set_geographic_coordinate_system_info(
const PointSet< dimension >& mesh,
PointSetBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

template < index_t dimension >
void assign_solid_mesh_geographic_coordinate_system_info(
const SolidMesh< dimension >& mesh,
SolidMeshBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

template < index_t dimension >
void assign_surface_mesh_geographic_coordinate_system_info(
const SurfaceMesh< dimension >& mesh,
SurfaceMeshBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

void opengeode_geosciences_explicit_api
assign_brep_geographic_coordinate_system_info( const BRep& brep,
BRepBuilder& builder,
std::string_view crs_name,
const GeographicCoordinateSystem3D::Info& info );
const GeographicCoordinateSystemInfo& info );

void opengeode_geosciences_explicit_api
assign_section_geographic_coordinate_system_info(
const Section& section,
SectionBuilder& builder,
std::string_view crs_name,
const GeographicCoordinateSystem2D::Info& info );
const GeographicCoordinateSystemInfo& info );

template < index_t dimension >
void convert_edged_curve_coordinate_reference_system(
const EdgedCurve< dimension >& mesh,
EdgedCurveBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

template < index_t dimension >
void convert_point_set_coordinate_reference_system(
const PointSet< dimension >& mesh,
PointSetBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

template < index_t dimension >
void convert_solid_mesh_coordinate_reference_system(
const SolidMesh< dimension >& mesh,
SolidMeshBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

template < index_t dimension >
void convert_surface_mesh_coordinate_reference_system(
const SurfaceMesh< dimension >& mesh,
SurfaceMeshBuilder< dimension >& builder,
std::string_view crs_name,
typename GeographicCoordinateSystem< dimension >::Info info );
GeographicCoordinateSystemInfo info );

void opengeode_geosciences_explicit_api
convert_brep_coordinate_reference_system( const BRep& brep,
BRepBuilder& builder,
std::string_view crs_name,
const GeographicCoordinateSystem3D::Info& info );
const GeographicCoordinateSystemInfo& info );

void opengeode_geosciences_explicit_api
convert_section_coordinate_reference_system( const Section& section,
SectionBuilder& builder,
std::string_view crs_name,
const GeographicCoordinateSystem2D::Info& info );
const GeographicCoordinateSystemInfo& info );
} // namespace geode
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,32 @@

namespace geode
{

GeographicCoordinateSystemInfo::GeographicCoordinateSystemInfo(
std::string authority_in, std::string code_in, std::string name_in )
: authority{ std::move( authority_in ) },
code{ std::move( code_in ) },
name{ std::move( name_in ) }
{
}

GeographicCoordinateSystemInfo::GeographicCoordinateSystemInfo() = default;

GeographicCoordinateSystemInfo::~GeographicCoordinateSystemInfo() = default;

template < index_t dimension >
class GeographicCoordinateSystem< dimension >::Impl
{
friend class bitsery::Access;

public:
Impl( Info info ) : info_{ std::move( info ) } {}
Impl( GeographicCoordinateSystemInfo info ) : info_{ std::move( info ) }
{
}

Impl() = default;

const Info& info() const
const GeographicCoordinateSystemInfo& info() const
{
return info_;
}
Expand Down Expand Up @@ -91,29 +106,28 @@ namespace geode
}

private:
Info info_;
GeographicCoordinateSystemInfo info_;
};

template < index_t dimension >
GeographicCoordinateSystem< dimension >::GeographicCoordinateSystem()
{
}
GeographicCoordinateSystem< dimension >::GeographicCoordinateSystem() =
default;

template < index_t dimension >
GeographicCoordinateSystem< dimension >::GeographicCoordinateSystem(
AttributeManager& manager, Info info )
AttributeManager& manager, GeographicCoordinateSystemInfo info )
: AttributeCoordinateReferenceSystem< dimension >{ manager, info.name },
impl_{ std::move( info ) }
{
}

template < index_t dimension >
GeographicCoordinateSystem< dimension >::~GeographicCoordinateSystem()
{
}
GeographicCoordinateSystem< dimension >::~GeographicCoordinateSystem() =
default;

template < index_t dimension >
auto GeographicCoordinateSystem< dimension >::info() const -> const Info&
const GeographicCoordinateSystemInfo&
GeographicCoordinateSystem< dimension >::info() const
{
return impl_->info();
}
Expand All @@ -133,14 +147,13 @@ namespace geode
}

template < index_t dimension >
auto
absl::FixedArray< GeographicCoordinateSystemInfo >
GeographicCoordinateSystem< dimension >::geographic_coordinate_systems()
-> absl::FixedArray< Info >
{
int nb_crs{ 0 };
auto** gdal_list =
OSRGetCRSInfoListFromDatabase( nullptr, nullptr, &nb_crs );
absl::FixedArray< Info > infos( nb_crs );
absl::FixedArray< GeographicCoordinateSystemInfo > infos( nb_crs );
for( const auto i : Range{ nb_crs } )
{
const auto* gdal_crs = gdal_list[i];
Expand Down
Loading