Skip to content

Commit

Permalink
CoordinateSystem, almost good on first try
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Oct 18, 2024
1 parent 0ec6488 commit 9bbd22c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/coordinatesystem.i
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
%nn_shared_ptr(osgeo::proj::cs::DateTimeTemporalCS)
%nn_shared_ptr(osgeo::proj::cs::TemporalCountCS)
%nn_shared_ptr(osgeo::proj::cs::TemporalMeasureCS)

// Meridian is nullable when not an nn pointer
%typemap(ts) osgeo::proj::cs::MeridianPtr "Meridian | null";
%typemap(ts) const osgeo::proj::cs::MeridianPtr & "Meridian | null";
5 changes: 5 additions & 0 deletions src/optional.i
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
}
}
// Return value, const reference, conversion by wrapping a constant object
// This typemap is not entirely safe because we wrap an existing object
// Normally, this object would be part of its parent object, but this
// object can be garbage-collected and if the user decides to keep its
// copy, this will be a dangling pointer
// The only safe way to do it is to always copy each object
%typemap(out) const osgeo::proj::util::optional & {
if ($1->has_value()) {
$typemap(out, const $T0type &, 1=&(*$1), result=$result, argnum=$argnum);
Expand Down
75 changes: 75 additions & 0 deletions test/shared/cs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { assert } from 'chai';

import qPROJ from 'proj.js';
import type * as PROJ from 'proj.js';

describe('CoordinateSystem with automatic import', () => {
let PROJ: Awaited<typeof qPROJ>;

let dbContext: PROJ.DatabaseContext;
let authFactory: PROJ.AuthorityFactory;
let authFactoryEPSG: PROJ.AuthorityFactory;
let crs: PROJ.CRS;
let geoCRS: PROJ.GeographicCRS;

before('init', async () => {
PROJ = await qPROJ;
dbContext = PROJ.DatabaseContext.create();
authFactory = PROJ.AuthorityFactory.create(dbContext, 'string');
authFactoryEPSG = PROJ.AuthorityFactory.create(dbContext, 'EPSG');
crs = authFactoryEPSG.createCoordinateReferenceSystem('3857');
geoCRS = crs.extractGeographicCRS();
});

it('class constructor inheritance', () => {
assert.instanceOf(PROJ.EllipsoidalCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.SphericalCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.CartesianCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.VerticalCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.AffineCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.OrdinalCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.ParametricCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.TemporalCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.DateTimeTemporalCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.TemporalCS, PROJ.CoordinateSystem.constructor);
assert.instanceOf(PROJ.TemporalMeasureCS, PROJ.CoordinateSystem.constructor);
});

it('static properties', () => {
assert.instanceOf(PROJ.AxisDirection.NORTH, PROJ.AxisDirection);
assert.instanceOf(PROJ.RangeMeaning.EXACT, PROJ.RangeMeaning);
});

it('extract CoordinateSystem', () => {
const cs = geoCRS.coordinateSystem();
assert.instanceOf(cs, PROJ.BaseObject);
assert.instanceOf(cs, PROJ.CoordinateSystem);
assert.instanceOf(cs, PROJ.EllipsoidalCS);
});

it('CoordinateSystemAxis', () => {
const cs = geoCRS.coordinateSystem();
const axis = cs.axisList();
assert.isArray(axis);
assert.isAbove(axis.length, 0);
axis.forEach((ax) => {
assert.instanceOf(ax, PROJ.CoordinateSystemAxis);
if (ax.meridian() !== null)
assert.instanceOf(ax.meridian(), PROJ.Meridian);
assert.instanceOf(ax.name(), PROJ.Identifier);
assert.instanceOf(ax.unit(), PROJ.UnitOfMeasure);
});
});

it('create w/ PropertyMap', () => {
// TODO: PropertyMap can be an automatic JS object
const pmap = new PROJ.PropertyMap();
pmap.set(PROJ.Identifier.CODE_KEY, '1337');
pmap.set(PROJ.Identifier.AUTHORITY_KEY, 'DeadCow');
pmap.set(PROJ.Identifier.EPSG, false);
const axis = PROJ.CoordinateSystemAxis.create(pmap, 'axis', PROJ.AxisDirection.NORTH_EAST, PROJ.UnitOfMeasure.METRE, null);
assert.instanceOf(axis, PROJ.CoordinateSystemAxis);
assert.isNull(axis.meridian());
assert.isTrue(axis.unit().equal(PROJ.UnitOfMeasure.METRE));
});
});

0 comments on commit 9bbd22c

Please sign in to comment.