Skip to content

Commit

Permalink
Export Emscripten Module (FS, etc.) #67
Browse files Browse the repository at this point in the history
v2.8.0
  • Loading branch information
bugra9 committed Feb 7, 2024
1 parent 7852e30 commit 9d084c6
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .info.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"licenseUrl": "http://www.gnu.org/licenses/lgpl-2.1.html"
},
{
"name": "Sqlite 3.44.2",
"name": "Sqlite 3.45.1",
"url": "https://www.sqlite.org/index.html",
"licenseUrl": "https://www.sqlite.org/copyright.html"
},
Expand All @@ -69,12 +69,12 @@
"licenseUrl": "https://chromium.googlesource.com/webm/libwebp/+/refs/heads/master/COPYING"
},
{
"name": "Expat 2.5.0",
"name": "Expat 2.6.0",
"url": "/~https://github.com/libexpat/libexpat",
"licenseUrl": "/~https://github.com/libexpat/libexpat/blob/master/expat/COPYING"
},
{
"name": "Zlib 1.2.12",
"name": "Zlib 1.3.1",
"url": "https://www.zlib.net/",
"licenseUrl": "https://www.zlib.net/zlib_license.html"
},
Expand Down
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
GDAL_VERSION = 3.8.3
SPATIALITE_VERSION = 5.1.0
SQLITE_VERSION = 3440200
SQLITE_VERSION = 3450100
GEOS_VERSION = 3.12.1
PROJ_VERSION = 9.3.1
ZLIB_VERSION = 1.3
ZLIB_VERSION = 1.3.1
TIFF_VERSION = 4.6.0
GEOTIFF_VERSION = 1.7.1
WEBP_VERSION = 1.3.2
EXPAT_VERSION = 2.5.0
EXPAT_VERSION = 2.6.0
ICONV_VERSION = 1.17

SQLITE_URL = "https://www.sqlite.org/2023/sqlite-autoconf-$(SQLITE_VERSION).tar.gz"
SQLITE_URL = "https://www.sqlite.org/2024/sqlite-autoconf-$(SQLITE_VERSION).tar.gz"
PROJ_URL = "http://download.osgeo.org/proj/proj-$(PROJ_VERSION).tar.gz"
GEOS_URL = "http://download.osgeo.org/geos/geos-$(GEOS_VERSION).tar.bz2"
SPATIALITE_URL = "http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-$(SPATIALITE_VERSION).tar.gz"
Expand Down Expand Up @@ -54,10 +54,10 @@ GDAL_SRC = $(SRC_DIR)/gdal-$(GDAL_VERSION)
gdal3.js: $(DIST_DIR)/gdal3WebAssembly.js
gdal: $(ROOT_DIR)/lib/libgdal.a

$(DIST_DIR)/gdal3WebAssembly.js: $(ROOT_DIR)/lib/libgdal.a $(ROOT_DIR)/lib/gdalinfo_lib.cpp.o
$(DIST_DIR)/gdal3WebAssembly.js: $(ROOT_DIR)/lib/libgdal.a
mkdir -p $(DIST_DIR); \
cd $(DIST_DIR); \
EMCC_CORES=4 $(EMCC) $(ROOT_DIR)/lib/libgdal.a $(ROOT_DIR)/lib/gdalinfo_lib.cpp.o $(ROOT_DIR)/lib/ogrinfo_lib.cpp.o \
EMCC_CORES=4 $(EMCC) $(ROOT_DIR)/lib/libgdal.a \
$(ROOT_DIR)/lib/libproj.a $(ROOT_DIR)/lib/libsqlite3.a $(ROOT_DIR)/lib/libz.a $(ROOT_DIR)/lib/libspatialite.a \
$(ROOT_DIR)/lib/libgeos.a $(ROOT_DIR)/lib/libgeos_c.a $(ROOT_DIR)/lib/libwebp.a $(ROOT_DIR)/lib/libsharpyuv.a $(ROOT_DIR)/lib/libwebpdemux.a \
$(ROOT_DIR)/lib/libexpat.a $(ROOT_DIR)/lib/libtiffxx.a $(ROOT_DIR)/lib/libtiff.a $(ROOT_DIR)/lib/libgeotiff.a \
Expand All @@ -66,10 +66,6 @@ $(DIST_DIR)/gdal3WebAssembly.js: $(ROOT_DIR)/lib/libgdal.a $(ROOT_DIR)/lib/gdali
--preload-file $(ROOT_DIR)/share/gdal@/usr/share/gdal \
--preload-file $(ROOT_DIR)/share/proj@/usr/share/proj;

$(ROOT_DIR)/lib/gdalinfo_lib.cpp.o: $(ROOT_DIR)/lib/libgdal.a
cp "$(GDAL_SRC)/build/apps/CMakeFiles/appslib.dir/ogrinfo_lib.cpp.o" $(ROOT_DIR)/lib/ogrinfo_lib.cpp.o; \
cp "$(GDAL_SRC)/build/apps/CMakeFiles/appslib.dir/gdalinfo_lib.cpp.o" $(ROOT_DIR)/lib/gdalinfo_lib.cpp.o;

$(ROOT_DIR)/lib/libgdal.a: $(GDAL_SRC)/build/Makefile
cd $(GDAL_SRC)/build; \
$(EMMAKE) make -j4 install;
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ PDF, PGDUMP
Note: It doesn't work with web worker.
```html
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package/gdal3.js"
integrity="sha384-XCdiemXIuf5D00dVi5q7Zcjjwhk6EqRvhL7Em9LXc8DsDglRZic5wQZCLrVZQ9+f"
src="https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package/gdal3.js"
integrity="sha384-BzpSb6YmxbpVPRLGih2K5JInaXNZXX57xLRYaXRMiIrBaLZGo2yATY2cAtQFg6eC"
crossorigin="anonymous"
></script>
```

```js
initGdalJs({ path: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package', useWorker: false }).then((Gdal) => {});
initGdalJs({ path: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package', useWorker: false }).then((Gdal) => {});
```
> Example: [/~https://github.com/bugra9/gdal3.js/tree/master/apps/example-browser](/~https://github.com/bugra9/gdal3.js/tree/master/apps/example-browser)
Expand All @@ -80,6 +80,8 @@ initGdalJs().then((Gdal) => {});
**Builder such as Webpack (Vue, React, Angular, ...)**
```bash
pnpm add gdal3.js
# or
yarn add gdal3.js
# or
npm install gdal3.js
Expand All @@ -105,6 +107,8 @@ plugins: [
**Vite + Vue3**
```bash
pnpm add gdal3.js
# or
yarn add gdal3.js
# or
npm install gdal3.js
Expand Down Expand Up @@ -137,6 +141,8 @@ initGdalJs({paths}).then((Gdal) => {

**Node**
```bash
pnpm add gdal3.js
# or
yarn add gdal3.js
# or
npm install gdal3.js
Expand Down Expand Up @@ -234,8 +240,8 @@ console.log(newCoords); // [ [ 3021629.2074563554, 4639610.441991095 ] ]
### Compiling
- Install the EMSDK, [as described here](https://emscripten.org/docs/getting_started/downloads.html)
- Install Sqlite3. ([#31](/~https://github.com/bugra9/gdal3.js/issues/31))
- Run `yarn compile` or `make`. Run `make type=debug` for debug version.
- Run `yarn build`. Run `yarn build-dev` for debug version.
- Run `pnpm install`
- Run `pnpm run build`

## License
GNU Lesser General Public License v2.1 or later
Expand All @@ -248,12 +254,12 @@ See [LICENSE](/~https://github.com/bugra9/gdal3.js/blob/master/LICENSE) to see the
- [Proj 9.3.1](/~https://github.com/OSGeo/PROJ) [(License)](/~https://github.com/OSGeo/PROJ/blob/master/COPYING)
- [Geos 3.12.1](/~https://github.com/libgeos/geos) [(License)](/~https://github.com/libgeos/geos/blob/master/COPYING)
- [Spatialite 5.1.0](https://www.gaia-gis.it/fossil/libspatialite/index) [(License)](http://www.gnu.org/licenses/lgpl-2.1.html)
- [Sqlite 3.44.2](https://www.sqlite.org/index.html) [(License)](https://www.sqlite.org/copyright.html)
- [Sqlite 3.45.1](https://www.sqlite.org/index.html) [(License)](https://www.sqlite.org/copyright.html)
- [GeoTIFF 1.7.1](/~https://github.com/OSGeo/libgeotiff) [(License)](/~https://github.com/OSGeo/libgeotiff/blob/master/libgeotiff/LICENSE)
- [Tiff 4.6.0](https://gitlab.com/libtiff/libtiff) [(License)](https://gitlab.com/libtiff/libtiff/-/blob/master/COPYRIGHT)
- [WebP 1.3.2](https://chromium.googlesource.com/webm/libwebp) [(License)](https://chromium.googlesource.com/webm/libwebp/+/refs/heads/master/COPYING)
- [Expat 2.5.0](/~https://github.com/libexpat/libexpat) [(License)](/~https://github.com/libexpat/libexpat/blob/master/expat/COPYING)
- [Zlib 1.2.12](https://www.zlib.net/) [(License)](https://www.zlib.net/zlib_license.html)
- [Expat 2.6.0](/~https://github.com/libexpat/libexpat) [(License)](/~https://github.com/libexpat/libexpat/blob/master/expat/COPYING)
- [Zlib 1.3.1](https://www.zlib.net/) [(License)](https://www.zlib.net/zlib_license.html)
- [Iconv 1.17](https://www.gnu.org/software/libiconv/) [(License)](https://www.gnu.org/software/libiconv/)

**Inspired by**
Expand Down
2 changes: 1 addition & 1 deletion apps/app-gui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gdal3.js-gui",
"version": "2.7.0",
"version": "2.8.0",
"description": "gdal3.js GUI is a open source project offering a user interface for Gdal.",
"license": "GPL-3.0-or-later",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions apps/example-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package/gdal3.js"
integrity="sha384-XCdiemXIuf5D00dVi5q7Zcjjwhk6EqRvhL7Em9LXc8DsDglRZic5wQZCLrVZQ9+f"
src="https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package/gdal3.js"
integrity="sha384-BzpSb6YmxbpVPRLGih2K5JInaXNZXX57xLRYaXRMiIrBaLZGo2yATY2cAtQFg6eC"
crossorigin="anonymous"
></script>
<script type="text/javascript" src="main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion apps/example-browser/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
document.write("Loading...");
initGdalJs({ path: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package', useWorker: false }).then((Gdal) => {
initGdalJs({ path: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package', useWorker: false }).then((Gdal) => {
const count = Object.keys(Gdal.drivers.raster).length + Object.keys(Gdal.drivers.vector).length;
document.write("Number of drivers: " + count);
console.log(Gdal.drivers);
Expand Down
2 changes: 1 addition & 1 deletion apps/example-node/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"gdal3.js": "2.7.0"
"gdal3.js": "2.8.0"
}
}
10 changes: 5 additions & 5 deletions apps/example-singlefile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package/gdal3.js"
integrity="sha384-XCdiemXIuf5D00dVi5q7Zcjjwhk6EqRvhL7Em9LXc8DsDglRZic5wQZCLrVZQ9+f"
src="https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package/gdal3.js"
integrity="sha384-BzpSb6YmxbpVPRLGih2K5JInaXNZXX57xLRYaXRMiIrBaLZGo2yATY2cAtQFg6eC"
crossorigin="anonymous"
></script>
</head>
<body>
Loading...
<script type="text/javascript">
async function start() {
const workerData = await fetch('https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package/gdal3.js');
const workerData = await fetch('https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package/gdal3.js');
const workerUrl = window.URL.createObjectURL(await workerData.blob());

const paths = {
wasm: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package/gdal3WebAssembly.wasm',
data: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.7.0/dist/package/gdal3WebAssembly.data',
wasm: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package/gdal3WebAssembly.wasm',
data: 'https://cdn.jsdelivr.net/npm/gdal3.js@2.8.0/dist/package/gdal3WebAssembly.data',
js: workerUrl,
};

Expand Down
4 changes: 3 additions & 1 deletion apps/playground-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ async function main() {
try {
const Gdal = await initGdalJs();

const result = await Gdal.open(['../../test/data/polygon-line-point.geojson', '../../test/data/simple-polygon-line-point.tif']);
const data = await fetch('https://gdal3.js.org/test/data/simple-polygon-line-point.tif').then(response => response.arrayBuffer());
Gdal.Module.FS.writeFile('/input/simple-polygon-line-point.tif', new Int8Array(data));
const result = await Gdal.open('/input/simple-polygon-line-point.tif');
console.log(result);
} catch (error) {
console.error(error);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gdal3.js",
"version": "2.7.0",
"version": "2.8.0",
"description": "gdal3.js is a port of Gdal applications (**gdal_translate**, **ogr2ogr**, **gdal_rasterize**, **gdalwarp**, **gdaltransform**) to Webassembly. It allows you to convert raster and vector geospatial data to various formats and coordinate systems.",
"license": "LGPL-2.1-or-later",
"homepage": "https://gdal3.js.org",
Expand Down Expand Up @@ -41,7 +41,7 @@
"build-src": "rollup --config rollup.config.mjs",
"build-spec": "mkdir -p build/test/specs/ && cp src/**/**/*.spec.js build/test/specs/ && cp test/*.spec.js build/test/specs/ && cp test/browser.html build/test/index.html && cp test/mocha.css build/test/mocha.css && cp test/mocha.js build/test/mocha.js && cp test/chai.js build/test/chai.js && cp -r test/data build/test/data",
"build-gui": "cd apps/app-gui && pnpm install && pnpm run build",
"build-docs": "jsdoc --configure .jsdoc.json --verbose && cp -r build/docs/gdal3.js/2.7.0/* build/docs",
"build-docs": "jsdoc --configure .jsdoc.json --verbose && cp -r build/docs/gdal3.js/2.8.0/* build/docs",
"test-node": "nyc --reporter=json --reporter=html --report-dir=./build/coverage/node mocha",
"test-browser": "karma start .karma.conf.js",
"test-coverage": "istanbul-merge --out build/coverage/coverage-final.json build/coverage/browser/coverage-final.json build/coverage/node/coverage-final.json && nyc report --reporter html -t build/coverage --report-dir build/coverage"
Expand Down
2 changes: 2 additions & 0 deletions src/allJsFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import getOutputFiles from './allJsFunctions/function/getOutputFiles';
import getFileBytes from './allJsFunctions/function/getFileBytes';

import { drivers } from './allJsFunctions/helper/drivers';
import { GDALFunctions } from './allCFunctions';

export default {
ogr2ogr,
Expand All @@ -31,4 +32,5 @@ export default {
getOutputFiles,
getFileBytes,
drivers,
Module: GDALFunctions.Module,
};
6 changes: 3 additions & 3 deletions src/allJsFunctions/function/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export default function open(fileOrFiles, openOptions = [], VFSHandlers = []) {
const externalFiles = [];
[...files].forEach((file) => {
if ((typeof file === 'string' || file instanceof String) && (
file.substr(0, INPUTPATH.length + 1) === `${INPUTPATH}/` || file.substr(0, OUTPUTPATH.length + 1) === `${OUTPUTPATH}/`
file.substring(0, INPUTPATH.length + 1) === `${INPUTPATH}/` || file.substring(0, OUTPUTPATH.length + 1) === `${OUTPUTPATH}/`
)) {
internalFiles.push({ name: file.substr(OUTPUTPATH.length + 1), internal: true });
internalFiles.push({ name: file.substring(file.indexOf('/', 1) + 1), internal: true, prefix: file.substring(0, file.indexOf('/', 1)) });
} else {
externalFiles.push(file);
}
Expand All @@ -92,7 +92,7 @@ export default function open(fileOrFiles, openOptions = [], VFSHandlers = []) {
inputResults[name].path = path;
const vfsHandlerStr = VFSHandlers && VFSHandlers.length ? `/${VFSHandlers.join('/')}/` : '';
let fileFullPath = `${vfsHandlerStr}${INPUTPATH}/${path}`;
if (mountedFiles[i].internal) fileFullPath = `${OUTPUTPATH}/${path}`;
if (mountedFiles[i].internal) fileFullPath = `${vfsHandlerStr}${mountedFiles[i].prefix}/${path}`;

const datasetPtr = GDALFunctions.GDALOpenEx(fileFullPath, null, null, optStr.ptr, null);
if (datasetPtr === 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/vector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (isNode) assert = require('chai').assert;
else assert = chai.assert;

const ignoredInputFormats = [''];
const ignoredOutputFormats = ['GeoJSON', 'S57', 'PDS4', 'PDF', 'PGDUMP', 'GPSBabel', 'OpenFileGDB'];
const ignoredOutputFormats = ['GeoJSON', 'S57', 'PDS4', 'PDF', 'PGDUMP', 'OpenFileGDB'];
const ignoredParams = [
'ESRI Shapefile-SHPT',
'CSV',
Expand Down

0 comments on commit 9d084c6

Please sign in to comment.