1
- import utils from '../utils' ;
2
- import test from 'flug' ;
3
- import load from '../load' ;
4
- import sum from './sum.module' ;
5
- import { polygon as turfPolygon } from '@turf/helpers' ;
1
+ /**
2
+ * @prettier
3
+ */
4
+ import test from "flug" ;
5
+ import { serve } from "srvd" ;
6
+
7
+ import utils from "../utils" ;
8
+ import load from "../load" ;
9
+ import parse from "../parse" ;
10
+ import sum from "./sum.module" ;
11
+ import { polygon as turfPolygon } from "@turf/helpers" ;
6
12
7
13
const { fetchJson, fetchJsons } = utils ;
8
14
9
- const urlRwanda = 'http://localhost:3000/data/RWA_MNH_ANC.tif' ;
10
- const bboxRwanda = require ( '../../data/RwandaBufferedBoundingBox.json' ) ;
15
+ if ( require . main === module ) serve ( { debug : true , port : 3000 , wait : 60 } ) ;
11
16
12
- const urlToData = 'http://localhost:3000/data/' ;
13
- const urlToGeojsons = urlToData + 'gadm/geojsons/' ;
14
- const urlToArcgisJsons = urlToData + 'gadm/arcgis/' ;
17
+ const urlRwanda = "http://localhost:3000/data/RWA_MNH_ANC.tif" ;
18
+ const bboxRwanda = require ( "../../data/RwandaBufferedBoundingBox.json" ) ;
15
19
16
- const url = ' http://localhost:3000/data/test.tiff' ;
17
- const bbox = [ 80.63 , 7.42 , 84.21 , 10.10 ] ;
18
- const expectedBboxValue = 262516.50 ;
20
+ const urlToData = " http://localhost:3000/data/" ;
21
+ const urlToGeojsons = urlToData + "gadm/geojsons/" ;
22
+ const urlToArcgisJsons = urlToData + "gadm/arcgis/" ;
19
23
20
- const polygon = [ [
21
- [ 83.12255859375 , 22.49225722008518 ] , [ 82.96875 , 21.57571893245848 ] , [ 81.58447265624999 , 1.207458730482642 ] ,
22
- [ 83.07861328125 , 20.34462694382967 ] , [ 83.8037109375 , 19.497664168139053 ] , [ 84.814453125 , 19.766703551716976 ] ,
23
- [ 85.078125 , 21.166483858206583 ] , [ 86.044921875 , 20.838277806058933 ] , [ 86.98974609375 , 22.49225722008518 ] ,
24
- [ 85.58349609375 , 24.54712317973075 ] , [ 84.6826171875 , 23.36242859340884 ] , [ 83.12255859375 , 22.49225722008518 ]
25
- ] ] ;
26
- const expectedPolygonValue = 3165731.9 ;
24
+ const url = "http://localhost:3000/data/test.tiff" ;
25
+ const bbox = [ 80.63 , 7.42 , 84.21 , 10.1 ] ;
26
+ const expectedBboxValue = 262516.5 ;
27
27
28
+ const polygon = [
29
+ [
30
+ [ 83.12255859375 , 22.49225722008518 ] ,
31
+ [ 82.96875 , 21.57571893245848 ] ,
32
+ [ 81.58447265624999 , 1.207458730482642 ] ,
33
+ [ 83.07861328125 , 20.34462694382967 ] ,
34
+ [ 83.8037109375 , 19.497664168139053 ] ,
35
+ [ 84.814453125 , 19.766703551716976 ] ,
36
+ [ 85.078125 , 21.166483858206583 ] ,
37
+ [ 86.044921875 , 20.838277806058933 ] ,
38
+ [ 86.98974609375 , 22.49225722008518 ] ,
39
+ [ 85.58349609375 , 24.54712317973075 ] ,
40
+ [ 84.6826171875 , 23.36242859340884 ] ,
41
+ [ 83.12255859375 , 22.49225722008518 ]
42
+ ]
43
+ ] ;
44
+ const expectedPolygonValue = 3165731.9 ;
28
45
29
46
const polygonGeojson1 = `{
30
47
"type": "FeatureCollection",
@@ -204,46 +221,47 @@ const polygonGeojsonCollection = `{
204
221
205
222
const expectedPolygonGeojsonCollectionValue = expectedPolygonGeojsonValue1 + expectedPolygonGeojsonValue2 ;
206
223
207
- test ( 'Get Sum from Veneto Geonode' , async ( { eq } ) => {
208
- const values = [
209
- await load ( 'https://s3.amazonaws.com/geoblaze/geonode_atlanteil.tif' ) ,
210
- await fetchJson ( 'https://s3.amazonaws.com/geoblaze/veneto.geojson' )
211
- ] ;
224
+ test ( "(Legacy) Get Sum from Veneto Geonode" , async ( { eq } ) => {
225
+ const values = [ await load ( "http://localhost:3000/data/veneto/geonode_atlanteil.tif" ) , await fetchJson ( "http://localhost:3000/data/veneto/veneto.geojson" ) ] ;
212
226
const [ georaster , geojson ] = values ;
213
- const actualValue = Number ( sum ( georaster , geojson ) [ 0 ] . toFixed ( 2 ) ) ;
227
+ const results = sum ( georaster , geojson ) ;
228
+ const actualValue = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
214
229
const expectedValue = 25323.11 ;
215
230
eq ( actualValue , expectedValue ) ;
216
231
} ) ;
217
232
218
- test ( ' Get Sum' , async ( { eq } ) => {
233
+ test ( "(Legacy) Get Sum" , async ( { eq } ) => {
219
234
const georaster = await load ( url ) ;
220
- const actualValue = Number ( sum ( georaster ) [ 0 ] . toFixed ( 2 ) ) ;
235
+ const results = sum ( georaster ) ;
236
+ const actualValue = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
221
237
const expectedValue = 108343045.4 ;
222
238
eq ( actualValue , expectedValue ) ;
223
239
} ) ;
224
240
225
- test ( ' Get Sum from Bounding Box' , async ( { eq } ) => {
241
+ test ( "(Legacy) Get Sum from Bounding Box" , async ( { eq } ) => {
226
242
const georaster = await load ( url ) ;
227
- const value = Number ( sum ( georaster , bbox ) [ 0 ] . toFixed ( 2 ) ) ;
243
+ const results = sum ( georaster , bbox ) ;
244
+ const value = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
228
245
eq ( value , expectedBboxValue ) ;
229
246
} ) ;
230
247
231
- test ( ' Get Sum from Bounding Box Greater Then Raster' , async ( { eq } ) => {
248
+ test ( "(Legacy) Get Sum from Bounding Box Greater Then Raster" , async ( { eq } ) => {
232
249
const georaster = await load ( urlRwanda ) ;
233
- const valueWithBufferedBbox = Number ( sum ( georaster , bboxRwanda ) [ 0 ] . toFixed ( 2 ) ) ;
250
+ const results = sum ( georaster , bboxRwanda ) ;
251
+ const valueWithBufferedBbox = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
234
252
const valueWithoutBbox = Number ( sum ( georaster ) [ 0 ] . toFixed ( 2 ) ) ;
235
253
eq ( valueWithBufferedBbox , 104848.45 ) ;
236
254
eq ( valueWithoutBbox , 104848.45 ) ;
237
255
eq ( valueWithBufferedBbox , valueWithoutBbox ) ;
238
256
} ) ;
239
257
240
- test ( ' Get Same Sum from GeoJSON and ESRI JSON' , async ( { eq } ) => {
241
- const urlToRaster = urlToData + ' mapspam/spam2005v3r2_harvested-area_wheat_total.tiff' ;
258
+ test ( "(Legacy) Get Same Sum from GeoJSON and ESRI JSON" , async ( { eq } ) => {
259
+ const urlToRaster = urlToData + " mapspam/spam2005v3r2_harvested-area_wheat_total.tiff" ;
242
260
const georaster = await load ( urlToRaster ) ;
243
- const countryNames = [ ' Afghanistan' , ' Ukraine' ] ;
261
+ const countryNames = [ " Afghanistan" , " Ukraine" ] ;
244
262
for ( let i = 0 ; i < countryNames . length ; i ++ ) {
245
263
const name = countryNames [ i ] ;
246
- const jsons = await fetchJsons ( [ urlToGeojsons + name + ' .geojson' , urlToArcgisJsons + name + ' .json' ] , true ) ;
264
+ const jsons = await fetchJsons ( [ urlToGeojsons + name + " .geojson" , urlToArcgisJsons + name + " .json" ] , true ) ;
247
265
const [ geojson , arcgisJson ] = jsons ;
248
266
const valueViaGeojson = Number ( sum ( georaster , geojson ) [ 0 ] . toFixed ( 2 ) ) ;
249
267
const valueViaArcgisJson = Number ( sum ( georaster , arcgisJson ) [ 0 ] . toFixed ( 2 ) ) ;
@@ -253,51 +271,48 @@ test('Get Same Sum from GeoJSON and ESRI JSON', async ({ eq }) => {
253
271
}
254
272
} ) ;
255
273
256
- test ( ' Get Sum from Polygon' , async ( { eq } ) => {
274
+ test ( "(Legacy) Get Sum from Polygon" , async ( { eq } ) => {
257
275
const georaster = await load ( url ) ;
258
276
const value = Number ( sum ( georaster , polygon ) [ 0 ] . toFixed ( 2 ) ) ;
259
277
eq ( value , expectedPolygonValue ) ;
260
278
} ) ;
261
279
262
-
263
- test ( 'Get Sum from Polygon (GeoJSON) 1' , async ( { eq } ) => {
280
+ test ( "(Legacy) Get Sum from Polygon (GeoJSON) 1" , async ( { eq } ) => {
264
281
const georaster = await load ( url ) ;
265
282
const value = Number ( sum ( georaster , polygonGeojson1 ) [ 0 ] . toFixed ( 2 ) ) ;
266
283
eq ( value , expectedPolygonGeojsonValue1 ) ;
267
284
} ) ;
268
285
269
- test ( ' Get Sum from Polygon (GeoJSON) 2' , async ( { eq } ) => {
286
+ test ( "(Legacy) Get Sum from Polygon (GeoJSON) 2" , async ( { eq } ) => {
270
287
const georaster = await load ( url ) ;
271
288
const value = Number ( sum ( georaster , polygonGeojson2 ) [ 0 ] . toFixed ( 2 ) ) ;
272
289
eq ( value , expectedPolygonGeojsonValue2 ) ;
273
290
} ) ;
274
291
275
- test ( ' Get Sum from Polygon (Multi-Polygon GeoJSON, 1 + 2)' , async ( { eq } ) => {
292
+ test ( "(Legacy) Get Sum from Polygon (Multi-Polygon GeoJSON, 1 + 2)" , async ( { eq } ) => {
276
293
const georaster = await load ( url ) ;
277
294
const value = Number ( sum ( georaster , polygonGeojsonCollection ) [ 0 ] . toFixed ( 2 ) ) ;
278
295
eq ( value , expectedPolygonGeojsonCollectionValue ) ;
279
296
} ) ;
280
297
281
- test ( ' Test sum for Country with Multiple Rings' , async ( { eq } ) => {
298
+ test ( "(Legacy) Test sum for Country with Multiple Rings" , async ( { eq } ) => {
282
299
const georaster = await load ( url ) ;
283
- const country = await utils . fetchJson ( urlToGeojsons + ' Akrotiri and Dhekelia.geojson' ) ;
300
+ const country = await utils . fetchJson ( urlToGeojsons + " Akrotiri and Dhekelia.geojson" ) ;
284
301
const result = sum ( georaster , country ) ;
285
302
// eq(result, [123]);
286
303
} ) ;
287
304
288
- test ( ' Get Sum from Polygon Above X Value' , async ( { eq } ) => {
305
+ test ( "(Legacy) Get Sum from Polygon Above X Value" , async ( { eq } ) => {
289
306
const georaster = await load ( url ) ;
290
307
const value = Number ( sum ( georaster , polygon , v => v > 3000 ) [ 0 ] . toFixed ( 2 ) ) ;
291
308
eq ( value , 1501820.8 ) ;
292
309
} ) ;
293
310
294
-
295
-
296
- test ( 'Test Super Simplified Albanian Polygon' , async ( { eq } ) => {
297
- const feature = await utils . fetchJson ( urlToData + 'gadm/derived/super-simplified-albanian-polygon.geojson' ) ;
298
- const georaster = await load ( urlToData + 'ghsl/tiles/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0_4326_60_40.tif' ) ;
299
- const result = sum ( georaster , turfPolygon ( polygon ) ) [ 0 ] ;
300
- eq ( result , 0 ) ;
311
+ test ( "(Legacy) Test Super Simplified Albanian Polygon" , async ( { eq } ) => {
312
+ const feature = await utils . fetchJson ( urlToData + "gadm/derived/super-simplified-albanian-polygon.geojson" ) ;
313
+ const georaster = await load ( urlToData + "ghsl/tiles/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0_4326_60_40.tif" ) ;
314
+ const result = sum ( georaster , turfPolygon ( polygon ) ) ;
315
+ eq ( result , [ 0 ] ) ;
301
316
} ) ;
302
317
303
318
// describe('Get Populations', function () {
@@ -367,3 +382,99 @@ test('Test Super Simplified Albanian Polygon', async ({ eq }) => {
367
382
// return Promise.all(promises);
368
383
// });
369
384
// });
385
+
386
+ // modern
387
+
388
+ test ( "(Modern) Get Sum from Veneto Geonode" , async ( { eq } ) => {
389
+ const values = [ await load ( "http://localhost:3000/data/veneto/geonode_atlanteil.tif" ) , await fetchJson ( "http://localhost:3000/data/veneto/veneto.geojson" ) ] ;
390
+ const [ georaster , geojson ] = values ;
391
+ const results = await sum ( georaster , geojson ) ;
392
+ const actualValue = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
393
+ const expectedValue = 25323.11 ;
394
+ eq ( actualValue , expectedValue ) ;
395
+ } ) ;
396
+
397
+ test ( "(Modern) Get Sum" , async ( { eq } ) => {
398
+ const georaster = await parse ( url ) ;
399
+ const results = await sum ( georaster ) ;
400
+ const actualValue = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
401
+ const expectedValue = 108343045.4 ;
402
+ eq ( actualValue , expectedValue ) ;
403
+ } ) ;
404
+
405
+ test ( "(Modern) Get Sum from Bounding Box" , async ( { eq } ) => {
406
+ const georaster = await parse ( url ) ;
407
+ const results = await sum ( georaster , bbox ) ;
408
+ const value = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
409
+ eq ( value , expectedBboxValue ) ;
410
+ } ) ;
411
+
412
+ test ( "(Modern) Get Sum from Bounding Box Greater Then Raster" , async ( { eq } ) => {
413
+ const georaster = await parse ( urlRwanda ) ;
414
+ const results = await sum ( georaster , bboxRwanda ) ;
415
+ const valueWithBufferedBbox = Number ( results [ 0 ] . toFixed ( 2 ) ) ;
416
+ const valueWithoutBbox = Number ( sum ( georaster ) [ 0 ] . toFixed ( 2 ) ) ;
417
+ eq ( valueWithBufferedBbox , 104848.45 ) ;
418
+ eq ( valueWithoutBbox , 104848.45 ) ;
419
+ eq ( valueWithBufferedBbox , valueWithoutBbox ) ;
420
+ } ) ;
421
+
422
+ test ( "(Modern) Get Same Sum from GeoJSON and ESRI JSON" , async ( { eq } ) => {
423
+ const urlToRaster = urlToData + "mapspam/spam2005v3r2_harvested-area_wheat_total.tiff" ;
424
+ const georaster = await parse ( urlToRaster ) ;
425
+ const countryNames = [ "Afghanistan" , "Ukraine" ] ;
426
+ for ( let i = 0 ; i < countryNames . length ; i ++ ) {
427
+ const name = countryNames [ i ] ;
428
+ const jsons = await fetchJsons ( [ urlToGeojsons + name + ".geojson" , urlToArcgisJsons + name + ".json" ] , true ) ;
429
+ const [ geojson , arcgisJson ] = jsons ;
430
+ const valueViaGeojson = Number ( sum ( georaster , geojson ) [ 0 ] . toFixed ( 2 ) ) ;
431
+ const valueViaArcgisJson = Number ( sum ( georaster , arcgisJson ) [ 0 ] . toFixed ( 2 ) ) ;
432
+ const valueViaArcgisJsonPolygon = Number ( sum ( georaster , arcgisJson . geometry ) [ 0 ] . toFixed ( 2 ) ) ;
433
+ eq ( valueViaGeojson , valueViaArcgisJson ) ;
434
+ eq ( valueViaGeojson , valueViaArcgisJsonPolygon ) ;
435
+ }
436
+ } ) ;
437
+
438
+ test ( "(Modern) Get Sum from Polygon" , async ( { eq } ) => {
439
+ const georaster = await parse ( url ) ;
440
+ const value = Number ( sum ( georaster , polygon ) [ 0 ] . toFixed ( 2 ) ) ;
441
+ eq ( value , expectedPolygonValue ) ;
442
+ } ) ;
443
+
444
+ test ( "(Modern) Get Sum from Polygon (GeoJSON) 1" , async ( { eq } ) => {
445
+ const georaster = await parse ( url ) ;
446
+ const value = Number ( sum ( georaster , polygonGeojson1 ) [ 0 ] . toFixed ( 2 ) ) ;
447
+ eq ( value , expectedPolygonGeojsonValue1 ) ;
448
+ } ) ;
449
+
450
+ test ( "(Modern) Get Sum from Polygon (GeoJSON) 2" , async ( { eq } ) => {
451
+ const georaster = await parse ( url ) ;
452
+ const value = Number ( sum ( georaster , polygonGeojson2 ) [ 0 ] . toFixed ( 2 ) ) ;
453
+ eq ( value , expectedPolygonGeojsonValue2 ) ;
454
+ } ) ;
455
+
456
+ test ( "(Modern) Get Sum from Polygon (Multi-Polygon GeoJSON, 1 + 2)" , async ( { eq } ) => {
457
+ const georaster = await parse ( url ) ;
458
+ const value = Number ( sum ( georaster , polygonGeojsonCollection ) [ 0 ] . toFixed ( 2 ) ) ;
459
+ eq ( value , expectedPolygonGeojsonCollectionValue ) ;
460
+ } ) ;
461
+
462
+ test ( "(Modern) Test sum for Country with Multiple Rings" , async ( { eq } ) => {
463
+ const georaster = await parse ( url ) ;
464
+ const country = await utils . fetchJson ( urlToGeojsons + "Akrotiri and Dhekelia.geojson" ) ;
465
+ const result = await sum ( georaster , country ) ;
466
+ // eq(result, [123]);
467
+ } ) ;
468
+
469
+ test ( "(Modern) Get Sum from Polygon Above X Value" , async ( { eq } ) => {
470
+ const georaster = await parse ( url ) ;
471
+ const value = Number ( sum ( georaster , polygon , v => v > 3000 ) [ 0 ] . toFixed ( 2 ) ) ;
472
+ eq ( value , 1501820.8 ) ;
473
+ } ) ;
474
+
475
+ test ( "(Modern) Test Super Simplified Albanian Polygon" , async ( { eq } ) => {
476
+ const feature = await utils . fetchJson ( urlToData + "gadm/derived/super-simplified-albanian-polygon.geojson" ) ;
477
+ const georaster = await parse ( urlToData + "ghsl/tiles/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0_4326_60_40.tif" ) ;
478
+ const result = await sum ( georaster , turfPolygon ( polygon ) ) ;
479
+ eq ( result , [ 0 ] ) ;
480
+ } ) ;
0 commit comments