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
315 stars 48 forks source link

Where is the output of ogr2ogr going? #56

Closed bertday closed 9 months ago

bertday commented 1 year ago

Hello!

I have a very basic question I haven't been able to answer so far using the docs. When I call Gdal.ogr2ogr(file, options), where is it storing the resulting/converted data? I'm capturing the file path returned by ogr2ogr and for me it says /output/test.geojson. Where is /output?

Would greatly appreciate any pointers on this!

May also be related to #44.

mthh commented 1 year ago

The output of Gdal.ogr2ogr is written in the (virtual) file system provided by Emscripten. This virtual file system simulates a local file system, allowing applications compiled with Emscripten to write to / read from this file system as if it were a normal file system (i.e. without modification of the code to compile).

I think you can read more about this in the Emscripten documentation here or here.

bertday commented 1 year ago

That's a big help, thank you @mthh.

I think I may have gotten the wrong impression about this project and what it does. I thought I could use it in Node as a binding to ogr2ogr to do ogr2ogr-like things 😄 (Namely, convert spatial data between formats). It seems like that's still possible, but it's also somewhat sandboxed within Emscripten, which seems like it's more browser-oriented? Just wondering if I might be able to make a suggestion on some clarifying language for the README, in case this may be a bit confusing to others.

acesgrandpa commented 11 months ago

我的理解是,ogr2ogr部分以文件转文件的形式工作。如果需要文件内容,应该用二进制读取接口。 i think ogr2ogr works in the form of file to file. So if you need file content, you should use getFileBytes. 我的可用代码 codes: (nodejs-dxf2geojson) const gdal=await initGdalJs(); const datasets=(await gdal.open(dxfPath)).datasets[0]; const options = [ '-f', 'GeoJSON', ]; const outJsonPath = await gdal.ogr2ogr(datasets, options); const dataByte =await gdal.getFileBytes(outJsonPath); const result=String.fromCharCode.apply(null,dataByte);

bugra9 commented 10 months ago

Hi @rbrtmrtn,

Gdal3.js uses a virtual file system to work with any system. In Node.js you can mount the /output virtual file system to a physical file system. This is configured with the dest config parameter when initializing gdal3.js. https://gdal3.js.org/docs/global.html#initGdalJs

For example;

const Gdal = await initGdalJs({
  dest: '.'
});

Thus, the converted files will be stored in the directory you set.

I will add Node.js examples to the documentation to make it more understandable. This library aims to work on all systems. If you experience an issue that makes it difficult to run on Node.js, I can fix it.