bugra9 / gdal3.js

Convert raster and vector geospatial data to various formats and coordinate systems entirely in the browser.
https://gdal3.js.org
GNU Lesser General Public License v2.1
300 stars 45 forks source link

vite+vue3 gdal3.js get error: "gdal3.js:1 gdal stderr: ERROR 4: Failed to create GeoJSON datasource" #69

Closed zhangtaohua closed 4 months ago

zhangtaohua commented 4 months ago

when I use gdal3.js in a vite + vue3 project, after initGdalJs from 'gdal3.js', when using Gdal.ogr2ogr to translate I get the following errors:

image

gdal3.js:1 gdal stderr: ERROR 4: Failed to create GeoJSON datasource: /output/hk/hk.geojson: /output/hk/hk.geojson: No such file or directory gdal stderr: ERROR 1: GeoJSON driver failed to create /output/hk/hk.geojson gdal3.js:1 gdal stderr: ERROR 10: Pointer 'hDS' is NULL in 'GDALGetFileList'.

The code like this:

<script setup>
import workerUrl from 'gdal3.js/dist/package/gdal3.js?url'
import dataUrl from 'gdal3.js/dist/package/gdal3WebAssembly.data?url'
import wasmUrl from 'gdal3.js/dist/package/gdal3WebAssembly.wasm?url'
import initGdalJs from 'gdal3.js';

const paths = {
  wasm: wasmUrl,
  data: dataUrl,
  js: workerUrl,
};

initGdalJs({paths}).then((Gdal) => {
    ...
    ...

const options = [ // https://gdal.org/programs/ogr2ogr.html#description
    '-f', 'GeoJSON',
    '-t_srs', 'EPSG:4326'
];
const output = await Gdal.ogr2ogr(result.datasets[0], options); // https://gdal3.js.org/docs/module-a_ogr2ogr.html
const bytes = await Gdal.getFileBytes(output);
});
</script>
zhangtaohua commented 4 months ago

image

If you don’t create a secondary directory, you won’t get an error.