All files / application ogrinfo.js

76.92% Statements 10/13
66.66% Branches 2/3
66.66% Functions 2/3
76.92% Lines 10/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                1067x 1067x 1067x 1067x     1067x   1067x 1067x 1067x   1067x       1067x        
/* eslint-disable no-underscore-dangle */
/* eslint-disable camelcase */
import { GDALFunctions } from '../../allCFunctions';
import { getGdalError } from '../helper/error';
import { getOptions, clearOptions } from '../helper/options';
 
/**
    * The ogrinfo program lists various information about an OGR-supported data source to stdout (the terminal).
    * By executing SQL statements it is also possible to edit data.
    *
    * {@link https://gdal.org/programs/ogrinfo.html}
    *
    * @module a/ogrinfo
    * @async
    * @param {TypeDefs.Dataset} dataset Dataset
    * @param {Array} [options] Options ({@link https://gdal.org/programs/ogrinfo.html#description})
    * @return {Promise<Object>} "Promise" returns information about the OGR-supported data source
    * @example
    * const Gdal = await initGdalJs();
    * const dataset = (await Gdal.open('data.geojson')).datasets[0];
    * const info = await Gdal.ogrinfo(dataset);
    *
*/
export default function ogrinfo(dataset, options = []) {
    return new Promise((resolve, reject) => {
        const optStr = getOptions(['-json', ...options]);
        const config = optStr.config;
        Object.entries(config).forEach(([key, value]) => {
            GDALFunctions.CPLSetConfigOption(key, value);
        });
        const gdalInfoOptionsPtr = GDALFunctions.GDALVectorInfoOptionsNew(optStr.ptr, null);
 
        const gdalInfo = GDALFunctions.GDALVectorInfo(dataset.pointer, gdalInfoOptionsPtr);
        GDALFunctions.GDALVectorInfoOptionsFree(gdalInfoOptionsPtr);
        clearOptions(optStr);
 
        Iif (GDALFunctions.CPLGetLastErrorNo() >= 3) {
            const error = getGdalError();
            reject(error);
        } else {
            resolve(JSON.parse(gdalInfo));
        }
    });
}