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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | 1083x 1083x 1083x 1083x 381x 381x 381x 381x 381x 381x 381x 381x 1524x 1524x 1524x 381x 381x 381x 381x 702x 702x 750x 750x 750x 750x 750x 702x 702x 702x 702x | /* eslint-disable no-underscore-dangle */ /* eslint-disable max-len */ import { GDALFunctions } from '../../allCFunctions'; /** * Lists information about a raster/vector dataset. * * @module f/getInfo * @async * @param {TypeDefs.Dataset} dataset Dataset * @return {Promise<TypeDefs.DatasetInfo>} "Promise" returns an object containing file information. * @example * const dataset = (await Gdal.open("...")).datasets[0]; * const datasetInfo = await Gdal.getInfo(dataset); * console.log(datasetInfo); * @example * // Raster output * { * "type": "raster", * "bandCount": 1, * "width": 514, * "height": 515, * "projectionWkt": "PROJCS[\"unnamed\",GEOGCS[\"NAD27\",DATUM[\"North_American_Datum_1927\",SPHEROID[\"Clarke 1866\",6378206.4,294.978698213898,AUTHORITY[\"EPSG\",\"7008\"]],AUTHORITY[\"EPSG\",\"6267\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4267\"]],PROJECTION[\"Cylindrical_Equal_Area\"],PARAMETER[\"standard_parallel_1\",33.75],PARAMETER[\"central_meridian\",-117.333333333333],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]", * "coordinateTransform": { * "0": -28493.166784412522, * "1": 60.02213698319374, * "2": 0, * "3": 4255884.5438021915, * "4": 0, * "5": -60.02213698319374 * }, * "corners": [ * [ * -28493.166784412522, * 4255884.5438021915 * ], * [ * 2358.211624949061, * 4255884.5438021915 * ], * [ * 2358.211624949061, * 4224973.143255847 * ], * [ * -28493.166784412522, * 4224973.143255847 * ] * ], * "driverName": "GeoTIFF", * "dsName": "/input/cea.tif" * } * @example * // Vector output * { * "type": "vector", * "layerCount": 1, * "featureCount": 2, * "layers": [ * { * "name": "polygon", * "featureCount": 2 * } * ], * "dsName": "/input/polygon.geojson", * "driverName": "GeoJSON" * } */ export default function getInfo(dataset) { return new Promise((resolve) => { const bandCount = GDALFunctions.GDALGetRasterCount(dataset.pointer); const layerCount = GDALFunctions.GDALDatasetGetLayerCount(dataset.pointer); if (bandCount > 0 && layerCount === 0) { // Raster const maxX = GDALFunctions.GDALGetRasterXSize(dataset.pointer); const maxY = GDALFunctions.GDALGetRasterYSize(dataset.pointer); const wktStr = GDALFunctions.GDALGetProjectionRef(dataset.pointer); const byteOffset = GDALFunctions.Module._malloc(6 * Float64Array.BYTES_PER_ELEMENT); GDALFunctions.GDALGetGeoTransform(dataset.pointer, byteOffset); const geoTransform = GDALFunctions.Module.HEAPF64.subarray( byteOffset / Float64Array.BYTES_PER_ELEMENT, (byteOffset / Float64Array.BYTES_PER_ELEMENT) + 6, ); const corners = [ [0, 0], [maxX, 0], [maxX, maxY], [0, maxY], ]; const geoCorners = corners.map((coords) => { const x = coords[0]; const y = coords[1]; return [ geoTransform[0] + (geoTransform[1] * x) + (geoTransform[2] * y), geoTransform[3] + (geoTransform[4] * x) + (geoTransform[5] * y), ]; }); const driverPtr = GDALFunctions.GDALGetDatasetDriver(dataset.pointer); const driverName = GDALFunctions.GDALGetDriverLongName(driverPtr); const dsName = GDALFunctions.OGR_DS_GetName(dataset.pointer); resolve(JSON.parse(JSON.stringify({ type: 'raster', bandCount, width: maxX, height: maxY, projectionWkt: wktStr, coordinateTransform: geoTransform, corners: geoCorners, driverName, dsName, }))); } else { // Vector // const layerCount2 = GDALFunctions.OGR_DS_GetLayerCount(dataset.pointer); const layers = []; for (let i = 0; i < layerCount; i += 1) { const layerPtr = GDALFunctions.OGR_DS_GetLayer(dataset.pointer, i); const layerName = GDALFunctions.OGR_L_GetName(layerPtr); const featureCount = GDALFunctions.OGR_L_GetFeatureCount(layerPtr, 1); layers.push({ name: layerName, featureCount, }); } const featureCount = layers.reduce((acc, layer) => acc + layer.featureCount, 0); const dsName = GDALFunctions.OGR_DS_GetName(dataset.pointer); const driverPtr = GDALFunctions.GDALGetDatasetDriver(dataset.pointer); const driverName = GDALFunctions.GDALGetDriverLongName(driverPtr); resolve({ type: 'vector', layerCount, featureCount, layers, dsName, driverName, }); } }); } |