forked from mapbox/mapbox-geostats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (29 loc) · 1.06 KB
/
Copy pathindex.js
File metadata and controls
35 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
const getFileType = require('./lib/get-file-type');
const mapnikAnalyze = require('./lib/mapnik-analyze');
const tileAnalyze = require('./lib/tile-analyze');
const reportStats = require('./lib/report-stats');
const Constants = require('./lib/constants');
/**
* @param {string} filePath
* @param {Object} options
* @returns {Object} The stats.
*/
async function buildGeoStats(filePath, options) {
options = options || {};
options.maxValuesToReport ??= 50;
if (options.attributes) {
if (options.attributes.length > Constants.ATTRIBUTES_MAX_REPORT) {
throw new Error('Cannot report on more than ' + Constants.ATTRIBUTES_MAX_REPORT
+ ' attributes');
}
// Conversion to a Set should make for faster lookups
options.attributes = new Set(options.attributes);
}
const fileType = await getFileType(filePath);
const stats = fileType === Constants.FILETYPE_MBTILES
? await tileAnalyze(filePath, options)
: mapnikAnalyze(filePath, fileType, options);
return reportStats(stats, options);
}
module.exports = buildGeoStats;