-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import qPROJ from 'proj.js/wasm'; | ||
import assert from 'node:assert'; | ||
import { readFileSync } from 'node:fs'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { dirname, resolve } from 'node:path'; | ||
|
||
const PROJ = await qPROJ; | ||
|
||
const proj_db_path = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'lib', 'binding', 'proj', 'proj.db'); | ||
const proj_db = readFileSync(proj_db_path); | ||
if (!PROJ.proj_js_inline_projdb) | ||
PROJ.loadDatabase(proj_db); | ||
|
||
const dbContext = PROJ.DatabaseContext.create(); | ||
const authFactory = PROJ.AuthorityFactory.create(dbContext, 'string'); | ||
const coord_op_ctxt = PROJ.CoordinateOperationContext.create(authFactory, null, 0); | ||
const authFactoryEPSG = PROJ.AuthorityFactory.create(dbContext, 'EPSG'); | ||
const sourceCRS = authFactoryEPSG.createCoordinateReferenceSystem('4326'); | ||
const targetCRS = PROJ.createFromUserInput('+proj=utm +zone=31 +datum=WGS84 +type=crs', dbContext); | ||
const list = PROJ.CoordinateOperationFactory.create().createOperations(sourceCRS, targetCRS, coord_op_ctxt); | ||
|
||
const transformer = list[0].coordinateTransformer(); | ||
const c0 = new PROJ.PJ_COORD; | ||
c0.v = [49, 2, 0, 0]; | ||
const c1 = transformer.transform(c0); | ||
assert(Math.abs(c1.v[0] - 426857.988) < 1e-3); | ||
assert(Math.abs(c1.v[1] - 5427937.523) < 1e-3); | ||
|
||
PROJ.swig_em_write_profile(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
void swig_em_write_profile(); | ||
|
||
%{ | ||
#ifdef __EMSCRIPTEN__ | ||
#include <emscripten.h> | ||
// Write the execution profile used for WASM code splitting | ||
EM_JS(void, swig_em_write_profile, (), { | ||
var __write_profile = wasmExports.__write_profile; | ||
if (!__write_profile) { | ||
console.error('__write_profile not exported'); | ||
return; | ||
} | ||
|
||
var len = __write_profile(0, 0); | ||
var ptr = _malloc(len); | ||
__write_profile(ptr, len); | ||
|
||
var profile_data = HEAPU8.subarray(ptr, ptr + len); | ||
console.log(`writing profile.data, ${len} bytes`); | ||
const fs = require('fs'); | ||
fs.writeFileSync('profile.data', profile_data); | ||
|
||
_free(ptr); | ||
}); | ||
#else | ||
void swig_em_write_profile() { | ||
throw std::exception{"Not a WASM build"}; | ||
} | ||
#endif | ||
%} |