Number of drivers: {{ count }}
```
--------------------------------
### Install and Initialize gdal3.js in Node.js
Source: https://gdal3.js.org/docs/index
This snippet demonstrates how to install gdal3.js for a Node.js environment and initialize the Gdal object. This allows server-side geospatial processing using Gdal functionalities.
```bash
pnpm add gdal3.js
# or
yarn add gdal3.js
# or
npm install gdal3.js
```
```javascript
const initGdalJs = require('gdal3.js/node');
initGdalJs().then((Gdal) => {
console.log('Gdal initialized in Node.js:', Gdal);
});
```
--------------------------------
### Install and Initialize gdal3.js with Webpack
Source: https://gdal3.js.org/docs/index
This demonstrates installing gdal3.js using npm/yarn/pnpm and initializing it within a Webpack build. It includes configuring CopyWebpackPlugin to handle WASM and data files.
```bash
pnpm add gdal3.js
# or
yarn add gdal3.js
# or
npm install gdal3.js
```
```javascript
import initGdalJs from 'gdal3.js';
initGdalJs({ path: 'static' }).then((Gdal) => {
console.log('Gdal initialized with Webpack:', Gdal);
});
```
```javascript
const CopyWebpackPlugin = require('copy-webpack-plugin');
// ... inside module.exports
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: '../node_modules/gdal3.js/dist/package/gdal3WebAssembly.wasm', to: 'static' },
{ from: '../node_modules/gdal3.js/dist/package/gdal3WebAssembly.data', to: 'static' }
]
})
]
```
--------------------------------
### Get Dataset Information with GDAL.js
Source: https://gdal3.js.org/docs/module-f_getInfo
This snippet demonstrates how to open a dataset and retrieve its information using GDAL.js. It first opens a file to get a dataset object, then passes this object to `Gdal.getInfo` to obtain detailed metadata. The resulting information is then logged to the console.
```javascript
const dataset = (await Gdal.open("...")).datasets[0];
const datasetInfo = await Gdal.getInfo(dataset);
console.log(datasetInfo);
```
--------------------------------
### Get OGR Data Source Information with ogrinfo (JavaScript)
Source: https://gdal3.js.org/docs/module-a_ogrinfo
This snippet demonstrates how to use the ogrinfo function from the GDAL3.js library to retrieve information about an OGR-supported data source. It requires initializing GDAL3.js, opening a dataset, and then calling ogrinfo with the dataset object. The function returns a Promise that resolves with information about the data source.
```javascript
const Gdal = await initGdalJs();
const dataset = (await Gdal.open('data.geojson')).datasets[0];
const info = await Gdal.ogrinfo(dataset);
```
--------------------------------
### Get Output File Paths and Sizes with gdal3.js
Source: https://gdal3.js.org/docs/module-f_getOutputFiles
This snippet demonstrates how to use the `getOutputFiles` function from the gdal3.js library to retrieve information about files generated by GDAL operations. The function returns a promise resolving to an array of objects, each detailing the `path` and `size` of an output file. This functionality is primarily intended for browser environments, as it returns an empty array when run on Node.js.
```javascript
const files = await Gdal.getOutputFiles();
files.forEach((fileInfo) => {
console.log(`file path: ${fileInfo.path}, file size: ${fileInfo.size}`);
});
```
--------------------------------
### Open File with Open Options (Node.js - JavaScript)
Source: https://gdal3.js.org/docs/module-f_open
Opens a file from the Node.js filesystem with specific open options. These options are passed as an array of strings to the driver, allowing customization of how the file is read, for example, specifying column names for CSV files.
```javascript
const result = await Gdal.open('test/points.csv', ['X_POSSIBLE_NAMES=lng', 'Y_POSSIBLE_NAMES=lat']);
```
--------------------------------
### Get File Bytes
Source: https://gdal3.js.org/docs/module-f_getFileBytes
Retrieves the byte content of a file given its path. This is useful for downloading or processing file data directly.
```APIDOC
## GET /getFileBytes
### Description
Get bytes of the file.
### Method
GET
### Endpoint
/getFileBytes
### Parameters
#### Query Parameters
- **filePath** (string) - Required - The path of the file to be downloaded.
### Request Example
```
// Download file from "/output" path on the browser.
const files = await Gdal.getOutputFiles();
const filePath = files[0].path;
const fileBytes = Gdal.getFileBytes(filePath);
const fileName = filePath.split('/').pop();
saveAs(fileBytes, filename);
function saveAs(fileBytes, fileName) {
const blob = new Blob([fileBytes]);
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = fileName;
link.click();
}
```
### Response
#### Success Response (200)
- **data** (Uint8Array) - An array of bytes representing the file content.
#### Response Example
```json
{
"data": "Uint8Array of file bytes"
}
```
```
--------------------------------
### Get Raster Dataset Information using GDAL JS gdalinfo
Source: https://gdal3.js.org/docs/module-a_gdalinfo
This function retrieves detailed information about a GDAL-supported raster dataset. It requires the GDAL JS library to be initialized and a dataset object obtained through Gdal.open(). The function returns a promise that resolves with an object containing various dataset properties.
```javascript
const Gdal = await initGdalJs();
const dataset = (await Gdal.open('data.tif')).datasets[0];
const info = await Gdal.gdalinfo(dataset);
```
--------------------------------
### Get Dataset Information with GDAL3.js
Source: https://gdal3.js.org/docs/index
Retrieves detailed information about opened geospatial datasets using GDAL3.js. This function is applicable to both vector and raster datasets, providing insights into their structure and properties.
```javascript
/* ======== Dataset Info ======== */
// https://gdal3.js.org/docs/module-f_getInfo.html
const mbTilesDatasetInfo = await Gdal.getInfo(mbTilesDataset); // Vector
const tifDatasetInfo = await Gdal.getInfo(tifDataset); // Raster
```
--------------------------------
### Get File Bytes with GDAL3.js and Save to Browser
Source: https://gdal3.js.org/docs/module-f_getFileBytes
Retrieves the byte array of a file specified by its path using `Gdal.getFileBytes`. The returned byte array can then be used to create a downloadable file in the browser using a helper function `saveAs`. This function is useful for client-side file manipulation and download.
```javascript
const files = await Gdal.getOutputFiles();
const filePath = files[0].path;
const fileBytes = Gdal.getFileBytes(filePath);
const fileName = filePath.split('/').pop();
saveAs(fileBytes, filename);
function saveAs(fileBytes, fileName) {
const blob = new Blob([fileBytes]);
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = fileName;
link.click();
}
```
--------------------------------
### Initialize GDAL3.js and Open Datasets
Source: https://gdal3.js.org/docs/index
Initializes the GDAL3.js library and opens multiple datasets, including MBTiles and GeoTIFF formats. It returns dataset objects that can be further processed. Assumes the existence of 'a.mbtiles' and 'b.tif' files.
```javascript
const Gdal = await initGdalJs();
const files = ['a.mbtiles', 'b.tif']; // [Vector, Raster]
const result = await Gdal.open(files); // https://gdal3.js.org/docs/module-f_open.html
const mbTilesDataset = result.datasets[0];
const tifDataset = result.datasets[1];
```
--------------------------------
### Open File with Virtual File System Handler (JavaScript)
Source: https://gdal3.js.org/docs/module-f_open
Opens a file using a specified virtual file system (VFS) handler, such as `/vsizip/` for zip archives. This is useful for accessing files within archives or other virtual file systems without extracting them. It accepts the file path, an empty options array, and the VFS handler.
```javascript
const result = await Gdal.open(file, [], ['vsizip']);
```
--------------------------------
### Initialize gdal3.js via Local Script Tag
Source: https://gdal3.js.org/docs/index
This code illustrates how to include gdal3.js locally and initialize the Gdal object. Ensure the 'gdal3.js' file is correctly linked in your HTML.
```html
```
--------------------------------
### Open Single File from Node.js Filesystem (JavaScript)
Source: https://gdal3.js.org/docs/module-f_open
Opens a single file directly from the Node.js filesystem. This method is straightforward, taking a file path string as an argument. It returns a Promise that resolves to a dataset list.
```javascript
const result = await Gdal.open('test/polygon.geojson');
```
--------------------------------
### Initialize gdal3.js via CDN (No Worker)
Source: https://gdal3.js.org/docs/index
This snippet demonstrates how to include gdal3.js using a CDN and initialize it without using a web worker. This method is suitable for direct browser integration but may not be compatible with web worker environments.
```html
```
--------------------------------
### FileInfo Type Definition
Source: https://gdal3.js.org/docs/TypeDefs
Defines the structure for basic file information, including its path and size.
```APIDOC
## FileInfo Type Definition
### Description
Provides basic information about a file, such as its local path and size in bytes.
### Type
`Object`
### Properties
- **`path`** (`string`) - Local path of the opened file.
- **`size`** (`number`) - File size in bytes.
```
--------------------------------
### FilePath Type Definition
Source: https://gdal3.js.org/docs/TypeDefs
Defines the structure for file paths, including local, real, and potentially all available paths.
```APIDOC
## FilePath Type Definition
### Description
Represents file path information, including the local path, the real (temporary) path, and an optional nested structure for all file paths.
### Type
`Object`
### Properties
- **`local`** (`string`) - Local path of the file. Example: `/output/polygon-line-point.mbtiles`
- **`real`** (`string`) - Real (temporary) path of the file. Example: `/tmp/gdaljsGClKZk/polygon-line-point.mbtiles`
- **`all`** (`FilePath`) - An optional, nested object containing all file paths.
```
--------------------------------
### Open Multiple Files from Node.js Filesystem (JavaScript)
Source: https://gdal3.js.org/docs/module-f_open
Opens multiple files from the Node.js filesystem simultaneously. The file paths are provided as an array of strings to the `Gdal.open()` function. This enables batch processing of multiple datasets.
```javascript
const result = await Gdal.open(['test/polygon.geojson', 'test/line.geojson']);
```
--------------------------------
### Open Network File (JavaScript)
Source: https://gdal3.js.org/docs/module-f_open
Opens a file fetched from a network URL. The file content is obtained using `fetch`, converted to a Blob, and then created as a `File` object before being passed to `Gdal.open()`. This allows processing of remote files as if they were local.
```javascript
const fileData = await fetch('test/polygon.geojson');
const file = new File([await fileData.blob()], "polygon.geojson");
const result = await Gdal.open(file);
```
--------------------------------
### ogrinfo
Source: https://gdal3.js.org/docs/module-a_ogrinfo
Lists various information about an OGR-supported data source to stdout. It also allows editing data by executing SQL statements.
```APIDOC
## ogrinfo
### Description
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.
### Method
`POST`
### Endpoint
`/websites/gdal3_js/ogrinfo`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **dataset** (TypeDefs.Dataset) - Required - The dataset to get information from.
- **options** (Array) - Optional - An array of options to configure the ogrinfo command.
### Request Example
```json
{
"dataset": "dataset_object",
"options": ["option1", "option2"]
}
```
### Response
#### Success Response (200)
- **Promise.