我想使用 NodeJS 中的 ogr2ogr 库将文件中的所有 geojsons 一次性转换为 shapefile。我知道可以使用 gdal cli 直接从终端完成,但我想知道如何在 Node.js 中完成。非常感谢!
我有这个代码来转换单个文件:
// Using CommonJS modules
const ogr2ogr = require('ogr2ogr').default;
const fs = require('fs') ;
// Promise API
(async() => {
// Convert path to GeoJSON.
let {data} = await ogr2ogr('/Users/MihaiB/Desktop/test_josm/test22.geojson' );
console.log(data);
let {stream} = await ogr2ogr( data, {format: 'ESRI Shapefile'}, {destination:'/Users/MihaiB/Desktop/shapefile2.shx'});
console.log(stream)
})()