npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geoaffine

v0.2.0

Published

GeoSpatial Affine Transformations for Humans

Downloads

6,173

Readme

geoaffine

GeoSpatial Affine Transformations for Humans

install

npm install geoaffine

basic usage

This library supports Geotransforms.

// 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 defines a 4x4 matrix of 16 parameters.

// 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 for mathematical calculations.

// 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