1
- import test from 'flug' ;
2
- import load from '../load' ;
3
- import histogram from './histogram.module' ;
1
+ /**
2
+ * @prettier
3
+ */
4
+ import test from "flug" ;
5
+ import { serve } from "srvd" ;
6
+ import load from "../load" ;
7
+ import histogram from "./histogram.module" ;
4
8
5
9
const ratioQuantileOptions = {
6
- scaleType : ' ratio' ,
10
+ scaleType : " ratio" ,
7
11
numClasses : 7 ,
8
- classType : ' quantile' ,
12
+ classType : " quantile"
9
13
} ;
10
14
11
15
const ratioEIOptions = {
12
- scaleType : ' ratio' ,
16
+ scaleType : " ratio" ,
13
17
numClasses : 7 ,
14
- classType : ' equal-interval' ,
18
+ classType : " equal-interval"
15
19
} ;
16
20
17
21
const ratioEIGeorasterResults = {
18
- ' 74 - 99.86' : 140 ,
19
- ' >99.86 - 125.71' : 426 ,
20
- ' >125.71 - 151.57' : 305 ,
21
- ' >151.57 - 177.43' : 140 ,
22
- ' >177.43 - 203.29' : 62 ,
23
- ' >203.29 - 229.14' : 49 ,
24
- ' >229.14 - 255' : 78 ,
22
+ " 74 - 99.86" : 140 ,
23
+ " >99.86 - 125.71" : 426 ,
24
+ " >125.71 - 151.57" : 305 ,
25
+ " >151.57 - 177.43" : 140 ,
26
+ " >177.43 - 203.29" : 62 ,
27
+ " >203.29 - 229.14" : 49 ,
28
+ " >229.14 - 255" : 78
25
29
} ;
26
30
27
31
const ratioQuantileBboxResults = {
28
- ' 0 - 93.2' : 31 ,
29
- ' >93.2 - 272' : 31 ,
30
- ' >272 - 724' : 31 ,
31
- ' >724 - 1141.9' : 31 ,
32
- ' >1141.9 - 1700.6' : 31 ,
33
- ' >1700.6 - 2732.4' : 31 ,
34
- ' >2732.4 - 5166.7' : 28 ,
32
+ " 0 - 93.2" : 31 ,
33
+ " >93.2 - 272" : 31 ,
34
+ " >272 - 724" : 31 ,
35
+ " >724 - 1141.9" : 31 ,
36
+ " >1141.9 - 1700.6" : 31 ,
37
+ " >1700.6 - 2732.4" : 31 ,
38
+ " >2732.4 - 5166.7" : 28
35
39
} ;
36
40
37
41
const ratioQuantilePolygonResults = {
38
- ' 0 - 129.3' : 248 ,
39
- ' >129.3 - 683.8' : 248 ,
40
- ' >683.8 - 1191' : 248 ,
41
- ' >1191 - 1948.7' : 248 ,
42
- ' >1948.7 - 2567.7' : 248 ,
43
- ' >2567.7 - 3483.9' : 248 ,
44
- ' >3483.9 - 7807.4' : 246 ,
42
+ " 0 - 129.3" : 248 ,
43
+ " >129.3 - 683.8" : 248 ,
44
+ " >683.8 - 1191" : 248 ,
45
+ " >1191 - 1948.7" : 248 ,
46
+ " >1948.7 - 2567.7" : 248 ,
47
+ " >2567.7 - 3483.9" : 248 ,
48
+ " >3483.9 - 7807.4" : 246
45
49
} ;
46
50
47
51
const ratioEIPolygonResults = {
48
- ' 0 - 1115.34' : 719 ,
49
- ' >1115.34 - 2230.69' : 373 ,
50
- ' >2230.69 - 3346.03' : 359 ,
51
- ' >3346.03 - 4461.37' : 170 ,
52
- ' >4461.37 - 5576.71' : 78 ,
53
- ' >5576.71 - 6692.06' : 25 ,
54
- ' >6692.06 - 7807.4' : 9 ,
52
+ " 0 - 1115.34" : 719 ,
53
+ " >1115.34 - 2230.69" : 373 ,
54
+ " >2230.69 - 3346.03" : 359 ,
55
+ " >3346.03 - 4461.37" : 170 ,
56
+ " >4461.37 - 5576.71" : 78 ,
57
+ " >5576.71 - 6692.06" : 25 ,
58
+ " >6692.06 - 7807.4" : 9
55
59
} ;
56
60
57
- const url = ' http://localhost:3000/data/test.tiff' ;
58
- const urlSmallRaster = ' http://localhost:3000/data/example_4326.tif' ;
61
+ const url = " http://localhost:3000/data/test.tiff" ;
62
+ const urlSmallRaster = " http://localhost:3000/data/example_4326.tif" ;
59
63
60
- const bbox = [ 80.63 , 7.42 , 84.21 , 10.10 ] ;
64
+ const bbox = [ 80.63 , 7.42 , 84.21 , 10.1 ] ;
61
65
62
- const polygon = [ [
63
- [ 83.12255859375 , 22.49225722008518 ] , [ 82.96875 , 21.57571893245848 ] , [ 81.58447265624999 , 1.207458730482642 ] ,
64
- [ 83.07861328125 , 20.34462694382967 ] , [ 83.8037109375 , 19.497664168139053 ] , [ 84.814453125 , 19.766703551716976 ] ,
65
- [ 85.078125 , 21.166483858206583 ] , [ 86.044921875 , 20.838277806058933 ] , [ 86.98974609375 , 22.49225722008518 ] ,
66
- [ 85.58349609375 , 24.54712317973075 ] , [ 84.6826171875 , 23.36242859340884 ] , [ 83.12255859375 , 22.49225722008518 ]
67
- ] ] ;
66
+ const polygon = [
67
+ [
68
+ [ 83.12255859375 , 22.49225722008518 ] ,
69
+ [ 82.96875 , 21.57571893245848 ] ,
70
+ [ 81.58447265624999 , 1.207458730482642 ] ,
71
+ [ 83.07861328125 , 20.34462694382967 ] ,
72
+ [ 83.8037109375 , 19.497664168139053 ] ,
73
+ [ 84.814453125 , 19.766703551716976 ] ,
74
+ [ 85.078125 , 21.166483858206583 ] ,
75
+ [ 86.044921875 , 20.838277806058933 ] ,
76
+ [ 86.98974609375 , 22.49225722008518 ] ,
77
+ [ 85.58349609375 , 24.54712317973075 ] ,
78
+ [ 84.6826171875 , 23.36242859340884 ] ,
79
+ [ 83.12255859375 , 22.49225722008518 ]
80
+ ]
81
+ ] ;
68
82
69
83
const polygonGeojson = `{
70
84
"type": "FeatureCollection",
@@ -87,7 +101,9 @@ const polygonGeojson = `{
87
101
]
88
102
}` ;
89
103
90
- test ( 'Get Histogram (Ratio, Equal Interval) from GeoRaster' , async ( { eq } ) => {
104
+ if ( require . main === module ) serve ( { debug : true , port : 3000 , wait : 15 } ) ;
105
+
106
+ test ( "(Legacy) Get Histogram (Ratio, Equal Interval) from GeoRaster" , async ( { eq } ) => {
91
107
const georaster = await load ( urlSmallRaster ) ;
92
108
const results = histogram ( georaster , null , ratioEIOptions ) [ 0 ] ;
93
109
Object . keys ( ratioEIGeorasterResults ) . forEach ( key => {
@@ -97,7 +113,7 @@ test('Get Histogram (Ratio, Equal Interval) from GeoRaster', async ({ eq }) => {
97
113
} ) ;
98
114
} ) ;
99
115
100
- test ( ' Get Histogram (Ratio, Quantile) from Bounding Box' , async ( { eq } ) => {
116
+ test ( "(Legacy) Get Histogram (Ratio, Quantile) from Bounding Box" , async ( { eq } ) => {
101
117
const georaster = await load ( url ) ;
102
118
const results = histogram ( georaster , bbox , ratioQuantileOptions ) [ 0 ] ;
103
119
Object . keys ( ratioQuantileBboxResults ) . forEach ( key => {
@@ -107,7 +123,7 @@ test('Get Histogram (Ratio, Quantile) from Bounding Box', async ({ eq }) => {
107
123
} ) ;
108
124
} ) ;
109
125
110
- test ( ' Get Histogram (Ratio, Quantile) from Polygon' , async ( { eq } ) => {
126
+ test ( "(Legacy) Get Histogram (Ratio, Quantile) from Polygon" , async ( { eq } ) => {
111
127
const georaster = await load ( url ) ;
112
128
const results = histogram ( georaster , polygon , ratioQuantileOptions ) [ 0 ] ;
113
129
Object . keys ( ratioQuantilePolygonResults ) . forEach ( key => {
@@ -117,7 +133,7 @@ test('Get Histogram (Ratio, Quantile) from Polygon', async ({ eq }) => {
117
133
} ) ;
118
134
} ) ;
119
135
120
- test ( ' Get Histogram (Ratio, Equal Interval) from Polygon (GeoJSON)' , async ( { eq } ) => {
136
+ test ( "(Legacy) Get Histogram (Ratio, Equal Interval) from Polygon (GeoJSON)" , async ( { eq } ) => {
121
137
const georaster = await load ( url ) ;
122
138
const results = histogram ( georaster , polygonGeojson , ratioEIOptions ) [ 0 ] ;
123
139
Object . keys ( ratioEIPolygonResults ) . forEach ( key => {
@@ -126,3 +142,40 @@ test('Get Histogram (Ratio, Equal Interval) from Polygon (GeoJSON)', async ({ eq
126
142
eq ( value , expectedValue ) ;
127
143
} ) ;
128
144
} ) ;
145
+
146
+ // MODERN
147
+ test ( "(Modern) Get Histogram (Ratio, Equal Interval) from GeoRaster" , async ( { eq } ) => {
148
+ const results = await histogram ( urlSmallRaster , null , ratioEIOptions ) ;
149
+ Object . keys ( ratioEIGeorasterResults ) . forEach ( key => {
150
+ const value = results [ 0 ] [ key ] ;
151
+ const expectedValue = ratioEIGeorasterResults [ key ] ;
152
+ eq ( value , expectedValue ) ;
153
+ } ) ;
154
+ } ) ;
155
+
156
+ test ( "(Modern) Get Histogram (Ratio, Quantile) from Bounding Box" , async ( { eq } ) => {
157
+ const results = await histogram ( url , bbox , ratioQuantileOptions ) ;
158
+ Object . keys ( ratioQuantileBboxResults ) . forEach ( key => {
159
+ const value = results [ 0 ] [ key ] ;
160
+ const expectedValue = ratioQuantileBboxResults [ key ] ;
161
+ eq ( value , expectedValue ) ;
162
+ } ) ;
163
+ } ) ;
164
+
165
+ test ( "(Modern) Get Histogram (Ratio, Quantile) from Polygon" , async ( { eq } ) => {
166
+ const results = await histogram ( url , polygon , ratioQuantileOptions ) ;
167
+ Object . keys ( ratioQuantilePolygonResults ) . forEach ( key => {
168
+ const value = results [ 0 ] [ key ] ;
169
+ const expectedValue = ratioQuantilePolygonResults [ key ] ;
170
+ eq ( value , expectedValue ) ;
171
+ } ) ;
172
+ } ) ;
173
+
174
+ test ( "(Modern) Get Histogram (Ratio, Equal Interval) from Polygon (GeoJSON)" , async ( { eq } ) => {
175
+ const results = await histogram ( url , polygonGeojson , ratioEIOptions ) ;
176
+ Object . keys ( ratioEIPolygonResults ) . forEach ( key => {
177
+ const value = results [ 0 ] [ key ] ;
178
+ const expectedValue = ratioEIPolygonResults [ key ] ;
179
+ eq ( value , expectedValue ) ;
180
+ } ) ;
181
+ } ) ;
0 commit comments