JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 36949
  • Score
    100M100P100Q242924F
  • License MIT

Reference Implementation of the Dufour-Peyton Intersection Algorithm. Calculates the Intersections of Arbitrary Polygons with a Geospatial Raster.

Package Exports

  • dufour-peyton-intersection
  • dufour-peyton-intersection/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dufour-peyton-intersection) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dufour-peyton-intersection

Reference Implementation of the Dufour-Peyton Intersection Algorithm. Calculates the Intersections of Arbitrary Polygons with a Geospatial Raster. Originally developed for geoblaze.

features

  • supports very large rasters because speed determined by number of geometry vertices
  • avoids double counting pixels in overlapping polygons
  • supports multi-polygons
  • supports overlapping holes

install

npm install dufour-peyton-intersection

usage

import dufour_peyton_intersection from "dufour-peyton-intersection";

const result = dufour_peyton_intersection.calculate({
  // bounding box of raster in format [xmin, ymin, xmax, ymax]
  raster_bbox: [ 69.15892987765864, 1.4638624159537426, 90.43900703997244, 11.81870408668788],

  // height of the raster in pixels
  raster_height: 472,

  // width of the raster in pixels
  raster_width: 970,

  // height of each pixel in the spatial reference system
  // in the example below, height is in degrees
  pixel_height: 0.02193822387867402,

  // width of each pixel in the spatial reference system
  // in the example below, width is in degrees
  pixel_width: 0.02193822387867402,

  // a GeoJSON
  // currently, this algorithm only support the following geometry types: Polygon and MultiPolygon
  geometry: geojson,

  // callback function run on each horizontal strip of consecutive intersecting pixels
  per_row_segment: ({ row, columns }) => {
    console.log("row index is (starting from zero):", row);
    const [start, end] = columns;
    console.log(`columns range is inclusive, starting at column ${start} and ending at column ${end}`);
  },

  // callback function run on each raster pixel that intersects the geometry
  per_pixel: ({ row, column }) => {
    console.log("we found a raster pixel that intersects the geometry at");
    console.log("row (from top to bottom): " + row);
    console.log("column (from left to right): " + column)
  }
});

calculate returns the following object:

{
  rows: [
    <91 empty items>, // empty rows mean that the geometry does not intersect these raster rows 
    [ [ 500, 504 ] ], // 5 pixels (500 to 504) in row 92 (zero-index) intersect the geometry
    [ [ 491, 505 ] ],
    [ [ 490, 499 ], [ 501, 505 ] ], // two parts of the geometry intersect this row and are separated by 1 pixel at index 500
    [ [ 487, 506 ] ],
    ... 380 more items
  ]
}

used by

  • geoblaze: blazing fast raster statistics engine
  • geomask: low-level geospatial masking functions