MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / interpolate

Function interpolate

test/libs/workers/TurfWorkerForTest.js:19–98  ·  view source on GitHub ↗
(points, cellSize, options)

Source from the content-addressed store, hash-verified

17
18//IDW 插值
19function interpolate(points, cellSize, options) {
20 options = options || {};
21 if (typeof options !== 'object') {
22 throw new Error('options is invalid');
23 }
24 var gridType = options.gridType;
25 var property = options.property;
26 var weight = options.weight;
27
28 if (!points) {
29 throw new Error('points is required');
30 }
31 turf.collectionOf(points, 'Point', 'input must contain Points');
32 if (!cellSize) {
33 throw new Error('cellSize is required');
34 }
35 if (weight !== undefined && typeof weight !== 'number') {
36 throw new Error('weight must be a number');
37 }
38 property = property || 'elevation';
39 gridType = gridType || 'square';
40 weight = weight || 1;
41
42 var box = options.bbox || turf.bbox(points);
43
44 var grid;
45 switch (gridType) {
46 case 'point':
47 case 'points':
48 grid = squareGrid(box, cellSize, options, gridType);
49 break;
50 case 'square':
51 case 'squares':
52 grid = squareGrid(box, cellSize, options, gridType);
53 break;
54 case 'hex':
55 case 'hexes':
56 grid = turf.hexGrid(box, cellSize, options);
57 break;
58 case 'triangle':
59 case 'triangles':
60 grid = turf.triangleGrid(box, cellSize, options);
61 break;
62 default:
63 throw new Error('invalid gridType');
64 }
65 var results = [];
66 var gridFeatures = grid.features;
67 var pointFeatures = points.features;
68 for (var i = 0, len = gridFeatures.length; i < len; i++) {
69 var zw = 0;
70 var sw = 0;
71 var gridFeature = gridFeatures[i];
72 for (var j = 0, leng = pointFeatures.length; j < leng; j++) {
73 var point = pointFeatures[j];
74 var gridPoint = (gridType === 'point') ? gridFeature : turf.centroid(gridFeature);
75 var d = turf.distance(gridPoint, point, options);
76 var zValue;

Callers 1

analysisFunction · 0.70

Calls 4

squareGridFunction · 0.85
distanceMethod · 0.80
pushMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected