@carto/api-client 0.5.7-alpha.5 → 0.5.7-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "homepage": "https://github.com/CartoDB/carto-api-client#readme",
9
9
  "author": "Don McCurdy <donmccurdy@carto.com>",
10
10
  "packageManager": "yarn@4.3.1",
11
- "version": "0.5.7-alpha.5",
11
+ "version": "0.5.7-alpha.6",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  cellToChildren as _cellToChildren,
3
+ cellToBoundary,
3
4
  cellToTile,
4
5
  geometryToCells,
5
6
  getResolution,
@@ -11,7 +12,9 @@ import type {
11
12
  RasterMetadataBand,
12
13
  SpatialDataType,
13
14
  } from '../sources/types.js';
14
- import {CellSet} from '../utils/CellSet.js';
15
+ import booleanWithin from '@turf/boolean-within';
16
+ import intersect from '@turf/intersect';
17
+ import {feature, featureCollection} from '@turf/helpers';
15
18
 
16
19
  export type TileFeaturesRasterOptions = {
17
20
  tiles: RasterTile[];
@@ -44,23 +47,34 @@ export function tileFeaturesRaster({
44
47
  const tileBlockSize = tiles[0].data!.blockSize;
45
48
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
46
49
 
47
- // Compute covering cells for the spatial filter, at same resolution as the
48
- // raster pixels, to be used as a mask.
49
- const spatialFilterCells = new CellSet(
50
- geometryToCells(options.spatialFilter, cellResolution)
51
- );
52
-
53
50
  const data = new Map<bigint, FeatureData>();
54
51
 
55
52
  for (const tile of tiles as Required<RasterTile>[]) {
56
53
  const parent = tile.index.q;
57
54
 
58
- const children = cellToChildrenSorted(parent, cellResolution);
55
+ // If tile is partially overlapping with the spatial filter, compute a quadbin covering for the
56
+ // spatial filter + tile intersection, at cell resolution. If tile is fully inside or outside
57
+ // the spatial filter, computing a covering can be skipped. Avoid computing a quadbin covering
58
+ // for the _entire_ spatial filter, which may contain far too many cells (e.g. at zoom=3 and
59
+ // resolution=14, we have ~18,000,000 cells in the viewport.)
60
+ const tilePolygon = cellToBoundary(parent);
61
+ const tileFilter = intersect(
62
+ featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
63
+ );
64
+ const needsFilter = tileFilter
65
+ ? !booleanWithin(tilePolygon, options.spatialFilter)
66
+ : false;
67
+ const tileFilterCells = needsFilter
68
+ ? new Set(geometryToCells(tileFilter!.geometry, cellResolution))
69
+ : null;
70
+ const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
59
71
 
60
72
  // For each pixel/cell within the spatial filter, create a FeatureData.
61
73
  // Order is row-major, starting from NW and ending at SE.
62
- for (let i = 0; i < children.length; i++) {
63
- if (!spatialFilterCells.has(children[i])) continue;
74
+ for (let i = 0; i < tileSortedCells.length; i++) {
75
+ if (needsFilter && !tileFilterCells!.has(tileSortedCells[i])) {
76
+ continue;
77
+ }
64
78
 
65
79
  const cellData: FeatureData = {};
66
80
  let cellDataExists = false;
@@ -76,7 +90,7 @@ export function tileFeaturesRaster({
76
90
  }
77
91
 
78
92
  if (cellDataExists) {
79
- data.set(children[i], cellData);
93
+ data.set(tileSortedCells[i], cellData);
80
94
  }
81
95
  }
82
96
  }