-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
37 lines (32 loc) · 1.37 KB
/
index.js
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
36
37
var getFileType = require('./lib/get-file-type');
var mapnikAnalyze = require('./lib/mapnik-analyze');
var tileAnalyze = require('./lib/tile-analyze');
var reportStats = require('./lib/report-stats');
var Constants = require('./lib/constants');
function buildGeoStats(filePath, options) {
options = options || {};
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);
}
// The number of unique values we'll count and record depends on
// the number of attributes we might record
var divisor = (options.attributes)
? Math.min(options.attributes.size, Constants.ATTRIBUTES_MAX_REPORT)
: Constants.ATTRIBUTES_MAX_REPORT;
options.maxValuesToCount = Math.floor(Constants.VALUES_MAX_COUNT / divisor);
options.maxValuesToReport = Math.floor(Constants.VALUES_MAX_REPORT / divisor);
return getFileType(filePath)
.then(function (fileType) {
if (fileType === Constants.FILETYPE_MBTILES) return tileAnalyze(filePath, options);
return mapnikAnalyze(filePath, fileType, options);
})
.then(function(stats) {
return reportStats(stats, options);
});
}
module.exports = buildGeoStats;