observablehq / observablehq/plot

A cutoff distance in spatial interpolators?

Open
#1,431 3 comments 1 reaction 1 assignee View on GitHub

@Fil is already working on this.

Since Apr 6, 2023.

enhancement geo
Dominant language
HTML
Stars
5.4k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

When the sample data covers only a subdomain of the frame (say, land), it is sometimes desirable to avoid extending it too much into lakes and oceans. A solution is to add a cutoff distance (in "raster" pixels, like the blur option).

Left: random walk; right: random walk with a cutoff at 9px (and pixelSize: 0.5).

cutoff

This can be done in user space with custom interpolators, but seems like a simple option to offer in interpolatorNearest (which would deprecate interpolateNearest), and interpolatorRandomWalk. (I haven't looked at interpolatorBarycentric yet.)

Code patch (to be optimized to avoid Math.hypot and skip unless cutoff is specified):

- W[k] = V[index[ix]];
+ W[k] = Math.hypot(X[index[ix]] - x, Y[index[ix]] - y) <= cutoff ? V[index[ix]] : NaN;

Feature suggested by @HarryStevens

(Slightly related to a generic “clip” feature #1109 —but here we only have point samples, no geojson.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.