# geoaffine

> GeoSpatial Affine Transformations for Humans

Latest version **0.2.0** (published 2023-05-01) · CC0-1.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2023-05-01 |
| First published | 2023-04-27 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | affine, crs, gdal, geospatial, geotransform, project, srs, transform |

## Links

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

## Dependencies (1)

- [preciso](https://npm.io/package/preciso.md) ^0.11.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2023-05-01
- 0.1.0 — 2023-04-29
- 0.0.1 — 2023-04-27

## README

# geoaffine
> GeoSpatial Affine Transformations for Humans

## install
```bash
npm install geoaffine
```

## basic usage
This library supports [Geotransforms](https://gdal.org/tutorials/geotransforms_tut.html).
```js
// or import Geotransform from "geoaffine/Geotransform.js";
import { Geotransform } from "geoaffine";

const geotransform = [337934.4836350695, -0.14299987236417117, -0.5767759114507439, 7840518.464866471, -0.5767759114507457, 0.14299987236414916];

const { forward, inverse } = Geotransform(geotransform);

// convert pixel at origin (top-left corner) to coordinates in spatial reference system 
forward([0, 0]);
[337934.4836350695, 7840518.464866471]

// convert point 200 pixels right and 100 pixels down
forward([200, 100]);
[337862.50605668797, 7840475.087262562]

// reverse above
inverse([337862.50605668797, 7840475.087262562], { floor: true })
[100, 100]
```

## advanced usage
### ModelTransform
GeoTIFF [ModelTransformationTag](https://www.awaresystems.be/imaging/tiff/tifftags/modeltransformationtag.html) defines a 4x4 matrix of 16 parameters.
```js
// or import ModelTransform from "geoaffine/ModelTransform.js";
import { ModelTransform } from "geoaffine";

const matrix = [
  -0.14299987236417117, -0.5767759114507439,  0,   337934.4836350695,
  -0.5767759114507457,  0.14299987236414916,  0,   7840518.464866471,
  0,                    0,                    0,   0,
  0,                    0,                    0,   1
];

const { forward, inverse } = ModelTransform(matrix);

forward([2000, 2000]);
[336494.93206743966, 7839650.912788298]

inverse([336780.9318121680122, 7840804.46461119929832], { floor: true })
[0, 2000]
```

### arbitrary precision
In order to avoid floating point arithmetic issues, you can use PreciseGeotransform and PreciseModelTransform,
which use [preciso](https://github.com/danieljdufour/preciso) for mathematical calculations.
```js
// or import PreciseGeotransform from "geoaffine/precise/Geotransform.js";
import { PreciseGeotransform } from "geoaffine";

// or import PreciseModelTransform from "geoaffine/precise/ModelTransform.js";
import { PreciseModelTransform } from "geoaffine";

const geotransform = [337934.4836350695, -0.14299987236417117, -0.5767759114507439, 7840518.464866471, -0.5767759114507457, 0.14299987236414916];

const { forward, inverse } = PreciseGeotransform(geotransform);

forward([33.125, 67.825])
const xy = ["337890.62693810329012497625", "7840509.0581307472924654645"]

inverse(xy)
["33.125", "67.825"]

inverse(xy, { floor: true })
["33", "67"]
```


## References:
- https://gdal.org/tutorials/geotransforms_tut.html
- https://en.wikipedia.org/wiki/World_file

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