const oxigdal = require('../');
const path = require('path');
async function main() {
console.log('=== OxiGDAL Basic Raster Example ===\n');
const info = oxigdal.getInfo();
console.log(`Version: ${info.version}`);
console.log(`Formats: ${info.formats.join(', ')}\n`);
console.log('Creating test raster...');
const width = 100;
const height = 100;
const dataset = oxigdal.createRaster(width, height, 3, 'float32');
dataset.setGeoTransform([
-180.0, 3.6, 0.0, 90.0, 0.0, -1.8 ]);
dataset.crs = 'EPSG:4326';
for (let bandIdx = 0; bandIdx < 3; bandIdx++) {
const buffer = new oxigdal.BufferWrapper(width, height, 'float32');
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const value = Math.sin(x / 10.0) * Math.cos(y / 10.0) * (bandIdx + 1) * 100;
buffer.setPixel(x, y, value);
}
}
dataset.writeBand(bandIdx, buffer);
console.log(`Band ${bandIdx + 1} filled with data`);
}
const metadata = dataset.getMetadata();
console.log('\nDataset Metadata:');
console.log(` Size: ${metadata.width}x${metadata.height}`);
console.log(` Bands: ${metadata.bandCount}`);
console.log(` Data Type: ${metadata.dataType}`);
console.log(` CRS: ${metadata.crs}`);
if (metadata.bounds) {
console.log(` Bounds: [${metadata.bounds.minX}, ${metadata.bounds.minY}, ${metadata.bounds.maxX}, ${metadata.bounds.maxY}]`);
}
console.log('\nBand 1 Statistics:');
const band = dataset.readBand(0);
const stats = band.statistics();
console.log(` Min: ${stats.min.toFixed(2)}`);
console.log(` Max: ${stats.max.toFixed(2)}`);
console.log(` Mean: ${stats.mean.toFixed(2)}`);
console.log(` StdDev: ${stats.stddev.toFixed(2)}`);
console.log(` Count: ${stats.count}`);
console.log('\nSample Pixels (band 1):');
const samplePoints = [[0, 0], [50, 50], [99, 99]];
for (const [x, y] of samplePoints) {
const value = band.getPixel(x, y);
const geo = dataset.pixelToGeo(x, y);
console.log(` Pixel(${x},${y}) = ${value.toFixed(2)}, Geo(${geo.x.toFixed(2)}, ${geo.y.toFixed(2)})`);
}
const outputPath = '/tmp/oxigdal_test.tif';
console.log(`\nSaving to ${outputPath}...`);
dataset.save(outputPath);
console.log('Done!');
console.log('\nVerifying saved file...');
const reopened = oxigdal.openRaster(outputPath);
console.log(` Size: ${reopened.width}x${reopened.height}`);
console.log(` Bands: ${reopened.bandCount}`);
console.log(` Type: ${reopened.dataType}`);
console.log('Verification successful!');
}
main().catch(console.error);