From c6d5eea78674ee9fa2bb7a1055c6680b4961ba63 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 13:21:13 +0200 Subject: [PATCH 1/9] basic metadata support --- src/metadata.i | 39 +++++++++++++++++++++++++ src/operation.i | 21 ++++++++++++- src/proj.i | 2 ++ src/util.i | 34 ++++++++++++--------- test/shared/coordinateoperation.test.ts | 2 +- test/shared/crs.test.ts | 14 +++++++++ test/shared/metadata.test.ts | 32 ++++++++++++++++++++ 7 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 src/metadata.i create mode 100644 test/shared/metadata.test.ts diff --git a/src/metadata.i b/src/metadata.i new file mode 100644 index 0000000..95d0185 --- /dev/null +++ b/src/metadata.i @@ -0,0 +1,39 @@ +%nn_shared_ptr(osgeo::proj::metadata::Identifier); +%nn_shared_ptr(osgeo::proj::metadata::Citation); +%nn_shared_ptr(osgeo::proj::metadata::Extent); +%nn_shared_ptr(osgeo::proj::metadata::GeographicBoundingBox); +%nn_shared_ptr(osgeo::proj::metadata::TemporalExtent); +%nn_shared_ptr(osgeo::proj::metadata::VerticalExtent); +%nn_shared_ptr(osgeo::proj::metadata::PositionalAccuracy); + +%define IDENTIFIER_DOWNCAST_TABLE_ENTRY(TYPE) +identifier_downcast_table.insert({typeid(TYPE).hash_code(), $descriptor(TYPE *)}) +%enddef + +%fragment("identifier_downcast_table", "header", fragment="include_map") { + std::map identifier_downcast_table; + + void init_identifier_downcast_table() { + IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Identifier); + IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Citation); + IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Extent); + IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::GeographicBoundingBox); + IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::TemporalExtent); + IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::VerticalExtent); + IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::PositionalAccuracy); + } +} + +%init { + init_identifier_downcast_table(); +} + +// See util.i for the downcasting mechanics +// This overwrites the typemap created by %nn_shared_ptr +%typemap(out, fragment="identifier_downcast_table") dropbox::oxygen::nn> { + TRY_DOWNCASTING($1, $result, osgeo::proj::metadata::Identifier, identifier_downcast_table) +} + +// Extent is nullable when not an nn pointer +%typemap(ts) osgeo::proj::metadata::ExtentPtr "Extent | null"; +%typemap(ts) const osgeo::proj::metadata::ExtentPtr & "Extent | null"; diff --git a/src/operation.i b/src/operation.i index 2dd42d2..23848c6 100644 --- a/src/operation.i +++ b/src/operation.i @@ -16,8 +16,27 @@ %nn_unique_ptr(osgeo::proj::operation::CoordinateOperationFactory); %nn_unique_ptr(osgeo::proj::operation::CoordinateTransformer); +%define COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(TYPE) +coordinate_operation_downcast_table.insert({typeid(TYPE).hash_code(), $descriptor(TYPE *)}) +%enddef + +%fragment("coordinate_operation_downcast_table", "header", fragment="include_map") { + std::map coordinate_operation_downcast_table; + + void init_coordinate_operation_downcast_table() { + COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::CoordinateOperation); + COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::SingleOperation); + COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::ConcatenatedOperation); + COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::Conversion); + } +} + +%init { + init_coordinate_operation_downcast_table(); +} + // See util.i for the downcasting mechanics // This overwrites the typemap created by %nn_shared_ptr -%typemap(out, fragment="downcast_tables") dropbox::oxygen::nn> { +%typemap(out, fragment="coordinate_operation_downcast_table") dropbox::oxygen::nn> { TRY_DOWNCASTING($1, $result, osgeo::proj::operation::CoordinateOperation, coordinate_operation_downcast_table) } diff --git a/src/proj.i b/src/proj.i index 44f3e7e..9cf35d7 100644 --- a/src/proj.i +++ b/src/proj.i @@ -62,6 +62,7 @@ using namespace NS_PROJ; %include "util.i" %include "common.i" %include "io.i" +%include "metadata.i" %include "operation.i" %include "datum.i" %include "coordinatesystem.i" @@ -112,6 +113,7 @@ using namespace NS_PROJ; %include %include +%include %include %include %include diff --git a/src/util.i b/src/util.i index 5bda794..5f86406 100644 --- a/src/util.i +++ b/src/util.i @@ -42,16 +42,14 @@ baseobject_downcast_table.insert({typeid(TYPE).hash_code(), $descriptor(TYPE *)}) %enddef -%define COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(TYPE) -coordinate_operation_downcast_table.insert({typeid(TYPE).hash_code(), $descriptor(TYPE *)}) -%enddef - -%fragment("downcast_tables", "header") { +%fragment("include_map", "header") { #include +} + +%fragment("baseobject_downcast_table", "header", fragment="include_map") { std::map baseobject_downcast_table; - std::map coordinate_operation_downcast_table; - void init_downcast_tables() { + void init_baseobject_downcast_table() { BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::crs::ProjectedCRS); BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::crs::GeographicCRS); BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::crs::VerticalCRS); @@ -72,16 +70,24 @@ coordinate_operation_downcast_table.insert({typeid(TYPE).hash_code(), $descripto BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::crs::DerivedEngineeringCRS); BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::crs::DerivedParametricCRS); BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::crs::DerivedTemporalCRS); - - COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::CoordinateOperation); - COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::SingleOperation); - COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::ConcatenatedOperation); - COORDINATE_OPERATION_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::Conversion); + // These can be downcasted both from BaseObject and from CoordinateOperation (in operation.i) + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::CoordinateOperation); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::SingleOperation); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::ConcatenatedOperation); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::operation::Conversion); + // These can be downcasted both from BaseObject and from Identifier (in metadata.i) + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Identifier); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Citation); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Extent); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::GeographicBoundingBox); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::TemporalExtent); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::VerticalExtent); + BASEOBJECT_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::PositionalAccuracy); } } %init { - init_downcast_tables(); + init_baseobject_downcast_table(); } /* @@ -109,7 +115,7 @@ coordinate_operation_downcast_table.insert({typeid(TYPE).hash_code(), $descripto } %enddef -%typemap(out, fragment="downcast_tables") osgeo::proj::util::BaseObjectNNPtr { +%typemap(out, fragment="baseobject_downcast_table") osgeo::proj::util::BaseObjectNNPtr { TRY_DOWNCASTING($1, $result, osgeo::proj::util::BaseObject, baseobject_downcast_table) } diff --git a/test/shared/coordinateoperation.test.ts b/test/shared/coordinateoperation.test.ts index 1aaa791..f4152fc 100644 --- a/test/shared/coordinateoperation.test.ts +++ b/test/shared/coordinateoperation.test.ts @@ -3,7 +3,7 @@ import { assert } from 'chai'; import qPROJ from 'proj.js'; import type * as PROJ from 'proj.js'; -describe.only('CoordinateOperation with automatic import', () => { +describe('CoordinateOperation with automatic import', () => { let PROJ: Awaited; let dbContext: PROJ.DatabaseContext; diff --git a/test/shared/crs.test.ts b/test/shared/crs.test.ts index 2dafc89..5fb7f44 100644 --- a/test/shared/crs.test.ts +++ b/test/shared/crs.test.ts @@ -53,4 +53,18 @@ describe('CRS with automatic import', () => { assert.instanceOf(crs, PROJ.CRS); assert.instanceOf(crs, PROJ.ProjectedCRS); }); + + it('isDynamic (return bool)', () => { + const crs = authFactoryEPSG.createCoordinateReferenceSystem('3857'); + assert.isBoolean(crs.isDynamic()); + }); + + it('extract GeographicCRS (return CRS)', () => { + const crs = authFactoryEPSG.createCoordinateReferenceSystem('3857'); + const geographic = crs.extractGeographicCRS(); + assert.instanceOf(geographic, PROJ.CRS); + assert.instanceOf(geographic, PROJ.SingleCRS); + assert.instanceOf(geographic, PROJ.GeographicCRS); + }); + }); diff --git a/test/shared/metadata.test.ts b/test/shared/metadata.test.ts new file mode 100644 index 0000000..376a17a --- /dev/null +++ b/test/shared/metadata.test.ts @@ -0,0 +1,32 @@ +import { assert } from 'chai'; + +import qPROJ from 'proj.js'; +import type * as PROJ from 'proj.js'; + +describe('metadata with automatic import', () => { + let PROJ: Awaited; + + let dbContext: PROJ.DatabaseContext; + let authFactory: PROJ.AuthorityFactory; + let authFactoryEPSG: PROJ.AuthorityFactory; + + before('init', async () => { + PROJ = await qPROJ; + dbContext = PROJ.DatabaseContext.create(); + authFactory = PROJ.AuthorityFactory.create(dbContext, 'string'); + authFactoryEPSG = PROJ.AuthorityFactory.create(dbContext, 'EPSG'); + }); + + it('IdentifiedObject properties', () => { + const crs = authFactoryEPSG.createCoordinateReferenceSystem('3857'); + const metadata = crs.identifiers(); + assert.isArray(metadata); + for (const m of metadata) { + assert.instanceOf(m, PROJ.Identifier); + assert.instanceOf(m, PROJ.BaseObject); + assert.isString(m.code()); + assert.isNotNull(m.authority()); + } + }); + +}); From 44547bf76231bb0211a48a040958669c5f6841e2 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 13:31:18 +0200 Subject: [PATCH 2/9] include the table and type name in the debug message --- src/util.i | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/util.i b/src/util.i index 5f86406..dd17ae5 100644 --- a/src/util.i +++ b/src/util.i @@ -99,10 +99,10 @@ baseobject_downcast_table.insert({typeid(TYPE).hash_code(), $descriptor(TYPE *)} */ %define TRY_DOWNCASTING(INPUT, OUTPUT, BASE_TYPE, TABLE) std::size_t rtti_code = typeid(*INPUT.get()).hash_code(); - SWIG_VERBOSE("downcasting for type %s: ", typeid(*INPUT.get()).name()); + SWIG_VERBOSE(#TABLE ": downcasting for type %s: ", typeid(*INPUT.get()).name()); if (TABLE.count(rtti_code) > 0) { - SWIG_VERBOSE("found\n"); swig_type_info *info = TABLE.at(rtti_code); + SWIG_VERBOSE("found %s (%s)\n", info->str, info->name); OUTPUT = SWIG_NewPointerObj(INPUT.get(), info, SWIG_POINTER_OWN | %newpointer_flags); auto *owner = new std::shared_ptr(*&INPUT); auto finalizer = new SWIG_NAPI_Finalizer([owner](){ @@ -119,11 +119,6 @@ baseobject_downcast_table.insert({typeid(TYPE).hash_code(), $descriptor(TYPE *)} TRY_DOWNCASTING($1, $result, osgeo::proj::util::BaseObject, baseobject_downcast_table) } -/* - * CoordinateOperation downcasting is in operation.i, it must come - * after the %nn_shared_ptr definition for CoordinateOperation - */ - /* * TypeScript has static compile-time checking just like C++, which means that * the explicit cast cannot be avoided From df9edf790968acd0f278499bc1d137c68ac96819 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 16:11:45 +0200 Subject: [PATCH 3/9] render the optional typemaps generic --- src/optional.i | 56 +++++++++++++++++++++++++++--------- test/shared/metadata.test.ts | 2 +- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/optional.i b/src/optional.i index 0c59c0b..f62f17d 100644 --- a/src/optional.i +++ b/src/optional.i @@ -1,32 +1,53 @@ -// C++ osgeo::proj::util::optional <-> JS string +// osgeo::proj::util::optional -// This is almost a string, but not quite - -// Input argument, plain object, conversion by copying -%typemap(in) osgeo::proj::util::optional { +// Input argument, plain object, conversion by copying using the underlying object typemap +%typemap(in) osgeo::proj::util::optional { if (!$input.IsNull()) { - std::string opt_string; - $typemap(in, std::string, input=$input, 1=opt_string, argnum=$argnum); - $1 = osgeo::proj::util::optional{opt_string}; + $T0type opt_obj; + $typemap(in, $T0type, input=$input, 1=opt_obj, argnum=$argnum); + $1 = osgeo::proj::util::optional<$T0type>{opt_obj}; } } -%typemap(in) const osgeo::proj::util::optional & (osgeo::proj::util::optional opt_string) { +// Input argument, const reference, conversion by copying, the extra +// step is needed because local variables do not support $T0type expansion +#if 0 +// This is a huge problem because some types are not copyable +%typemap(in) const osgeo::proj::util::optional & (void *opt_obj) { + osgeo::proj::util::optional<$T0type> *typed_ptr; if (!$input.IsNull()) { - $typemap(in, std::string, input=$input, 1=opt_string, argnum=$argnum); + $T0type opt_obj; + $typemap(in, $T0type, input=$input, 1=opt_obj, argnum=$argnum); + typed_ptr = new osgeo::proj::util::optional<$T0type>{opt_obj}; + } else { + typed_ptr = new osgeo::proj::util::optional<$T0type>{}; } - $1 = &opt_string; + opt_obj = static_cast(typed_ptr); + $1 = typed_ptr; } +%typemap(free) const osgeo::proj::util::optional & (void *opt_obj) { + delete static_cast *>(opt_obj$argnum); +} +#endif -%typemap(ts) osgeo::proj::util::optional, const osgeo::proj::util::optional & "string"; +%typemap(ts) osgeo::proj::util::optional, const osgeo::proj::util::optional & "$typemap(ts, $T0type)[]"; // Return value, plain object, conversion by copying -%typemap(out) osgeo::proj::util::optional { +%typemap(out) osgeo::proj::util::optional { if ($1.has_value()) { - $typemap(out, std::string, 1=(*$1), result=$result, argnum=$argnum); + $typemap(out, $T0type, 1=(*$1), result=$result, argnum=$argnum); } else { $result = env.Null(); } } +// Return value, const reference, conversion by wrapping a constant object +%typemap(out) const osgeo::proj::util::optional & { + if ($1->has_value()) { + $typemap(out, const $T0type &, 1=&(*$1), result=$result, argnum=$argnum); + } else { + $result = env.Null(); + } +} +// string and double are special cases, these are copied %typemap(out) const osgeo::proj::util::optional & { if ($1->has_value()) { $typemap(out, const std::string &, 1=(*$1), result=$result, argnum=$argnum); @@ -34,3 +55,10 @@ $result = env.Null(); } } +%typemap(out) const osgeo::proj::util::optional & { + if ($1->has_value()) { + $typemap(out, double, 1=(**$1), result=$result, argnum=$argnum); + } else { + $result = env.Null(); + } +} diff --git a/test/shared/metadata.test.ts b/test/shared/metadata.test.ts index 376a17a..4267224 100644 --- a/test/shared/metadata.test.ts +++ b/test/shared/metadata.test.ts @@ -25,7 +25,7 @@ describe('metadata with automatic import', () => { assert.instanceOf(m, PROJ.Identifier); assert.instanceOf(m, PROJ.BaseObject); assert.isString(m.code()); - assert.isNotNull(m.authority()); + assert.isNull(m.authority()); } }); From 0a579736ed69aa381cd8340611e54c495c874715 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 17:10:26 +0200 Subject: [PATCH 4/9] fully generic optional --- src/optional.i | 52 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/optional.i b/src/optional.i index f62f17d..e2820bb 100644 --- a/src/optional.i +++ b/src/optional.i @@ -1,36 +1,58 @@ // osgeo::proj::util::optional +/* + * Input arguments + */ + // Input argument, plain object, conversion by copying using the underlying object typemap %typemap(in) osgeo::proj::util::optional { if (!$input.IsNull()) { - $T0type opt_obj; - $typemap(in, $T0type, input=$input, 1=opt_obj, argnum=$argnum); - $1 = osgeo::proj::util::optional<$T0type>{opt_obj}; + $T0type obj; + $typemap(in, $T0type, input=$input, 1=obj, argnum=$argnum); + $1 = osgeo::proj::util::optional<$T0type>{obj}; } } -// Input argument, const reference, conversion by copying, the extra -// step is needed because local variables do not support $T0type expansion -#if 0 -// This is a huge problem because some types are not copyable -%typemap(in) const osgeo::proj::util::optional & (void *opt_obj) { +// Input argument, const reference, conversion by constructing an 'optional' +// around the object held by JS, the extra step is needed because local +// variables do not support $T0type expansion +// (some PROJ objects do not support operator=) +%typemap(in) const osgeo::proj::util::optional & (void *to_delete) { osgeo::proj::util::optional<$T0type> *typed_ptr; if (!$input.IsNull()) { - $T0type opt_obj; - $typemap(in, $T0type, input=$input, 1=opt_obj, argnum=$argnum); - typed_ptr = new osgeo::proj::util::optional<$T0type>{opt_obj}; + $T0type *obj; + $typemap(in, const $T0type &, input=$input, 1=obj, argnum=$argnum); + typed_ptr = new osgeo::proj::util::optional<$T0type>{*obj}; } else { typed_ptr = new osgeo::proj::util::optional<$T0type>{}; } - opt_obj = static_cast(typed_ptr); + to_delete = static_cast(typed_ptr); $1 = typed_ptr; } -%typemap(free) const osgeo::proj::util::optional & (void *opt_obj) { - delete static_cast *>(opt_obj$argnum); +%typemap(freearg) const osgeo::proj::util::optional & { + delete static_cast *>(to_delete$argnum); +} + +// string and double are special cases, these are copied +%typemap(in) const osgeo::proj::util::optional & (osgeo::proj::util::optional opt_string) { + if (!$input.IsNull()) { + $typemap(in, std::string, input=$input, 1=opt_string, argnum=$argnum); + } + $1 = &opt_string; +} +%typemap(in) const osgeo::proj::util::optional & (osgeo::proj::util::optional opt_double) { + if (!$input.IsNull()) { + $typemap(in, double, input=$input, 1=opt_double, argnum=$argnum); + } + $1 = &opt_double; } -#endif +%typemap(freearg) const osgeo::proj::util::optional &, const osgeo::proj::util::optional & "" %typemap(ts) osgeo::proj::util::optional, const osgeo::proj::util::optional & "$typemap(ts, $T0type)[]"; +/* + * Return values + */ + // Return value, plain object, conversion by copying %typemap(out) osgeo::proj::util::optional { if ($1.has_value()) { From 921e68529a9ce2d1f8512307c041b0fc025b7ab8 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 17:32:26 +0200 Subject: [PATCH 5/9] simplify the optional typemap using $*1_ltype --- src/optional.i | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/optional.i b/src/optional.i index e2820bb..03327c7 100644 --- a/src/optional.i +++ b/src/optional.i @@ -15,21 +15,16 @@ // Input argument, const reference, conversion by constructing an 'optional' // around the object held by JS, the extra step is needed because local // variables do not support $T0type expansion -// (some PROJ objects do not support operator=) -%typemap(in) const osgeo::proj::util::optional & (void *to_delete) { - osgeo::proj::util::optional<$T0type> *typed_ptr; +// (some PROJ objects do not support operator=, thus the unique_ptr gymnastics) +%typemap(in) const osgeo::proj::util::optional & (std::unique_ptr<$*1_ltype> opt_object) { if (!$input.IsNull()) { $T0type *obj; $typemap(in, const $T0type &, input=$input, 1=obj, argnum=$argnum); - typed_ptr = new osgeo::proj::util::optional<$T0type>{*obj}; + opt_object = std::make_unique<$*1_ltype>(*obj); } else { - typed_ptr = new osgeo::proj::util::optional<$T0type>{}; + opt_object = std::make_unique<$*1_ltype>(); } - to_delete = static_cast(typed_ptr); - $1 = typed_ptr; -} -%typemap(freearg) const osgeo::proj::util::optional & { - delete static_cast *>(to_delete$argnum); + $1 = opt_object.get(); } // string and double are special cases, these are copied @@ -45,7 +40,6 @@ } $1 = &opt_double; } -%typemap(freearg) const osgeo::proj::util::optional &, const osgeo::proj::util::optional & "" %typemap(ts) osgeo::proj::util::optional, const osgeo::proj::util::optional & "$typemap(ts, $T0type)[]"; From 038ff78ea3d0b152c736b540024aa09362aa4682 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 17:32:38 +0200 Subject: [PATCH 6/9] use colored YES/NO --- meson.build | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index a7117be..6ea2a75 100644 --- a/meson.build +++ b/meson.build @@ -52,10 +52,10 @@ endif # Build PROJ and its dependencies cmake = import('cmake') summary({ - 'libcurl enabled' : enable_curl, - 'libtiff enabled' : enable_tiff, - 'inline proj.db' : inline_projdb -}) + 'libcurl' : enable_curl, + 'libtiff' : enable_tiff, + 'inline proj.db' : inline_projdb +}, bool_yn: true) if inline_projdb add_global_link_arguments([ From ab34fede29d477f24cce865831cad8ffcbbbf7ad Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 17:34:16 +0200 Subject: [PATCH 7/9] final version --- src/optional.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/optional.i b/src/optional.i index 03327c7..9e303bd 100644 --- a/src/optional.i +++ b/src/optional.i @@ -15,7 +15,7 @@ // Input argument, const reference, conversion by constructing an 'optional' // around the object held by JS, the extra step is needed because local // variables do not support $T0type expansion -// (some PROJ objects do not support operator=, thus the unique_ptr gymnastics) +// (DataEpoch & Measure do not support operator=, thus the unique_ptr gymnastics) %typemap(in) const osgeo::proj::util::optional & (std::unique_ptr<$*1_ltype> opt_object) { if (!$input.IsNull()) { $T0type *obj; From 83755ce322c09b5d4fc40085503daf20bddb3167 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 17:41:01 +0200 Subject: [PATCH 8/9] this is not a problem anymore --- src/optional.i | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/optional.i b/src/optional.i index 9e303bd..fe4d66e 100644 --- a/src/optional.i +++ b/src/optional.i @@ -13,8 +13,7 @@ } } // Input argument, const reference, conversion by constructing an 'optional' -// around the object held by JS, the extra step is needed because local -// variables do not support $T0type expansion +// around the object held by JS // (DataEpoch & Measure do not support operator=, thus the unique_ptr gymnastics) %typemap(in) const osgeo::proj::util::optional & (std::unique_ptr<$*1_ltype> opt_object) { if (!$input.IsNull()) { From 29f37f4f20569bc2986b8b823ea8898f52f79685 Mon Sep 17 00:00:00 2001 From: Momtchil Momtchev Date: Thu, 17 Oct 2024 18:26:42 +0200 Subject: [PATCH 9/9] fix optional returning an array in TS and test one string --- src/optional.i | 2 +- test/shared/metadata.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/optional.i b/src/optional.i index fe4d66e..d9b694a 100644 --- a/src/optional.i +++ b/src/optional.i @@ -40,7 +40,7 @@ $1 = &opt_double; } -%typemap(ts) osgeo::proj::util::optional, const osgeo::proj::util::optional & "$typemap(ts, $T0type)[]"; +%typemap(ts) osgeo::proj::util::optional, const osgeo::proj::util::optional & "$typemap(ts, $T0type)"; /* * Return values diff --git a/test/shared/metadata.test.ts b/test/shared/metadata.test.ts index 4267224..afb835f 100644 --- a/test/shared/metadata.test.ts +++ b/test/shared/metadata.test.ts @@ -17,6 +17,11 @@ describe('metadata with automatic import', () => { authFactoryEPSG = PROJ.AuthorityFactory.create(dbContext, 'EPSG'); }); + it('static properties', () => { + assert.isString(PROJ.Identifier.AUTHORITY_KEY); + assert.isString(PROJ.Identifier.CODESPACE_KEY); + }); + it('IdentifiedObject properties', () => { const crs = authFactoryEPSG.createCoordinateReferenceSystem('3857'); const metadata = crs.identifiers(); @@ -25,7 +30,11 @@ describe('metadata with automatic import', () => { assert.instanceOf(m, PROJ.Identifier); assert.instanceOf(m, PROJ.BaseObject); assert.isString(m.code()); + assert.isString(m.codeSpace()); + assert.strictEqual(m.code(), '3857'); + assert.strictEqual(m.codeSpace(), 'EPSG'); assert.isNull(m.authority()); + assert.isNull(m.uri()); } });