Skip to content

Commit 2b322d6

Browse files
committedOct 9, 2021
COG support and formatted
1 parent 2f71f1b commit 2b322d6

25 files changed

+339
-252
lines changed
 

‎.eslintrc.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
},
77
"extends": "eslint:recommended",
88
"parserOptions": {
9-
"ecmaVersion": 2017,
9+
"ecmaVersion": 2018,
1010
"sourceType": "module"
1111
},
1212
"rules": {
1313
"arrow-parens": ["error", "as-needed"],
1414
"camelcase": "error",
15-
"comma-dangle": ["error", { "objects": "always-multiline" }],
15+
"comma-dangle": ["error", "never"],
1616
"indent": ["error", 2],
1717
"linebreak-style": ["error", "unix"],
1818
"no-console": "off",
@@ -24,8 +24,12 @@
2424
"prefer-const": "error",
2525
"prefer-rest-params": "error",
2626
"prefer-spread": "error",
27-
"quotes": ["error", "single"],
27+
"quotes": ["error", "double", { "avoidEscape": true }],
2828
"semi": ["error", "always"],
29-
"space-before-function-paren": ["error", "always"]
29+
"space-before-function-paren": ["error", {
30+
"anonymous": "always",
31+
"named": "never",
32+
"asyncArrow": "always"
33+
}]
3034
}
3135
}

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"dev": "webpack --mode development --target node --watch",
1818
"documentation": "./node_modules/.bin/documentation build src/** --config documentation.yml -f html -o docs && echo 'geoblaze.io' > docs/CNAME",
1919
"fix": "eslint src --fix",
20-
"format": "npx prettier --arrow-parens=avoid --print-width=160 --trailing-comma=none --require-pragma --write src/*.js src/*/*.js",
20+
"format": "npx prettier --arrow-parens=avoid --print-width=160 --trailing-comma=none --insert-pragma --write src/*.js src/*/*.js",
2121
"lint": "eslint src",
2222
"serve": "npx srvd --debug --port=3000 --wait=120",
2323
"test": "for f in src/*/*test*.js; do echo \"\nrunning $f\" && node -r esm $f; done",
24-
"test-loading-builds": "npm run serve && sleep 2 && node test-loading-builds.js",
24+
"test-loading-builds": "node test-loading-builds.js",
2525
"setup": "bash setup.sh"
2626
},
2727
"repository": {

‎src/band-arithmetic/band-arithmetic.module.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import _ from 'underscore';
2-
import parseGeoraster from 'georaster';
3-
import { parse } from 'mathjs';
1+
/** @format */
42

5-
import get from '../get';
6-
import wrap from '../wrap-func';
7-
import utils from '../utils';
3+
import _ from "underscore";
4+
import parseGeoraster from "georaster";
5+
import { parse } from "mathjs";
6+
7+
import get from "../get";
8+
import wrap from "../wrap-func";
9+
import utils from "../utils";
810

911
const regexMultiCharacter = /[A-z]{2}/g;
1012

@@ -29,7 +31,8 @@ const parseNode = node => {
2931
const operation = node.op;
3032

3133
let leftHandSide;
32-
if (leftNode.content) { // if the node represents parentheses, it will be an object with a single property "content" which contains a node
34+
if (leftNode.content) {
35+
// if the node represents parentheses, it will be an object with a single property "content" which contains a node
3336
leftHandSide = `(${parseNode(leftNode.content)}`;
3437
} else if (isLeafNode(leftNode)) {
3538
leftHandSide = `(${leftNode.value || leftNode.name}`;
@@ -38,7 +41,8 @@ const parseNode = node => {
3841
}
3942

4043
let rightHandSide;
41-
if (rightNode.content) { // if the node represents parentheses, it will be an object with a single property "content" which contains a node
44+
if (rightNode.content) {
45+
// if the node represents parentheses, it will be an object with a single property "content" which contains a node
4246
rightHandSide = `${parseNode(rightNode.content)})`;
4347
} else if (isLeafNode(rightNode)) {
4448
rightHandSide = `${rightNode.value || rightNode.name})`;
@@ -71,7 +75,7 @@ const getBandValues = (bandRows, index) => {
7175
// before attempting to compute
7276
const arithmeticError = arithmetic => {
7377
if (arithmetic.match(regexMultiCharacter)) {
74-
return ('Geoblaze does not currently support implicit multiplication between variables. Please use the multiplication (*) symbol for these operations.');
78+
return "Geoblaze does not currently support implicit multiplication between variables. Please use the multiplication (*) symbol for these operations.";
7579
}
7680
};
7781

@@ -81,7 +85,7 @@ const bandArithmetic = async (georaster, arithmetic) => {
8185
const bands = await get(georaster, undefined, false);
8286

8387
if (bands.length < 2) {
84-
return reject(new Error('Band arithmetic is not available for this raster. Please make sure you are using a multi-band raster.'));
88+
throw new Error("Band arithmetic is not available for this raster. Please make sure you are using a multi-band raster.");
8589
}
8690

8791
const parseError = arithmeticError(arithmetic);
@@ -114,14 +118,7 @@ const bandArithmetic = async (georaster, arithmetic) => {
114118
values.push(row);
115119
}
116120

117-
const metadata = _.pick(georaster, ...[
118-
'noDataValue',
119-
'projection',
120-
'xmin',
121-
'ymax',
122-
'pixelWidth',
123-
'pixelHeight'
124-
]);
121+
const metadata = _.pick(georaster, ...["noDataValue", "projection", "xmin", "ymax", "pixelWidth", "pixelHeight"]);
125122
const newGeoRaster = await parseGeoraster([values], metadata);
126123
return newGeoRaster;
127124
};

‎src/band-arithmetic/band-arithmetic.test.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1+
/** @format */
2+
13
import test from "flug";
24
import { serve } from "srvd";
3-
import get from '../get';
4-
import load from '../load';
5-
import parse from '../parse';
6-
import bandArithmetic from './band-arithmetic.module';
5+
import get from "../get";
6+
import load from "../load";
7+
import parse from "../parse";
8+
import bandArithmetic from "./band-arithmetic.module";
79

810
// url is cached so only need 1 request
911
serve({ debug: true, max: 1, port: 3000 });
1012

11-
const url = 'http://localhost:3000/data/rgb/wildfires.tiff';
13+
const url = "http://localhost:3000/data/rgb/wildfires.tiff";
1214

13-
const calculation1 = 'a + b';
15+
const calculation1 = "a + b";
1416
const getExpectedValue1 = (a, b) => a + b;
1517

16-
const calculation2 = 'b - a * 2';
18+
const calculation2 = "b - a * 2";
1719
const getExpectedValue2 = (a, b) => b - a * 2;
1820

19-
const calculation3 = '2a * c + 10';
21+
const calculation3 = "2a * c + 10";
2022
const getExpectedValue3 = (a, c) => 2 * a * c + 10;
2123

22-
const calculation4 = '(a - b)/(a + b)';
24+
const calculation4 = "(a - b)/(a + b)";
2325
const getExpectedValue4 = (a, b) => (a - b) / (a + b);
2426

25-
const calculation5 = '2(b + a * c) - 100';
27+
const calculation5 = "2(b + a * c) - 100";
2628
const getExpectedValue5 = (a, b, c) => 2 * (b + a * c) - 100;
2729

28-
const calculation6 = '(a + b) / c';
30+
const calculation6 = "(a + b) / c";
2931
const getExpectedValue6 = (a, b, c) => (a + b) / c;
3032

31-
const calculation7 = '(a - a) / (b - b)';
33+
const calculation7 = "(a - a) / (b - b)";
3234

33-
function expectNoInfinityValues ({ georaster, eq }) {
35+
function expectNoInfinityValues({ georaster, eq }) {
3436
georaster.values.forEach(band => {
3537
band.forEach(row => {
3638
row.forEach(pixel => {
@@ -40,18 +42,17 @@ function expectNoInfinityValues ({ georaster, eq }) {
4042
});
4143
}
4244

43-
function expectNoNaNValues ({ georaster, eq }) {
45+
function expectNoNaNValues({ georaster, eq }) {
4446
georaster.values.forEach(band => {
4547
band.forEach(row => {
4648
row.forEach(pixel => {
47-
eq(pixel === NaN, false);
49+
eq(isNaN(pixel), false);
4850
});
4951
});
5052
});
5153
}
5254

53-
54-
test('(Legacy) Band Arithmetic: Run Calculation 1', async function ({ eq }) {
55+
test("(Legacy) Band Arithmetic: Run Calculation 1", async ({ eq }) => {
5556
const georaster = await load(url);
5657
const computedGeoraster = await bandArithmetic(georaster, calculation1);
5758
const value = computedGeoraster.values[0][0][0];
@@ -62,7 +63,7 @@ test('(Legacy) Band Arithmetic: Run Calculation 1', async function ({ eq }) {
6263
expectNoInfinityValues({ georaster: computedGeoraster, eq });
6364
});
6465

65-
test('(Legacy) Band Arithmetic: Run Calculation 2', async ({ eq }) => {
66+
test("(Legacy) Band Arithmetic: Run Calculation 2", async ({ eq }) => {
6667
const georaster = await load(url);
6768
const computedGeoraster = await bandArithmetic(georaster, calculation2);
6869
const value = computedGeoraster.values[0][0][0];
@@ -73,7 +74,7 @@ test('(Legacy) Band Arithmetic: Run Calculation 2', async ({ eq }) => {
7374
expectNoInfinityValues({ georaster: computedGeoraster, eq });
7475
});
7576

76-
test('(Legacy) Band Arithmetic: Run Calculation 3', async ({ eq }) => {
77+
test("(Legacy) Band Arithmetic: Run Calculation 3", async ({ eq }) => {
7778
const georaster = await load(url);
7879
const computedGeoraster = await bandArithmetic(georaster, calculation3);
7980
const value = computedGeoraster.values[0][0][0];
@@ -84,7 +85,7 @@ test('(Legacy) Band Arithmetic: Run Calculation 3', async ({ eq }) => {
8485
expectNoInfinityValues({ georaster: computedGeoraster, eq });
8586
});
8687

87-
test('(Legacy) Band Arithmetic: Run Calculation 4', async ({ eq }) => {
88+
test("(Legacy) Band Arithmetic: Run Calculation 4", async ({ eq }) => {
8889
const georaster = await load(url);
8990
const computedGeoraster = await bandArithmetic(georaster, calculation4);
9091
const value = computedGeoraster.values[0][0][0];
@@ -95,7 +96,7 @@ test('(Legacy) Band Arithmetic: Run Calculation 4', async ({ eq }) => {
9596
expectNoInfinityValues({ georaster: computedGeoraster, eq });
9697
});
9798

98-
test('(Legacy) Band Arithmetic: Run Calculation 5', async ({ eq }) => {
99+
test("(Legacy) Band Arithmetic: Run Calculation 5", async ({ eq }) => {
99100
const georaster = await load(url);
100101
const computedGeoraster = await bandArithmetic(georaster, calculation5);
101102
const value = computedGeoraster.values[0][0][0];
@@ -107,7 +108,7 @@ test('(Legacy) Band Arithmetic: Run Calculation 5', async ({ eq }) => {
107108
expectNoInfinityValues({ georaster: computedGeoraster, eq });
108109
});
109110

110-
test('(Legacy) Band Arithmetic: Run Calculation 6', async ({ eq }) => {
111+
test("(Legacy) Band Arithmetic: Run Calculation 6", async ({ eq }) => {
111112
const georaster = await load(url);
112113
const computedGeoraster = await bandArithmetic(georaster, calculation6);
113114
const value = computedGeoraster.values[0][0][0];
@@ -119,15 +120,14 @@ test('(Legacy) Band Arithmetic: Run Calculation 6', async ({ eq }) => {
119120
expectNoInfinityValues({ georaster: computedGeoraster, eq });
120121
});
121122

122-
test('(Legacy) Band Arithmetic: Run Calculation 7', async ({ eq }) => {
123+
test("(Legacy) Band Arithmetic: Run Calculation 7", async ({ eq }) => {
123124
const georaster = await load(url);
124125
const computedGeoraster = await bandArithmetic(georaster, calculation7);
125126
expectNoNaNValues({ georaster: computedGeoraster, eq });
126127
});
127128

128-
129129
// MODERN
130-
test('(Modern) Band Arithmetic: Run Calculation 1', async function ({ eq }) {
130+
test("(Modern) Band Arithmetic: Run Calculation 1", async ({ eq }) => {
131131
const georaster = await parse(url);
132132
const computedGeoraster = await bandArithmetic(url, calculation1);
133133
const value = computedGeoraster.values[0][0][0];
@@ -138,7 +138,7 @@ test('(Modern) Band Arithmetic: Run Calculation 1', async function ({ eq }) {
138138
expectNoInfinityValues({ georaster: computedGeoraster, eq });
139139
});
140140

141-
test('(Modern) Band Arithmetic: Run Calculation 2', async ({ eq }) => {
141+
test("(Modern) Band Arithmetic: Run Calculation 2", async ({ eq }) => {
142142
const georaster = await parse(url);
143143
const computedGeoraster = await bandArithmetic(url, calculation2);
144144
const value = computedGeoraster.values[0][0][0];
@@ -149,7 +149,7 @@ test('(Modern) Band Arithmetic: Run Calculation 2', async ({ eq }) => {
149149
expectNoInfinityValues({ georaster: computedGeoraster, eq });
150150
});
151151

152-
test('(Modern) Band Arithmetic: Run Calculation 3', async ({ eq }) => {
152+
test("(Modern) Band Arithmetic: Run Calculation 3", async ({ eq }) => {
153153
const georaster = await parse(url);
154154
const computedGeoraster = await bandArithmetic(url, calculation3);
155155
const value = computedGeoraster.values[0][0][0];
@@ -160,7 +160,7 @@ test('(Modern) Band Arithmetic: Run Calculation 3', async ({ eq }) => {
160160
expectNoInfinityValues({ georaster: computedGeoraster, eq });
161161
});
162162

163-
test('(Modern) Band Arithmetic: Run Calculation 4', async ({ eq }) => {
163+
test("(Modern) Band Arithmetic: Run Calculation 4", async ({ eq }) => {
164164
const georaster = await parse(url);
165165
const computedGeoraster = await bandArithmetic(url, calculation4);
166166
const value = computedGeoraster.values[0][0][0];
@@ -171,7 +171,7 @@ test('(Modern) Band Arithmetic: Run Calculation 4', async ({ eq }) => {
171171
expectNoInfinityValues({ georaster: computedGeoraster, eq });
172172
});
173173

174-
test('(Modern) Band Arithmetic: Run Calculation 5', async ({ eq }) => {
174+
test("(Modern) Band Arithmetic: Run Calculation 5", async ({ eq }) => {
175175
const georaster = await parse(url);
176176
const computedGeoraster = await bandArithmetic(url, calculation5);
177177
const value = computedGeoraster.values[0][0][0];
@@ -183,7 +183,7 @@ test('(Modern) Band Arithmetic: Run Calculation 5', async ({ eq }) => {
183183
expectNoInfinityValues({ georaster: computedGeoraster, eq });
184184
});
185185

186-
test('(Modern) Band Arithmetic: Run Calculation 6', async ({ eq }) => {
186+
test("(Modern) Band Arithmetic: Run Calculation 6", async ({ eq }) => {
187187
const georaster = await parse(url);
188188
const computedGeoraster = await bandArithmetic(url, calculation6);
189189
const value = computedGeoraster.values[0][0][0];
@@ -195,7 +195,7 @@ test('(Modern) Band Arithmetic: Run Calculation 6', async ({ eq }) => {
195195
expectNoInfinityValues({ georaster: computedGeoraster, eq });
196196
});
197197

198-
test('(Modern) Band Arithmetic: Run Calculation 7', async ({ eq }) => {
198+
test("(Modern) Band Arithmetic: Run Calculation 7", async ({ eq }) => {
199199
const computedGeoraster = await bandArithmetic(url, calculation7);
200200
expectNoNaNValues({ georaster: computedGeoraster, eq });
201201
});

‎src/band-arithmetic/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import bandArithmetic from './band-arithmetic.module';
1+
/** @format */
2+
3+
import bandArithmetic from "./band-arithmetic.module";
24

35
/**
46
* The band arithmetic function takes a raster and an arithmetic operation written as

‎src/cache/cache.module.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @format */
2+
13
const cache = {};
24

35
export default cache;

‎src/cache/cache.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** @format */

‎src/cache/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import cache from './cache.module';
1+
/** @format */
2+
3+
import cache from "./cache.module";
24

35
export default cache;

‎src/convert-geometry/convert-geometry.module.js

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import utils from '../utils';
1+
/** @format */
2+
3+
import utils from "../utils";
24

35
const convertPoint = geometry => {
46
let point;
5-
if (Array.isArray(geometry) && geometry.length === 2) { // array
7+
if (Array.isArray(geometry) && geometry.length === 2) {
8+
// array
69
point = geometry;
7-
} else if (typeof geometry === 'string') { // stringified geojson
10+
} else if (typeof geometry === "string") {
11+
// stringified geojson
812
const geojson = JSON.parse(geometry);
9-
if (geojson.type === 'Point') {
13+
if (geojson.type === "Point") {
1014
point = geojson.coordinates;
1115
}
12-
} else if (typeof geometry === 'object') { // geojson
13-
if (geometry.type === 'Point') {
16+
} else if (typeof geometry === "object") {
17+
// geojson
18+
if (geometry.type === "Point") {
1419
point = geometry.coordinates;
1520
}
1621
}
@@ -26,18 +31,20 @@ const convertPoint = geometry => {
2631
const convertBbox = geometry => {
2732
let bbox;
2833
if (utils.isBbox(geometry)) {
29-
if (typeof geometry.xmin !== 'undefined' && typeof geometry.ymax !== 'undefined') {
34+
if (typeof geometry.xmin !== "undefined" && typeof geometry.ymax !== "undefined") {
3035
bbox = geometry;
31-
}
32-
else if (Array.isArray(geometry) && geometry.length === 4) { // array
36+
} else if (Array.isArray(geometry) && geometry.length === 4) {
37+
// array
3338
bbox = { xmin: geometry[0], ymin: geometry[1], xmax: geometry[2], ymax: geometry[3] };
34-
} else if (typeof geometry === 'string') { // stringified geojson
39+
} else if (typeof geometry === "string") {
40+
// stringified geojson
3541
const geojson = JSON.parse(geometry);
3642
const coors = utils.getGeojsonCoors(geojson)[0];
3743
const lngs = coors.map(coor => coor[0]);
3844
const lats = coors.map(coor => coor[1]);
3945
bbox = { xmin: Math.min(...lngs), ymin: Math.min(...lats), xmax: Math.max(...lngs), ymax: Math.max(...lats) };
40-
} else if (typeof geometry === 'object') { // geojson
46+
} else if (typeof geometry === "object") {
47+
// geojson
4148
const coors = utils.getGeojsonCoors(geometry)[0];
4249
const lngs = coors.map(coor => coor[0]);
4350
const lats = coors.map(coor => coor[1]);
@@ -56,13 +63,16 @@ const convertBbox = geometry => {
5663
const convertPolygon = geometry => {
5764
let polygon;
5865
if (utils.isPolygon(geometry)) {
59-
if (Array.isArray(geometry)) { // array
66+
if (Array.isArray(geometry)) {
67+
// array
6068
polygon = geometry;
61-
} else if (typeof geometry === 'string') { // stringified geojson
69+
} else if (typeof geometry === "string") {
70+
// stringified geojson
6271
const parsed = JSON.parse(geometry);
6372
const geojson = utils.convertToGeojsonIfNecessary(parsed);
6473
polygon = utils.getGeojsonCoors(geojson);
65-
} else if (typeof geometry === 'object') { // geojson
74+
} else if (typeof geometry === "object") {
75+
// geojson
6676
const geojson = utils.convertToGeojsonIfNecessary(geometry);
6777
polygon = utils.getGeojsonCoors(geojson);
6878
}
@@ -78,16 +88,16 @@ const convertPolygon = geometry => {
7888

7989
const convertGeometry = (typeOfGeometry, geometry) => {
8090
try {
81-
if (typeOfGeometry === 'point') {
91+
if (typeOfGeometry === "point") {
8292
return convertPoint(geometry);
83-
} else if (typeOfGeometry === 'bbox') {
93+
} else if (typeOfGeometry === "bbox") {
8494
return convertBbox(geometry);
85-
} else if (typeOfGeometry === 'polygon') {
95+
} else if (typeOfGeometry === "polygon") {
8696
return convertPolygon(geometry);
8797
} else {
8898
throw 'Invalid geometry type was specified. Please use either "point" or "polygon"';
8999
}
90-
} catch(e) {
100+
} catch (e) {
91101
console.error(e);
92102
throw e;
93103
}

‎src/convert-geometry/convert-geometry.test.js

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import test from 'flug';
2-
import convertGeometry from './convert-geometry.module';
3-
import getDepth from 'get-depth';
1+
/** @format */
2+
3+
import test from "flug";
4+
import convertGeometry from "./convert-geometry.module";
5+
import getDepth from "get-depth";
46

57
const arrayPoint = [102, 0.5];
68

@@ -16,8 +18,20 @@ const geojsonBboxStr = `{
1618
const geojsonBbox = JSON.parse(geojsonBboxStr);
1719

1820
const arrayPolygon = [
19-
[ [100.0, 0.0], [101.0, 0.0], [101.5, 1.0], [100.0, 0.5], [100.0, 0.0] ],
20-
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.4], [100.2, 0.2] ]
21+
[
22+
[100.0, 0.0],
23+
[101.0, 0.0],
24+
[101.5, 1.0],
25+
[100.0, 0.5],
26+
[100.0, 0.0]
27+
],
28+
[
29+
[100.2, 0.2],
30+
[100.8, 0.2],
31+
[100.8, 0.8],
32+
[100.2, 0.4],
33+
[100.2, 0.2]
34+
]
2135
];
2236

2337
const geojsonPolygonStr1 = `{
@@ -50,58 +64,57 @@ const geojsonPolygon1 = JSON.parse(geojsonPolygonStr1);
5064
const geojsonPolygon2 = JSON.parse(geojsonPolygonStr2);
5165

5266
const testPointLoad = (feature, eq) => {
53-
const point = convertGeometry('point', feature);
67+
const point = convertGeometry("point", feature);
5468
eq(point[0], 102);
5569
eq(point[1], 0.5);
5670
};
5771

5872
const testBboxLoad = (feature, eq) => {
59-
const bbox = convertGeometry('bbox', feature);
73+
const bbox = convertGeometry("bbox", feature);
6074
eq(bbox.xmin, 100);
6175
eq(bbox.ymin, 0);
6276
eq(bbox.xmax, 101);
6377
eq(bbox.ymax, 1);
6478
};
6579

6680
const testPolygonLoad = (feature, eq) => {
67-
const poly = convertGeometry('polygon', feature);
81+
const poly = convertGeometry("polygon", feature);
6882
const depth = getDepth(poly);
6983
eq(depth, 3);
7084
};
7185

72-
test('Load Point from array', ({ eq }) => {
86+
test("Load Point from array", ({ eq }) => {
7387
testPointLoad(arrayPoint, eq);
7488
});
75-
test('Load Point from geojson string', ({ eq }) => {
89+
test("Load Point from geojson string", ({ eq }) => {
7690
testPointLoad(geojsonPointStr, eq);
7791
});
78-
test('Load Point from geojson obj', ({ eq }) => {
92+
test("Load Point from geojson obj", ({ eq }) => {
7993
testPointLoad(geojsonPoint, eq);
8094
});
8195

82-
83-
test('Load bbox from array', ({ eq }) => {
96+
test("Load bbox from array", ({ eq }) => {
8497
testBboxLoad(arrayBbox, eq);
8598
});
86-
test('Load bbox from geojson string', ({ eq }) => {
99+
test("Load bbox from geojson string", ({ eq }) => {
87100
testBboxLoad(geojsonBboxStr, eq);
88101
});
89-
test('Load bbox from geojson obj', ({ eq }) => {
102+
test("Load bbox from geojson obj", ({ eq }) => {
90103
testBboxLoad(geojsonBbox, eq);
91104
});
92105

93-
test('Load Polygon from array', ({ eq }) => {
106+
test("Load Polygon from array", ({ eq }) => {
94107
testPolygonLoad(arrayPolygon, eq);
95108
});
96-
test('Load Polygon from geojson string (simple)', ({ eq }) => {
109+
test("Load Polygon from geojson string (simple)", ({ eq }) => {
97110
testPolygonLoad(geojsonPolygonStr1, eq);
98111
});
99-
test('Load Polygon from geojson string (complex)', ({ eq }) => {
112+
test("Load Polygon from geojson string (complex)", ({ eq }) => {
100113
testPolygonLoad(geojsonPolygonStr2, eq);
101114
});
102-
test('Load Polygon from geojson obj (simple)', ({ eq }) => {
115+
test("Load Polygon from geojson obj (simple)", ({ eq }) => {
103116
testPolygonLoad(geojsonPolygon1, eq);
104117
});
105-
test('Load Polygon from geojson obj (complex)', ({ eq }) => {
118+
test("Load Polygon from geojson obj (complex)", ({ eq }) => {
106119
testPolygonLoad(geojsonPolygon2, eq);
107120
});

‎src/convert-geometry/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import convertGeometry from './convert-geometry.module';
1+
/** @format */
2+
3+
import convertGeometry from "./convert-geometry.module";
24

35
export default convertGeometry;

‎src/histogram/histogram.module.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ const getHistogramsForRaster = (georaster, geom, options) => {
174174
const { noDataValue } = georaster;
175175

176176
// grab array of values by band
177-
let values = [];
178-
let done = intersectPolygon(georaster, geom, (value, bandIndex) => {
177+
const values = [];
178+
const done = intersectPolygon(georaster, geom, (value, bandIndex) => {
179179
if (values[bandIndex]) {
180180
values[bandIndex].push(value);
181181
} else {

‎src/load/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import load from './load.module';
1+
/** @format */
2+
3+
import load from "./load.module";
24

35
/**
46
* This function is deprecated and you should try to migrate to using parse.

‎src/load/load.module.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import parseGeoraster from 'georaster';
2-
import fetch from 'cross-fetch';
3-
import nodeUrl from 'url';
4-
import { ERROR_LOAD_FILE_OUTSIDE_BROWSER, ERROR_BAD_URL, ERROR_PARSING_GEOTIFF } from '../error-constants';
5-
import cache from '../cache';
1+
/** @format */
62

7-
const inBrowser = typeof window === 'object';
3+
import parseGeoraster from "georaster";
4+
import fetch from "cross-fetch";
5+
import nodeUrl from "url";
6+
import { ERROR_LOAD_FILE_OUTSIDE_BROWSER, ERROR_BAD_URL, ERROR_PARSING_GEOTIFF } from "../error-constants";
7+
import cache from "../cache";
8+
9+
const inBrowser = typeof window === "object";
810

911
const URL = inBrowser ? window.URL : nodeUrl.parse;
1012

11-
async function toArrayBuffer (response) {
13+
async function toArrayBuffer(response) {
1214
try {
1315
if (response.arrayBuffer) {
1416
return response.arrayBuffer();
@@ -21,7 +23,7 @@ async function toArrayBuffer (response) {
2123
}
2224
}
2325

24-
async function fetchWithErrorHandling (url) {
26+
async function fetchWithErrorHandling(url) {
2527
try {
2628
const response = await fetch(url);
2729
if (!response.ok) {
@@ -34,20 +36,20 @@ async function fetchWithErrorHandling (url) {
3436
}
3537
}
3638

37-
async function parseGeorasterWithErrorHandling (arrayBuffer) {
39+
async function parseGeorasterWithErrorHandling(arrayBuffer) {
3840
try {
3941
return await parseGeoraster(arrayBuffer);
4042
} catch (error) {
4143
throw new Error(ERROR_PARSING_GEOTIFF);
4244
}
4345
}
4446

45-
async function load (urlOrFile) {
46-
if (!inBrowser && typeof urlOrFile === 'object') {
47+
async function load(urlOrFile) {
48+
if (!inBrowser && typeof urlOrFile === "object") {
4749
throw new Error(ERROR_LOAD_FILE_OUTSIDE_BROWSER);
4850
}
4951

50-
const url = typeof urlOrFile === 'object' ? URL.createObjectURL(urlOrFile) : urlOrFile;
52+
const url = typeof urlOrFile === "object" ? URL.createObjectURL(urlOrFile) : urlOrFile;
5153

5254
if (!cache[url]) {
5355
const response = await fetchWithErrorHandling(url);

‎src/load/load.test.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
1-
import test from 'flug';
1+
/** @format */
2+
3+
import test from "flug";
24
import { serve } from "srvd";
3-
import load from './load.module';
5+
import load from "./load.module";
46

57
import {
68
ERROR_BAD_URL
79
//ERROR_PARSING_GEOTIFF
8-
} from '../error-constants';
10+
} from "../error-constants";
911

10-
serve({ debug: true, max: 2, port: 3000});
12+
serve({ debug: true, max: 2, port: 3000 });
1113

12-
const path = 'http://localhost:3000/data/test.tiff';
13-
const incorrectPath = 'http://localhost:3000/data/this-is-not-a-real-dataset.tiff';
14-
const incorrectPath2 = 'this-is-a-fake-path';
14+
const path = "http://localhost:3000/data/test.tiff";
15+
const incorrectPath = "http://localhost:3000/data/this-is-not-a-real-dataset.tiff";
16+
const incorrectPath2 = "this-is-a-fake-path";
1517
//const incorrectPath3 = 'http://localhost:3000/data/random-file';
1618

17-
const properties = [
18-
'projection',
19-
'xmin',
20-
'values'
21-
];
22-
19+
const properties = ["projection", "xmin", "values"];
2320

24-
test('Loaded tiff export from geonode', async ({ eq }) => {
25-
const url = 'https://s3.amazonaws.com/georaster/geonode_atlanteil.tif';
21+
test("Loaded tiff export from geonode", async ({ eq }) => {
22+
const url = "https://s3.amazonaws.com/georaster/geonode_atlanteil.tif";
2623
const georaster = await load(url);
2724
properties.forEach(property => {
2825
eq(property in georaster, true);
2926
});
3027
});
3128

32-
test('Loaded tiff file', async ({ eq }) => {
29+
test("Loaded tiff file", async ({ eq }) => {
3330
const georaster = await load(path);
3431
properties.forEach(property => {
3532
eq(property in georaster, true);
3633
});
3734
});
3835

39-
test('Error from invalid URL', async ({ eq }) => {
36+
test("Error from invalid URL", async ({ eq }) => {
4037
let message;
4138
try {
4239
await load(incorrectPath);
@@ -46,7 +43,7 @@ test('Error from invalid URL', async ({ eq }) => {
4643
eq(message, ERROR_BAD_URL);
4744
});
4845

49-
test('Load: Error from another invalid URL tiff file', async ({ eq }) => {
46+
test("Load: Error from another invalid URL tiff file", async ({ eq }) => {
5047
let message;
5148
try {
5249
await load(incorrectPath2);

‎src/median/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import median from './median.module';
1+
/** @format */
2+
3+
import median from "./median.module";
24

35
/**
46
* The median function takes a raster as an input and an optional geometry.

‎src/median/median.test.js

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import test from 'flug';
1+
/** @format */
2+
3+
import test from "flug";
24
import { serve } from "srvd";
3-
import load from '../load';
4-
import median from './median.module';
5+
import load from "../load";
6+
import median from "./median.module";
57

68
serve({ debug: true, max: 1, port: 3000 });
79

8-
const url = 'http://localhost:3000/data/test.tiff';
10+
const url = "http://localhost:3000/data/test.tiff";
911

10-
const bbox = [80.63, 7.42, 84.21, 10.10];
11-
const expectedBboxValue = 906.70;
12+
const bbox = [80.63, 7.42, 84.21, 10.1];
13+
const expectedBboxValue = 906.7;
1214

1315
const bboxGeojson = `{
1416
"type": "FeatureCollection",
@@ -27,58 +29,67 @@ const bboxGeojson = `{
2729
}`;
2830
const expectedBboxGeojsonValue = 1849.4;
2931

30-
const polygon = [[
31-
[83.12255859375, 22.49225722008518], [82.96875, 21.57571893245848], [81.58447265624999, 1.207458730482642],
32-
[83.07861328125, 20.34462694382967], [83.8037109375, 19.497664168139053], [84.814453125, 19.766703551716976],
33-
[85.078125, 21.166483858206583], [86.044921875, 20.838277806058933], [86.98974609375, 22.49225722008518],
34-
[85.58349609375, 24.54712317973075], [84.6826171875, 23.36242859340884], [83.12255859375, 22.49225722008518]
35-
]];
32+
const polygon = [
33+
[
34+
[83.12255859375, 22.49225722008518],
35+
[82.96875, 21.57571893245848],
36+
[81.58447265624999, 1.207458730482642],
37+
[83.07861328125, 20.34462694382967],
38+
[83.8037109375, 19.497664168139053],
39+
[84.814453125, 19.766703551716976],
40+
[85.078125, 21.166483858206583],
41+
[86.044921875, 20.838277806058933],
42+
[86.98974609375, 22.49225722008518],
43+
[85.58349609375, 24.54712317973075],
44+
[84.6826171875, 23.36242859340884],
45+
[83.12255859375, 22.49225722008518]
46+
]
47+
];
3648
const expectedPolygonValue = 1573.3;
3749

38-
test('Get Median from Bounding Box', async ({ eq }) => {
50+
test("Get Median from Bounding Box", async ({ eq }) => {
3951
const georaster = await load(url);
4052
const value = Number(median(georaster, bbox)[0].toFixed(2));
4153
eq(value, expectedBboxValue);
4254
});
4355

44-
test('Get Median from Bounding Box (GeoJSON)', async ({ eq }) => {
56+
test("Get Median from Bounding Box (GeoJSON)", async ({ eq }) => {
4557
const georaster = await load(url);
4658
const value = Number(median(georaster, bboxGeojson)[0].toFixed(2));
4759
eq(value, expectedBboxGeojsonValue);
4860
});
4961

50-
test('Get Median from Polygon', async ({ eq }) => {
62+
test("Get Median from Polygon", async ({ eq }) => {
5163
const georaster = await load(url);
5264
const value = Number(median(georaster, polygon)[0].toFixed(2));
5365
eq(value, expectedPolygonValue);
5466
});
5567

56-
test('Get Median from Whole Raster', async ({ eq }) => {
68+
test("Get Median from Whole Raster", async ({ eq }) => {
5769
const georaster = await load(url);
5870
const value = median(georaster)[0];
5971
eq(value, 0);
6072
});
6173

62-
63-
test('Get Median from Bounding Box from url', async ({ eq }) => {
74+
test("Get Median from Bounding Box from url", async ({ eq }) => {
6475
const result = await median(url, bbox);
6576
const value = Number(result[0].toFixed(2));
6677
eq(value, expectedBboxValue);
6778
});
6879

69-
test('Get Median from Bounding Box (GeoJSON) from url', async ({ eq }) => {
80+
test("Get Median from Bounding Box (GeoJSON) from url", async ({ eq }) => {
7081
const result = await median(url, bboxGeojson);
7182
const value = Number(result[0].toFixed(2));
7283
eq(value, expectedBboxGeojsonValue);
7384
});
7485

75-
test('Get Median from Polygon from url', async ({ eq }) => {
86+
test("Get Median from Polygon from url", async ({ eq }) => {
7687
const result = await median(url, polygon);
7788
const value = Number(result[0].toFixed(2));
7889
eq(value, expectedPolygonValue);
7990
});
8091

81-
test('Get Median from Whole Raster from url', async ({ eq }) => {
92+
test("Get Median from Whole Raster from url", async ({ eq }) => {
8293
const result = await median(url);
8394
const value = result[0];
8495
eq(value, 0);

‎src/raster-calculator/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import rasterCalculator from './raster-calculator.module';
1+
/** @format */
2+
3+
import rasterCalculator from "./raster-calculator.module";
24

35
/**
46
* The raster calculator function takes a raster and a javascript function as input.

‎src/raster-calculator/raster-calculator.module.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import _ from 'underscore';
2-
import parseGeoraster from 'georaster';
1+
/** @format */
32

4-
import get from '../get';
5-
import wrap from '../wrap-func';
6-
import utils from '../utils';
3+
import _ from "underscore";
4+
import parseGeoraster from "georaster";
5+
6+
import get from "../get";
7+
import wrap from "../wrap-func";
8+
import utils from "../utils";
79

810
const containsNoDataValue = (bandValues, noDataValue) => {
911
const numBandValues = bandValues.length;
@@ -39,12 +41,12 @@ const rasterCalculator = async (georaster, func) => {
3941
const bands = await get(georaster);
4042
const numBands = bands.length;
4143

42-
if (typeof func === 'string') {
44+
if (typeof func === "string") {
4345
func = parseString(func.toLowerCase(), numBands);
4446
}
4547

46-
if (typeof func !== 'function') {
47-
return reject(new Error('Function is invalid. Please provide a valid function as the second argument.'));
48+
if (typeof func !== "function") {
49+
throw new Error("Function is invalid. Please provide a valid function as the second argument.");
4850
}
4951

5052
const { noDataValue } = georaster;
@@ -72,14 +74,7 @@ const rasterCalculator = async (georaster, func) => {
7274
values.push(row);
7375
}
7476

75-
const metadata = _.pick(georaster, ...[
76-
'noDataValue',
77-
'projection',
78-
'xmin',
79-
'ymax',
80-
'pixelWidth',
81-
'pixelHeight'
82-
]);
77+
const metadata = _.pick(georaster, ...["noDataValue", "projection", "xmin", "ymax", "pixelWidth", "pixelHeight"]);
8378
return await parseGeoraster([values], metadata);
8479
};
8580

‎src/raster-calculator/raster-calculator.test.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import test from 'flug';
2-
import { serve } from 'srvd';
3-
import load from '../load';
4-
import rasterCalculator from './raster-calculator.module';
1+
/** @format */
52

6-
serve({ debug: true, max: 1, port: 3000});
3+
import test from "flug";
4+
import { serve } from "srvd";
5+
import load from "../load";
6+
import rasterCalculator from "./raster-calculator.module";
77

8-
const url = 'http://localhost:3000/data/rgb/wildfires.tiff';
8+
serve({ debug: true, max: 1, port: 3000 });
9+
10+
const url = "http://localhost:3000/data/rgb/wildfires.tiff";
911

1012
const calculation1 = (a, b) => a + b;
1113
const calculation2 = (a, b) => b - a * 2;
1214
const calculation3 = (a, b, c) => 2 * a * c + 10;
13-
const calculation4 = (a, b) => a > b ? 1 : 0;
15+
const calculation4 = (a, b) => (a > b ? 1 : 0);
1416
const calculation5 = (a, b, c) => {
1517
if (a + b > c) return null;
1618
return a + b;
@@ -30,11 +32,11 @@ const calculation7 = (a, b, c) => {
3032

3133
const calculation8 = () => NaN;
3234

33-
const calculation9 = 'return a > 200 ? 1 : 0;';
35+
const calculation9 = "return a > 200 ? 1 : 0;";
3436

35-
const calculation10 = 'return A > 200 ? 1 : 0;';
37+
const calculation10 = "return A > 200 ? 1 : 0;";
3638

37-
function expectNoInfinityValues (georaster, eq) {
39+
function expectNoInfinityValues(georaster, eq) {
3840
georaster.values.forEach(band => {
3941
band.forEach(row => {
4042
row.forEach(pixel => {
@@ -44,17 +46,17 @@ function expectNoInfinityValues (georaster, eq) {
4446
});
4547
}
4648

47-
function expectNoNaNValues (georaster, eq) {
49+
function expectNoNaNValues(georaster, eq) {
4850
georaster.values.forEach(band => {
4951
band.forEach(row => {
5052
row.forEach(pixel => {
51-
eq(pixel === NaN, false);
53+
eq(isNaN(pixel), false);
5254
});
5355
});
5456
});
5557
}
5658

57-
test('Run Calculation 1', async ({ eq }) => {
59+
test("Run Calculation 1", async ({ eq }) => {
5860
const georaster = await load(url);
5961
const computedGeoraster = await rasterCalculator(georaster, calculation1);
6062
const value = computedGeoraster.values[0][0][0];
@@ -64,19 +66,19 @@ test('Run Calculation 1', async ({ eq }) => {
6466
expectNoInfinityValues(computedGeoraster, eq);
6567
});
6668

67-
test('Run Calculation 2', async ({ eq }) => {
69+
test("Run Calculation 2", async ({ eq }) => {
6870
const georaster = await load(url);
69-
const computedGeoraster = await rasterCalculator(georaster, calculation2);
71+
const computedGeoraster = await rasterCalculator(georaster, calculation2);
7072
const value = computedGeoraster.values[0][0][0];
7173
const a = georaster.values[0][0][0];
7274
const b = georaster.values[1][0][0];
7375
eq(value, calculation2(a, b));
7476
expectNoInfinityValues(computedGeoraster, eq);
7577
});
7678

77-
test('Run Calculation 3', async ({ eq }) => {
79+
test("Run Calculation 3", async ({ eq }) => {
7880
const georaster = await load(url);
79-
const computedGeoraster = await rasterCalculator(georaster, calculation3);
81+
const computedGeoraster = await rasterCalculator(georaster, calculation3);
8082
const value = computedGeoraster.values[0][0][0];
8183
const a = georaster.values[0][0][0];
8284
const b = georaster.values[1][0][0];
@@ -85,19 +87,19 @@ test('Run Calculation 3', async ({ eq }) => {
8587
expectNoInfinityValues(computedGeoraster, eq);
8688
});
8789

88-
test('Run Calculation 4', async ({ eq }) => {
90+
test("Run Calculation 4", async ({ eq }) => {
8991
const georaster = await load(url);
90-
const computedGeoraster = await rasterCalculator(georaster, calculation4);
92+
const computedGeoraster = await rasterCalculator(georaster, calculation4);
9193
const value = computedGeoraster.values[0][0][0];
9294
const a = georaster.values[0][0][0];
9395
const b = georaster.values[1][0][0];
9496
eq(value, calculation4(a, b));
9597
expectNoInfinityValues(computedGeoraster, eq);
9698
});
9799

98-
test('Run Calculation 5', async ({ eq }) => {
100+
test("Run Calculation 5", async ({ eq }) => {
99101
const georaster = await load(url);
100-
const computedGeoraster = await rasterCalculator(georaster, calculation5);
102+
const computedGeoraster = await rasterCalculator(georaster, calculation5);
101103
const value = computedGeoraster.values[0][0][0];
102104
const a = georaster.values[0][0][0];
103105
const b = georaster.values[1][0][0];
@@ -106,9 +108,9 @@ test('Run Calculation 5', async ({ eq }) => {
106108
expectNoInfinityValues(computedGeoraster, eq);
107109
});
108110

109-
test('Run Calculation 6', async ({ eq }) => {
111+
test("Run Calculation 6", async ({ eq }) => {
110112
const georaster = await load(url);
111-
const computedGeoraster = await rasterCalculator(georaster, calculation6);
113+
const computedGeoraster = await rasterCalculator(georaster, calculation6);
112114
const value = computedGeoraster.values[0][0][0];
113115
const a = georaster.values[0][0][0];
114116
const b = georaster.values[1][0][0];
@@ -117,9 +119,9 @@ test('Run Calculation 6', async ({ eq }) => {
117119
expectNoInfinityValues(computedGeoraster, eq);
118120
});
119121

120-
test('Run Calculation 7', async ({ eq }) => {
122+
test("Run Calculation 7", async ({ eq }) => {
121123
const georaster = await load(url);
122-
const computedGeoraster = await rasterCalculator(georaster, calculation7);
124+
const computedGeoraster = await rasterCalculator(georaster, calculation7);
123125
const value = computedGeoraster.values[0][0][0];
124126
const a = georaster.values[0][0][0];
125127
const b = georaster.values[1][0][0];
@@ -128,15 +130,15 @@ test('Run Calculation 7', async ({ eq }) => {
128130
expectNoInfinityValues(computedGeoraster, eq);
129131
});
130132

131-
test('Run Calculation 8', async ({ eq }) => {
133+
test("Run Calculation 8", async ({ eq }) => {
132134
const georaster = await load(url);
133-
const computedGeoraster = await rasterCalculator(georaster, calculation8);
135+
const computedGeoraster = await rasterCalculator(georaster, calculation8);
134136
expectNoNaNValues(computedGeoraster, eq);
135137
});
136138

137-
test('Run Calculation 9', async ({ eq }) => {
139+
test("Run Calculation 9", async ({ eq }) => {
138140
const georaster = await load(url);
139-
const computedGeoraster = await rasterCalculator(georaster, calculation9);
141+
const computedGeoraster = await rasterCalculator(georaster, calculation9);
140142
let numZeros = 0;
141143
let numOnes = 0;
142144
computedGeoraster.values.forEach(band => {
@@ -155,9 +157,9 @@ test('Run Calculation 9', async ({ eq }) => {
155157
expectNoInfinityValues(computedGeoraster, eq);
156158
});
157159

158-
test('Run Calculation 10', async ({ eq }) => {
160+
test("Run Calculation 10", async ({ eq }) => {
159161
const georaster = await load(url);
160-
const computedGeoraster = await rasterCalculator(georaster, calculation10);
162+
const computedGeoraster = await rasterCalculator(georaster, calculation10);
161163
let numZeros = 0;
162164
let numOnes = 0;
163165
computedGeoraster.values.forEach(band => {

‎src/sum/sum.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ test("(Legacy) Test sum for Country with Multiple Rings", async ({ eq }) => {
305305
const georaster = await load(url);
306306
const country = await utils.fetchJson(urlToGeojsons + "Akrotiri and Dhekelia.geojson");
307307
const result = sum(georaster, country);
308-
// eq(result, [123]);
308+
eq(result, [0]);
309309
});
310310

311311
test("(Legacy) Get Sum from Polygon Above X Value", async ({ eq }) => {
@@ -463,7 +463,7 @@ test("(Modern) Test sum for Country with Multiple Rings", async ({ eq }) => {
463463
const georaster = await parse(url);
464464
const country = await utils.fetchJson(urlToGeojsons + "Akrotiri and Dhekelia.geojson");
465465
const result = await sum(georaster, country);
466-
// eq(result, [123]);
466+
eq(result, [0]);
467467
});
468468

469469
test("(Modern) Get Sum from Polygon Above X Value", async ({ eq }) => {

‎src/utils/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import utils from './utils.module';
1+
/** @format */
2+
3+
import utils from "./utils.module";
24

35
export default utils;

‎src/utils/utils.module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @prettier
33
*/
44

5-
import _, { result } from "underscore";
5+
import _ from "underscore";
66
import combine from "@turf/combine";
77
import fetch from "cross-fetch";
88
import ArcGIS from "terraformer-arcgis-parser";

‎src/utils/utils.test.js

+84-48
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import test from 'flug';
2-
import { serve } from 'srvd';
3-
import load from '../load';
4-
import utils from './utils.module';
5-
import getDepth from 'get-depth';
1+
/** @format */
2+
3+
import test from "flug";
4+
import { serve } from "srvd";
5+
import load from "../load";
6+
import utils from "./utils.module";
7+
import getDepth from "get-depth";
68

79
serve({ debug: true, max: 10, port: 3000 });
810

911
const { fetchJson, fetchJsons } = utils;
1012

11-
const url = 'http://localhost:3000/data/RWA_MNH_ANC.tif';
12-
const urlToData = 'http://localhost:3000/data/';
13-
const urlToGeojsons = urlToData + 'gadm/geojsons/';
14-
const urlToGeojson = urlToGeojsons + 'Akrotiri and Dhekelia.geojson';
15-
const urlToArcgisJsons = urlToData + 'gadm/arcgis/';
13+
const url = "http://localhost:3000/data/RWA_MNH_ANC.tif";
14+
const urlToData = "http://localhost:3000/data/";
15+
const urlToGeojsons = urlToData + "gadm/geojsons/";
16+
const urlToGeojson = urlToGeojsons + "Akrotiri and Dhekelia.geojson";
17+
const urlToArcgisJsons = urlToData + "gadm/arcgis/";
1618

17-
test('Get Bounding when Bounding Box when Bigger Than Raster and with Negative Values', async ({ eq }) => {
19+
test("Get Bounding when Bounding Box when Bigger Than Raster and with Negative Values", async ({ eq }) => {
1820
const georaster = await load(url);
1921
const bboxWithBuffer = {
2022
xmin: georaster.xmin - 1,
2123
xmax: georaster.xmax + 1,
2224
ymin: georaster.ymin - 1,
23-
ymax: georaster.ymax + 1,
25+
ymax: georaster.ymax + 1
2426
};
2527
const actualBbox = utils.convertCrsBboxToImageBbox(georaster, bboxWithBuffer);
2628
eq(actualBbox.xmin < 0, true);
@@ -29,50 +31,59 @@ test('Get Bounding when Bounding Box when Bigger Than Raster and with Negative V
2931
eq(actualBbox.ymin < actualBbox.ymax, true);
3032
});
3133

32-
test('Get Bounding Box of GeoJSON that has MultiPolygon Geometry (i.e., multiple rings)', async ({ eq }) => {
34+
test("Get Bounding Box of GeoJSON that has MultiPolygon Geometry (i.e., multiple rings)", async ({ eq }) => {
3335
const country = await fetchJson(urlToGeojson);
3436
const bbox = utils.getBoundingBox(country.geometry.coordinates);
35-
eq(typeof bbox.xmin, 'number');
36-
eq(typeof bbox.xmax, 'number');
37-
eq(typeof bbox.ymin, 'number');
38-
eq(typeof bbox.ymax, 'number');
37+
eq(typeof bbox.xmin, "number");
38+
eq(typeof bbox.xmax, "number");
39+
eq(typeof bbox.ymin, "number");
40+
eq(typeof bbox.ymax, "number");
3941
eq(bbox.xmin, 32.76010131835966);
4042
eq(bbox.xmax, 33.92147445678711);
4143
eq(bbox.ymin, 34.56208419799816);
4244
eq(bbox.ymax, 35.118995666503906);
4345
});
4446

45-
46-
test('Test Forcing Within', ({ eq }) => {
47+
test("Test Forcing Within", ({ eq }) => {
4748
eq(utils.forceWithin(10, 1, 11), 10);
4849
eq(utils.forceWithin(-10, 1, 11), 1);
4950
eq(utils.forceWithin(990, 1, 11), 11);
5051
});
5152

52-
test('Test Merging of Index Ranges', ({ eq }) => {
53-
let original = [ [0, 10], [10, 10], [20, 30], [30, 40] ];
53+
test("Test Merging of Index Ranges", ({ eq }) => {
54+
let original = [
55+
[0, 10],
56+
[10, 10],
57+
[20, 30],
58+
[30, 40]
59+
];
5460
let merged = utils.mergeRanges(original);
55-
eq(JSON.stringify(merged), '[[0,10],[20,40]]');
56-
57-
original = [ [0, 10], [10, 10], [21, 31], [30, 40] ];
61+
eq(JSON.stringify(merged), "[[0,10],[20,40]]");
62+
63+
original = [
64+
[0, 10],
65+
[10, 10],
66+
[21, 31],
67+
[30, 40]
68+
];
5869
merged = utils.mergeRanges(original);
59-
eq(JSON.stringify(merged), '[[0,10],[21,40]]');
70+
eq(JSON.stringify(merged), "[[0,10],[21,40]]");
6071
});
6172

62-
63-
64-
test('Get Depth For Multipolygon', async ({ eq }) => {
65-
const countryDepths = [['Afghanistan', 3], ['Akrotiri and Dhekelia', 4]];
73+
test("Get Depth For Multipolygon", async ({ eq }) => {
74+
const countryDepths = [
75+
["Afghanistan", 3],
76+
["Akrotiri and Dhekelia", 4]
77+
];
6678
for (let i = 0; i < countryDepths.length; i++) {
6779
const [name, depth] = countryDepths[i];
68-
const country = await fetchJson(urlToGeojsons + name + '.geojson');
80+
const country = await fetchJson(urlToGeojsons + name + ".geojson");
6981
const actualDepth = getDepth(country.geometry.coordinates);
7082
eq(actualDepth, depth);
7183
}
7284
});
7385

74-
75-
test('Clustering Of Line Segments: For array of objects holding information about intersections: Got Correct Split', ({ eq }) => {
86+
test("Clustering Of Line Segments: For array of objects holding information about intersections: Got Correct Split", ({ eq }) => {
7687
let segments, computed, computedNumberOfClusters;
7788

7889
segments = [{ endsOffLine: true }, { endsOffLine: false }, { endsOffLine: false }, { endsOffLine: true }];
@@ -96,7 +107,7 @@ test('Clustering Of Line Segments: For array of objects holding information abou
96107
eq(computed[0].length, 4);
97108
});
98109

99-
test('Test Coupling', ({ eq }) => {
110+
test("Test Coupling", ({ eq }) => {
100111
const items = [0, 1, 18, 77, 99, 103];
101112
const actual = utils.couple(items);
102113
eq(actual.length, items.length / 2);
@@ -105,11 +116,11 @@ test('Test Coupling', ({ eq }) => {
105116
});
106117
});
107118

108-
test('Test isPolygon', async ({ eq }) => {
109-
const countries = ['Afghanistan', 'Ukraine'];
119+
test("Test isPolygon", async ({ eq }) => {
120+
const countries = ["Afghanistan", "Ukraine"];
110121
for (let i = 0; i < countries.length; i++) {
111122
const name = countries[i];
112-
const jsons = await fetchJsons([urlToGeojsons + name + '.geojson', urlToArcgisJsons + name + '.json']);
123+
const jsons = await fetchJsons([urlToGeojsons + name + ".geojson", urlToArcgisJsons + name + ".json"]);
113124
const [geojson, arcgisjson] = jsons;
114125
// console.log('geojson:', JSON.stringify(geojson).substring(0, 100) + '...');
115126
// console.log('arcgisjson:', JSON.stringify(arcgisjson).substring(0, 100) + '...');
@@ -119,27 +130,38 @@ test('Test isPolygon', async ({ eq }) => {
119130
}
120131
});
121132

122-
test('Test Intersections', ({ eq }) => {
123-
const edge1 = [[32.87069320678728,34.66652679443354],[32.87069320678728,34.66680526733393]]; // vertical
124-
const edge2 = [[30,34.70833333333334],[40,34.70833333333334]];
133+
test("Test Intersections", ({ eq }) => {
134+
const edge1 = [
135+
[32.87069320678728, 34.66652679443354],
136+
[32.87069320678728, 34.66680526733393]
137+
]; // vertical
138+
const edge2 = [
139+
[30, 34.70833333333334],
140+
[40, 34.70833333333334]
141+
];
125142
const line1 = utils.getLineFromPoints(edge1[0], edge1[1]);
126143
const line2 = utils.getLineFromPoints(edge2[0], edge2[1]);
127144
let intersection = utils.getIntersectionOfTwoLines(line1, line2);
128145
eq(intersection.x, 32.87069320678728);
129146
eq(intersection.y, 34.70833333333334);
130147

131148
// this test fails because of floating point arithmetic
132-
const verticalEdge = [ [ 19.59097290039091, 29.76190948486328 ], [ 19.59097290039091, 41.76180648803728 ] ];
133-
const horizontalEdge = [ [ 15, 41.641892470257524 ], [ 25, 41.641892470257524 ] ];
149+
const verticalEdge = [
150+
[19.59097290039091, 29.76190948486328],
151+
[19.59097290039091, 41.76180648803728]
152+
];
153+
const horizontalEdge = [
154+
[15, 41.641892470257524],
155+
[25, 41.641892470257524]
156+
];
134157
const verticalLine = utils.getLineFromPoints(verticalEdge[0], verticalEdge[1]);
135158
const horizontalLine = utils.getLineFromPoints(horizontalEdge[0], horizontalEdge[1]);
136159
intersection = utils.getIntersectionOfTwoLines(verticalLine, horizontalLine);
137160
//eq(intersection.x, 19.59097290039091);
138161
//eq(intersection.y, 41.641892470257524);
139162
});
140163

141-
142-
test('Test Categorization of Intersections', ({ eq }) => {
164+
test("Test Categorization of Intersections", ({ eq }) => {
143165
// through
144166
let segments = [{ xmin: -140, xmax: -140, direction: 1 }];
145167
let actual = utils.categorizeIntersection(segments);
@@ -148,28 +170,42 @@ test('Test Categorization of Intersections', ({ eq }) => {
148170
eq(actual.xmax, -140);
149171

150172
// rebound
151-
segments = [{ xmin: -140, xmax: -140, direction: 1 },{ xmin: -140, xmax: -140, direction: -1 }];
173+
segments = [
174+
{ xmin: -140, xmax: -140, direction: 1 },
175+
{ xmin: -140, xmax: -140, direction: -1 }
176+
];
152177
actual = utils.categorizeIntersection(segments);
153178
eq(actual.through, false);
154179
eq(actual.xmin, -140);
155180
eq(actual.xmax, -140);
156181

157182
// horizontal through
158-
segments = [{ xmin: -140, xmax: -140, direction: 1 },{ xmin: -140, xmax: -130, direction: 0 },{ xmin: -130, xmax: -130, direction: 1 }];
183+
segments = [
184+
{ xmin: -140, xmax: -140, direction: 1 },
185+
{ xmin: -140, xmax: -130, direction: 0 },
186+
{ xmin: -130, xmax: -130, direction: 1 }
187+
];
159188
actual = utils.categorizeIntersection(segments);
160189
eq(actual.through, true);
161190
eq(actual.xmin, -140);
162191
eq(actual.xmax, -130);
163192

164193
// horizontal rebound
165-
segments = [{ xmin: -140, xmax: -140, direction: 1 },{ xmin: -140, xmax: -130, direction: 0 },{ xmin: -130, xmax: -130, direction: -1 }];
194+
segments = [
195+
{ xmin: -140, xmax: -140, direction: 1 },
196+
{ xmin: -140, xmax: -130, direction: 0 },
197+
{ xmin: -130, xmax: -130, direction: -1 }
198+
];
166199
actual = utils.categorizeIntersection(segments);
167200
eq(actual.through, false);
168201
eq(actual.xmin, -140);
169202
eq(actual.xmax, -130);
170203

171204
// through with stop
172-
segments = [{ xmin: -140, xmax: -140, direction: 1 }, { xmin: -140, xmax: -140, direction: 1 }];
205+
segments = [
206+
{ xmin: -140, xmax: -140, direction: 1 },
207+
{ xmin: -140, xmax: -140, direction: 1 }
208+
];
173209
actual = utils.categorizeIntersection(segments);
174210
eq(actual.through, true);
175211
eq(actual.xmin, -140);
@@ -178,4 +214,4 @@ test('Test Categorization of Intersections', ({ eq }) => {
178214

179215
test("get constructor names", ({ eq }) => {
180216
eq(utils.getConstructorName(new ArrayBuffer()), "ArrayBuffer");
181-
})
217+
});

‎test-loading-builds.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const test = require('flug');
2+
const { serve } = require('srvd');
23
const puppeteer = require('puppeteer');
34

4-
const url2GeoTIFF = 'http://localhost:3000/data/example_4326.tif';
5+
const { port } = serve({ debug: true, max: 6, port: 3000 });
6+
7+
const url2GeoTIFF = `http://localhost:${port}/data/example_4326.tif`;
58

69

710
test('Should Successfully Require Production Build in Node', async ({ eq }) => {

0 commit comments

Comments
 (0)
Please sign in to comment.