Low-Level GeoSpatial Masking Functions

Overview

geomask

Low-Level GeoSpatial Masking Functions

features

  • calculate raster pixels inside and outside a geometry mask
  • built-in reprojection support for almost all projections (thanks to proj4-fully-loaded)
  • lite build for advanced usage

install

npm install geomask

usage

calculating interior pixels

In order to calculate the pixels that are inside a masking geometry:

import geomask from "geomask";

// calculate the horizontal segments of pixels
// that fall within the masking geometry
const { rows } = geomask.inside({
  // bounding box in projection of the raster
  // in this case, Web Mercator
  raster_bbox: [
    7698736.857788673, // xmin
    163239.83797837654, // ymin
    10066450.245949663, // xmax
    1325082.6679127468 // ymax
  ],

  // spatial reference system of the raster
  // 3857 is the EPSG code for Web Mercator
  raster_srs: 3857,

  // height of the raster
  raster_height: 475,

  // width of the raster
  raster_width: 968,

  // optional height of pixel in srs units
  pixel_height: 2445.98490512499,

  // optional width of pixel in srs units
  pixel_width: 2445.9849051249894,

  // a masking geometry in GeoJSON format
  // currently, only Polygon and MultiPolygon geometries are supported
  // in the example below, we see a GeoJSON Feature Collection of Polygon Features
  mask: { type: "FeatureCollection", features: [...] },

  // the standard projection used by GeoJSON
  mask_srs: 4326
});

rows is a multi-dimensional array where each row includes the ranges of pixels inside the mask

[
  <92 empty items>, // the top 92 rows of the raster don't intersect the geometry mask
  [ [ 500, 500 ] ], // only 1 pixel in this row falls within the geometry mask
  [ [ 499, 501 ] ], // 3 pixels in this row fall within the mask, pixels with index 499, 500 and 501
  [ [ 499, 502 ] ], // 4 pixels from index 499 to 502 fall within the mask
  ... 380 more items
]

calculating exterior pixels

In order to calculate the pixels that are outside a masking geometry, pass in the same parameters as above to the geomask.outside function

import geomask from "geomask";

const { rows } = geomask.outside({ raster_bbox, raster_srs, raster_height, raster_width, mask, mask_srs: 4326 })

rows is a multi-dimensional array where each row includes the ranges of pixels outside the mask

[
  [ [0, 967] ], // the top rows of the raster don't intersect the geometry mask
  [ [0, 967] ], // so the outside range extends the whole width of the raster
  [ [0, 967] ],
  <90 rows of [ [0, 967] ]>
  [ [ 0, 499 ], [501, 967] ], // all but one pixel (index 500) falls outside the mask
  ... 382 more items
]

advanced usage

By default, geomask includes proj4js-definitions, a large dataset of projection information for almost all standard projections. This will add about 175kb to your bundle size. If your mask is in the same projection as your raster or don't need built-in reprojection support, you can use geomask/lite. You will use a reproject function (instead of passing in raster_srs and mask_srs).

import geomask from "geomask/lite";
import proj4 from "proj4";

geomask.inside({
  raster_bbox: [7698736.857788673, 163239.83797837654, 10066450.245949663, 1325082.6679127468 ],
  raster_height: 475,
  raster_width: 968,
  mask: { type: "FeatureCollection", features: [...] },

  // if your mask is in a different projection than your raster
  // provide a reproject function that converts an [x, y] point
  // from the geometry mask to a point in the raster projection
  reproject: proj4("EPSG:4326", "EPSG:3857").forward
})
You might also like...

Simple news reader that keeps the noise low.

Simple news reader that keeps the noise low.

Thud. Read news without the fuss · Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Prerequisites Contribut

Jan 1, 2023

A template for site builders and low-code tools.

Platforms Starter Kit The all-in-one starter kit for building platforms on Vercel. Introduction · Guide · Demo · Kitchen Sink · Contributing Deploy Yo

Jan 3, 2023

A low-feature, dependency-free and performant test runner inspired by Rust and Deno

minitest A low-feature, dependency-free and performant test runner inspired by Rust and Deno Simplicity: Use the mt test runner with the test function

Nov 12, 2022

Brickdoc is an open-source compound document-based online workspace and low-code development platform.

Brickdoc is an open-source compound document-based online workspace and low-code development platform.

Brickdoc ⚠️ Note: This software is currently under active development. Some features may be available in the future, and the API and interface may cha

Dec 20, 2022

Brickdoc is an open-source compound document-based online workspace and low-code development platform.

Brickdoc is an open-source compound document-based online workspace and low-code development platform.

Brickdoc ⚠️ Note: This software is currently under active development. Some features may be available in the future, and the API and interface may cha

Jun 17, 2022

A powerful data visualization 2D/3D large-screen editor tool with low-code.

tp-editor(2D/3D)中文说明 A topology 2D/3D editor with nodejs, express, socket.io es6, HT for Web and vite. It's a powerful large-screen data visualization

Dec 25, 2022

MashCard is an open-source all-in-one workspace and low-code development platform.

MashCard ⚠️ Note: This software is currently under active development. Some features may be available in the future, and the API and interface may cha

Dec 20, 2022

Eigen ZK-ZKRollup, Low gas-fee, better privacy-enhancement, high composable

Eigen ZK-ZKRollup, Low gas-fee, better privacy-enhancement, high composable

ZKZRU: Eigen ZK-ZKRollup Eigen ZK-ZKRollup provides confidential transaction for users with low gas cost. The ZK-Rollup is an extention of RollupNC an

Dec 22, 2022

Modern approach to Low Quality Image Placeholders (LQIP) using webp and sharp.

Modern approach to Low Quality Image Placeholders (LQIP) using webp and sharp.

lqip-modern Modern approach to Low Quality Image Placeholders (LQIP) using webp and sharp. (demo) This approach is extremely fast and produces much sm

Dec 30, 2022
Releases(v0.4.0)
  • v0.4.0(Nov 6, 2022)

  • v0.3.5(Apr 17, 2022)

  • v0.3.4(Apr 17, 2022)

  • v0.3.3(Apr 17, 2022)

  • v0.3.2(Apr 16, 2022)

  • v0.3.1(Apr 16, 2022)

  • v0.3.0(Apr 16, 2022)

  • v0.2.0(Apr 15, 2022)

    • made main prop relative ef29250
    • fixed bug with outsides calculations skipping rows outside bounds of geometry be3b8e2

    https://github.com/DanielJDufour/geomask/compare/v0.1.0...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Apr 14, 2022)

    • fixed test 61241f5
    • fix bug where pixel size wasn't being automatically calculated 998bf92

    https://github.com/DanielJDufour/geomask/compare/v0.0.1...v0.1.0

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Mar 21, 2022)

    • Merge branch 'main' of github.com:DanielJDufour/geomask into main f2e945d
    • removed advarr f980aa9
    • Update README.md fe76327
    • Update README.md 5791d66
    • Update README.md 01f440f
    • Update README.md 71f71ab
    • Update README.md 8941e30
    • Update README.md bbe4833
    • beta 65ace5e

    https://github.com/DanielJDufour/geomask/compare/f2bac50a156ffae4bae67ea123db9e6f19102d05...v0.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
Daniel J. Dufour
builds geotiff.io, geoblaze.io, georaster, georaster-layer-for-leaflet, date-extractor, geotiff-stats, and xml-utils; built code.gov, and maintains proj4js/mgrs
Daniel J. Dufour
A fully-typed, low-level, and HyperScript-like Frontend Library 🚀

A fully-typed, low-level, and HyperScript-like Frontend Library ??

Eliaz Bobadilla 5 Apr 4, 2022
Basic Implementation of a Contract Wallet in Solidity. The owner can transfer Ether/ERC20 and execute transactions via low-level calls.

Contract Wallet Basic Implementation of a Contract Wallet in Solidity. The owner can transfer Ether/ERC20 and execute transactions via low-level calls

Junho Yeo 3 Jun 18, 2022
App for displaying geospatial data on queues on the Polish-Ukrainian border.

Live app embedded here. App helps coordinate volunteer work with refugees from Ukraine on Polish-Belarusian Border. Data comes from Grupa Granica – a

null 3 Mar 10, 2022
Bertin.js is a JavaScript library for visualizing geospatial data and make thematic maps for the web.

Bertin.js is a JavaScript library for visualizing geospatial data and make thematic maps for the web. The project is under active development. Some of

Nicolas LAMBERT 229 Dec 20, 2022
Functions Recipes is a library of examples to help you getting started with Salesforce Functions and get used to their main features.

Functions Recipes Introduction Salesforce Functions lets you use the Salesforce Platform for building event-driven, elastically scalable apps and expe

Trailhead Apps 172 Dec 29, 2022
Use pulsar to make custom trading strategy that uses Flashloans at low cost. No contract deployment required.

PULSAR Pulsar is a contract that will let you execute custom call on the blockchain and let you make use of the Flasloans in your trading sequences. Y

idecentralize.finance 9 Jun 6, 2022
Low-Budget Password Strength Estimation

_________________________________________________/\/\___________________ _/\/\/\/\/\__/\/\__/\/\____/\/\/\/\__/\/\__/\/\__/\/\________/\/\/\/\___ ____

Dropbox 13.6k Dec 31, 2022
ToolJet an open-source low-code framework to build and deploy internal tools quickly without much effort from the engineering teams

ToolJet is an open-source low-code framework to build and deploy internal tools quickly without much effort from the engineering teams. You can connect to your data sources, such as databases (like PostgreSQL, MongoDB, Elasticsearch, etc), API endpoints (ToolJet supports importing OpenAPI spec & OAuth2 authorization), and external services (like Stripe, Slack, Google Sheets, Airtable) and use our pre-built UI widgets to build internal tools.

ToolJet 15.6k Jan 3, 2023
A low-quality mod made by a rookie

Unstable-Industrial A low-quality mod made by a rookie There may be many grammatical mistakes in the descriptions because of my poor English ability.I

Niruvu Rūche 3 Dec 7, 2022
Bitloops is Low-Code Workflow Orchestration platform that helps you build backend systems and APIs 10x faster.

Bitloops Bitloops is a scalable open source Firebase substitute that can support any database and workflow orchestration. We’re building Bitloops usin

Bitloops 21 Aug 9, 2022