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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@envisim/geosampling

v0.3.0

Published

Spatial sampling algorithms

Readme

npm package

@envisim/geosampling

A TypeScript library with functions for spatial sampling.

This package provides functions for various spatial sampling techniques.

Installation

npm install @envisim/geosampling

Usage

Package exposes the following entry points:

Sampling from continuous populations

You can sample fixed-size area plots within a collection of areas defined in WGS84 coordinates (e.g., forest stands, administrative regions). The model geometry for the plots is defined in planar units (meters), and the library handles placing them correctly onto the WGS84 map.

import { Feature, FeatureCollection, Polygon } from "@envisim/geojson";
import { rectangularAreaGeometry } from "@envisim/geosampling/model-geometry";
import { sampleAreaFeaturesOnAreas } from "@envisim/geosampling/sample-continuous";

// 1. Define the population area (sampling frame)
const polygon = Polygon.create([
  [
    [0, 0],
    [1, 0],
    [1, 1],
    [0, 1],
    [0, 0],
  ],
]);

const frame = FeatureCollection.newArea([new Feature(polygon, {})]);

// 2. Define the sampling unit's model geometry
const modelGeometry = rectangularAreaGeometry(10.0);

// 3. Select the sample
sampleAreaFeaturesOnAreas(frame, {
  pointSelection: "independent",
  sampleSize: 10,
  modelGeometry,
});

Explanation:

  1. We create a FeatureCollection containing the area where sampling will occur, using WGS84 longitude and latitude coordinates.
  2. We define the shape and size (model geometry) of the individual sample plots using functions like rectangularAreaGeometry. These dimensions are specified in meters.
  3. The sampleAreaFeaturesOnAreas function takes the WGS84 population areas and the meter-based model geometry options. It calculates the placement of the sample plots onto the WGS84 map, returning a new FeatureCollection containing the sampled plots with their coordinates now in WGS84. Each feature includes properties like _designWeight which might be useful for subsequent statistical analysis.

Sampling from finite populations

import { Feature, FeatureCollection, Point } from "@envisim/geojson";
// Import functions to define model geometry (in meters) and perform sampling
import { sampleSpatiallyBalanced } from "@envisim/geosampling/sample-finite";

// 1. Define the sampling frame
const frame = FeatureCollection.newPoint([
  Point.create([0, 1]),
  Point.create([1, 2]),
  Point.create([2, 3]),
  Point.create([3, 4]),
  Point.create([4, 5]),
]);

// 2. Select the sample
sampleSpatiallyBalanced(frame, {
  method: "lpm2",
  sampleSize: 2,
  spreadOn: [],
  spreadGeo: true,
});

Model geometries

import { rectangularAreaGeometry } from "@envisim/geosampling/model-geometry";
// Create a 10 x 10 meter model geometry
rectangularAreaGeometry(10.0);

Collect properties from collections

import { collectProperties } from "@envisim/geosampling/collect-properties";

Create intersect of collections

import { selectAreaIntersectsArea } from "@envisim/geosampling/select-intersects";

Point processes

import { FeatureCollection, Polygon } from "@envisim/geojson";
import { uniformPoissonPointProcess } from "@envisim/geosampling/point-processes";

const frame = FeatureCollection.newArea([]);
frame.addGeometry(
  Polygon.create([
    [
      [0, 0],
      [1, 0],
      [1, 1],
      [0, 1],
      [0, 0],
    ],
  ]),
  {},
);

// Sample points uniformly on the frame, with an intensity of .00001 points per square meter.
uniformPoissonPointProcess(frame, { intensity: 0.00001 });

Error code lists

Error code lists of geosampling procedures.