# geowarp

> Super Low-Level Raster Reprojection and Resampling Library

Latest version **1.26.2** (published 2024-02-25) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install geowarp
pnpm add geowarp
yarn add geowarp
bun add geowarp
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.26.2 |
| Published | 2024-02-25 |
| First published | 2021-05-18 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 15 |
| Unpacked size | 59.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | geo, gis, image, map, maps, proj, proj4, projection, reprojection, resample, sample, warp |

## Links

- npm: https://www.npmjs.com/package/geowarp
- Repository: https://github.com/DanielJDufour/geowarp
- Homepage: https://github.com/DanielJDufour/geowarp#readme
- Issues: https://github.com/DanielJDufour/geowarp/issues
- npm.io page: https://npm.io/package/geowarp

## Dependencies (15)

- [xdim](https://npm.io/package/xdim.md) ^1.10.1
- [mediana](https://npm.io/package/mediana.md) ^2.0.0
- [segflip](https://npm.io/package/segflip.md) ^0.0.2
- [bbox-fns](https://npm.io/package/bbox-fns.md) ^0.20.2
- [fast-max](https://npm.io/package/fast-max.md) ^0.5.1
- [fast-min](https://npm.io/package/fast-min.md) ^0.4.0
- [geoaffine](https://npm.io/package/geoaffine.md) ^0.2.0
- [get-depth](https://npm.io/package/get-depth.md) ^0.0.3
- [proj-turbo](https://npm.io/package/proj-turbo.md) ^0.0.1
- [quick-resolve](https://npm.io/package/quick-resolve.md) ^0.0.1
- [reproject-bbox](https://npm.io/package/reproject-bbox.md) ^0.13.1
- [calc-image-stats](https://npm.io/package/calc-image-stats.md) ^0.9.0
- [reproject-geojson](https://npm.io/package/reproject-geojson.md) ^0.5.0
- [typed-array-ranges](https://npm.io/package/typed-array-ranges.md) ^0.0.0
- [dufour-peyton-intersection](https://npm.io/package/dufour-peyton-intersection.md) ^0.2.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.26.2 (latest) — 2024-02-25
- 1.26.1 — 2024-01-14
- 1.26.0 — 2024-01-14
- 1.25.0 — 2023-12-22
- 1.23.2 — 2023-12-22
- 1.23.1 — 2023-11-12
- 1.23.0 — 2023-08-06
- 1.22.0 — 2023-05-06
- 1.21.0 — 2023-03-07
- 1.20.0 — 2023-03-06
- 1.19.0 — 2023-02-14
- 1.18.1 — 2023-02-14
- 1.18.0 — 2023-02-04
- 1.17.0 — 2023-02-04
- 1.16.0 — 2023-01-30
- … 29 more at https://npm.io/package/geowarp/versions

## README

# geowarp
> Super Low-Level Raster Reprojection and Resampling Library

# install
```bash
npm install -S geowarp
```

# usage
```javascript
const geowarp = require("geowarp");
const proj4 = require("proj4-fully-loaded");

const result = geowarp({
  // control the level of console log output
  // set debug_level to zero to turn off console logging
  debug_level: 2,

  // reproject from an [x, y] point in the input spatial reference system
  // to an [x, y] point in the output spatial reference system
  forward: proj4("EPSG:" + in_srs, "EPSG:3857").forward,

  // reproject from an [x, y] point in the output spatial reference system
  // to an [x, y] point in the input spatial reference system
  inverse: proj4("EPSG:" + in_srs, "EPSG:3857").inverse,

  // two-dimensional array of pixel data organized by band
  // usually [ r, g, b ] or [ r, g, b, a ]
  // pixel data for each band is usually flattened,
  // so the end of one row is immediately followed by the next row
  in_data: [
    [0, 123, 123, 162, ...],
    [213, 41, 62, 124, ...],
    [84, 52, 124, 235, ...]
  ],

  // bounding box of input data (in_data)
  // in [xmin, ymin, xmax, ymax] format
  in_bbox: [ -122.51, 40.97, -122.34, 41.11 ],

  // layout of the in_data using xdim layout syntax
  // see: https://github.com/danieljdufour/xdim
  in_layout: "[band][row,column]",

  // a number or array of numbers
  in_no_data: -99,

  // a number or string representing the spatial reference system of the input data
  // could be 4326 or "EPSG:4326"
  in_srs: 4326,

  // only necessary when in_data is skewed or rotated
  // 6-parameter geotransform using the order from https://gdal.org/tutorials/geotransforms_tut.html
  in_geotransform: [337934.48363, -0.142999, -0.576775, 7840518.4648, -0.57677, 0.14299],

  // how many pixels wide the input data is
  in_width: 1032,

  // how many pixels tall the input data is
  in_height: 1015,

  // optional array of constructor names for each array level
  // default is to use Array (untyped) for everything
  out_array_types: ["Array", "Array", "Uint8Array"],

  // optional array for sampling and/or changing band order
  // array is the order of the bands in the output with numbers
  // indicating the band index in the input (starting at zero)
  // for example, [13, 12, 11] skips the first 11 bands,
  // and takes the 12th, 13th, and 14th in reverse order
  out_bands: [13, 12, 11],

  // bounding box of output
  // this is the space that you want to paint
  // in same format as in_bbox
  out_bbox: [-13638811.83098057, 5028944.964938315, -13619243.951739563, 5028944.964938315],

  // optional
  // single or multi-dimensional array that will hold the output
  out_data: [[[[],[],[],...],[[],[],[],...],[[],[],[],...],[[],[],[],...],...]],

  // optional, default is null
  // the no data value for your output data
  out_no_data: -99,

  // layout of the result using xdim layout syntax
  // see: https://github.com/danieljdufour/xdim
  out_layout: "[row][column][band]",

  // a number or string representing the spatial reference system of the input data
  // could be 4326 or "EPSG:4326"
  out_srs: 3857,

  // optional
  // number of bands in the output
  out_pixel_depth: 3,

  // height of the output image in pixels
  out_height: 256,

  // width of the output image in pixels
  out_width: 256,

  // horizontal and vertical resolution
  // resolution of [0.25, 0.25] (i.e. 25%) means that you sample once for every 4 x 4 pixels
  // this is useful if you need your output to be a certain height or width (like 256 x 256)
  // but don't necessarily want to render data at that high resolution
  out_resolution: [0.5, 0.5],

  // method for sampling pixels
  // current supported methods are:
  // "near", "vectorize", "near-vectorize", "bilinear", "max", "mean", "median", "min", "mode", "mode-max", "mode-mean", "mode-median", and "mode-min"
  // you can also pass in a custom function that takes in ({ values }) and returns a number
  method: 'median',

  // round output pixel values to closest integer
  // do this if you will convert your output to a PNG or JPG
  round: true,

  // optional
  // the lowest possible pixel value considering the bit-depth of the data
  // this is used to speed up the min and mode-min resampling
  // if in_data is an array of typed arrays, this will be automatically calculated 
  theoretical_min: 0,

  // optional
  // the highest possible pixel value considering the bit-depth of the data
  // this is used to speed up the max and mode-max resampling
  // if in_data is an array of typed arrays, this will be automatically calculated 
  theoretical_max: 255,

  // optional
  // band math expression that maps a pixel from the read bands to the output
  // if expr is async (i.e. returns a promise), geowarp will return a promise
  expr: ({ pixel }) => {
    // clamp values above 100
    return pixel.map(value => Math.min(value, 100));
  },

  // optional
  // whether to insert or skip null values
  // "skip" - default, don't insert null values
  // "insert" - try to insert null values into output data
  insert_null_strategy: "skip",

  // optional
  // array of band indexes to read from
  // use this if your expr function only uses select bands
  read_bands: [0, 1, 2],
  
  // optional
  // polygon or multi-polygons defining areas to cut out (everything outside becomes no data)
  // terminology taken from https://gdal.org/programs/gdalwarp.html
  cutline: geojson,
  
  // if you specify a cutline, this is required
  cutline_srs: 4326,
  
  // function to reproject [x, y] point from cutline_srs to out_srs
  // required if you specify a cutline and the cutline is a different srs than out_srs,
  cutline_forward: proj4("EPSG:4326", "EPSG:3857").forward,

  // optional, default is "outside"
  // cut out the pixels "inside" or "outside" the cutline
  // in other words, if your cutline_strategy is "inside",
  // geowarp will set every pixel inside your cutline geometry to out_no_data
  cutline_strategy: "inside",

  // optional, default is false
  // enable experimental turbocharging via proj-turbo
  turbo: true,

  // completely optional and not recommended
  // you don't want this in most cases
  // over-ride the default function for inserting data into the output multidimensional array
  // useful if writing to an alternative object like a canvas
  insert_pixel: ({ row, column, pixel }) => {
    context.fillStyle = toColor(pixel);
    context.fillRect(column, row, 1, 1);
  },

  // completely optional and not recommended in most cases
  // take pixel values for a given sample located by sample row and column
  // and insert into the output multidimensional array
  // by default, this will call insert_pixel
  insert_sample: ({ row, column, pixel }) => {
    const [xmin, ymin, xmax, ymax] = scalePixel([column, row], [x_scale, y_scale]);
    for (let y = ymin; y < ymax; y++) {
      for (let x = xmin; x < xmax; x++) {
        insert_pixel({ row: y, column: x, pixel });
      }
    }
  },

  // skip writing a pixel if "any" or "all" its values are no data
  // default is undefined, meaning don't skip no data values
  skip_no_data_strategy: "any"
});
```
result is
```js
{
  // a multi-dimensional array of pixel values with the structure defined by out_layout
  data: [
    [ [...], [...], [...] ], // band 1
    // ...
  ]
}
```

---
_Source: https://npm.io/package/geowarp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
