blob: 775ccb64a864cde4bfd2ca4a5ddb0e4d772633b3 [file] [log] [blame]
Evan Siroky7891a6e2016-11-05 11:50:50 -07001var exec = require('child_process').exec
2var fs = require('fs')
evansirokyd401c892016-06-16 00:05:14 -07003
Evan Siroky477ece62017-08-01 07:08:51 -07004var area = require('@mapbox/geojson-area')
evansiroky70b35fe2018-04-01 21:06:36 -07005var geojsonhint = require('@mapbox/geojsonhint')
evansiroky0ea1d1e2018-10-30 22:30:51 -07006var bbox = require('@turf/bbox').default
Evan Siroky8326cf02017-03-02 08:27:55 -08007var helpers = require('@turf/helpers')
Evan Siroky070bbb92017-03-07 23:48:29 -08008var multiPolygon = helpers.multiPolygon
Evan Siroky8326cf02017-03-02 08:27:55 -08009var polygon = helpers.polygon
Evan Siroky7891a6e2016-11-05 11:50:50 -070010var asynclib = require('async')
11var jsts = require('jsts')
Evan Sirokyb57a5b92016-11-07 10:22:34 -080012var rimraf = require('rimraf')
Evan Siroky7891a6e2016-11-05 11:50:50 -070013var overpass = require('query-overpass')
Neil Fullerc4ae49b2020-04-30 18:08:43 +010014var yargs = require('yargs')
Neil Fuller01803192020-08-14 11:19:42 +010015var path = require('path')
evansirokyd401c892016-06-16 00:05:14 -070016
evansiroky5348a6f2019-01-05 15:39:28 -080017const ProgressStats = require('./progressStats')
18
Evan Siroky7891a6e2016-11-05 11:50:50 -070019var osmBoundarySources = require('./osmBoundarySources.json')
20var zoneCfg = require('./timezones.json')
evansiroky0ea1d1e2018-10-30 22:30:51 -070021var expectedZoneOverlaps = require('./expectedZoneOverlaps.json')
Evan Siroky081648a2017-07-04 09:53:36 -070022
Neil Fullerc4ae49b2020-04-30 18:08:43 +010023const argv = yargs
24 .option('included_zones', {
25 description: 'Include specified zones',
26 type: 'array'
27 })
Neil Fuller2b4b80a2020-04-30 18:20:56 +010028 .option('excluded_zones', {
29 description: 'Exclude specified zones',
30 type: 'array'
31 })
Neil Fullera4e73272020-04-30 18:25:44 +010032 .option('downloads_dir', {
33 description: 'Set the download location',
34 default: './downloads',
35 type: 'string'
36 })
37 .option('dist_dir', {
38 description: 'Set the dist location',
39 default: './dist',
40 type: 'string'
41 })
Neil Fullerc4ae49b2020-04-30 18:08:43 +010042 .option('no_validation', {
43 description: 'Skip validation',
44 type: 'boolean'
45 })
Neil Fullera83cc6d2020-04-30 18:37:08 +010046 .option('skip_zip', {
47 description: 'Skip zip creation',
48 type: 'boolean'
49 })
50 .option('skip_shapefile', {
51 description: 'Skip shapefile creation',
52 type: 'boolean'
53 })
Neil Fullerc4ae49b2020-04-30 18:08:43 +010054 .help()
55 .strict()
56 .alias('help', 'h')
57 .argv
58
Neil Fuller01803192020-08-14 11:19:42 +010059// Resolve the arguments with paths so relative paths become absolute.
60let downloads_dir = path.resolve(argv.downloads_dir)
61let dist_dir = path.resolve(argv.dist_dir)
62
Evan Siroky081648a2017-07-04 09:53:36 -070063// allow building of only a specified zones
Neil Fullerc4ae49b2020-04-30 18:08:43 +010064let includedZones = []
Neil Fuller2b4b80a2020-04-30 18:20:56 +010065let excludedZones = []
66if (argv.included_zones || argv.excluded_zones) {
67 if (argv.included_zones) {
68 let newZoneCfg = {}
69 includedZones = argv.included_zones
70 includedZones.forEach((zoneName) => {
71 newZoneCfg[zoneName] = zoneCfg[zoneName]
72 })
73 zoneCfg = newZoneCfg
74 }
75 if (argv.excluded_zones) {
76 let newZoneCfg = {}
77 excludedZones = argv.excluded_zones
78 Object.keys(zoneCfg).forEach((zoneName) => {
79 if (!excludedZones.includes(zoneName)) {
80 newZoneCfg[zoneName] = zoneCfg[zoneName]
81 }
82 })
83 zoneCfg = newZoneCfg
84 }
Evan Siroky081648a2017-07-04 09:53:36 -070085
86 // filter out unneccessary downloads
87 var newOsmBoundarySources = {}
88 Object.keys(zoneCfg).forEach((zoneName) => {
89 zoneCfg[zoneName].forEach((op) => {
90 if (op.source === 'overpass') {
91 newOsmBoundarySources[op.id] = osmBoundarySources[op.id]
92 }
93 })
94 })
95
96 osmBoundarySources = newOsmBoundarySources
97}
98
Evan Siroky7891a6e2016-11-05 11:50:50 -070099var geoJsonReader = new jsts.io.GeoJSONReader()
100var geoJsonWriter = new jsts.io.GeoJSONWriter()
Evan Siroky477ece62017-08-01 07:08:51 -0700101var precisionModel = new jsts.geom.PrecisionModel(1000000)
102var precisionReducer = new jsts.precision.GeometryPrecisionReducer(precisionModel)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700103var distZones = {}
Evan Sirokyb57a5b92016-11-07 10:22:34 -0800104var minRequestGap = 4
105var curRequestGap = 4
evansirokyd401c892016-06-16 00:05:14 -0700106
Evan Siroky7891a6e2016-11-05 11:50:50 -0700107var safeMkdir = function (dirname, callback) {
108 fs.mkdir(dirname, function (err) {
109 if (err && err.code === 'EEXIST') {
evansiroky4be1c7a2016-06-16 18:23:34 -0700110 callback()
111 } else {
112 callback(err)
113 }
114 })
115}
116
Evan Sirokyb173fd42017-03-08 15:16:27 -0800117var debugGeo = function (op, a, b, reducePrecision) {
evansirokybecb56e2016-07-06 12:42:35 -0700118 var result
119
Evan Sirokyb173fd42017-03-08 15:16:27 -0800120 if (reducePrecision) {
Evan Sirokyb173fd42017-03-08 15:16:27 -0800121 a = precisionReducer.reduce(a)
122 b = precisionReducer.reduce(b)
123 }
124
evansiroky6f9d8f72016-06-21 16:27:54 -0700125 try {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700126 switch (op) {
evansiroky6f9d8f72016-06-21 16:27:54 -0700127 case 'union':
evansirokybecb56e2016-07-06 12:42:35 -0700128 result = a.union(b)
evansiroky6f9d8f72016-06-21 16:27:54 -0700129 break
130 case 'intersection':
evansirokybecb56e2016-07-06 12:42:35 -0700131 result = a.intersection(b)
evansiroky6f9d8f72016-06-21 16:27:54 -0700132 break
Evan Siroky070bbb92017-03-07 23:48:29 -0800133 case 'intersects':
134 result = a.intersects(b)
135 break
evansiroky6f9d8f72016-06-21 16:27:54 -0700136 case 'diff':
Evan Sirokyb173fd42017-03-08 15:16:27 -0800137 result = a.difference(b)
evansiroky6f9d8f72016-06-21 16:27:54 -0700138 break
139 default:
140 var err = new Error('invalid op: ' + op)
141 throw err
142 }
Evan Siroky7891a6e2016-11-05 11:50:50 -0700143 } catch (e) {
Evan Sirokyb173fd42017-03-08 15:16:27 -0800144 if (e.name === 'TopologyException') {
145 console.log('Encountered TopologyException, retry with GeometryPrecisionReducer')
146 return debugGeo(op, a, b, true)
147 }
evansiroky6f9d8f72016-06-21 16:27:54 -0700148 console.log('op err')
evansirokybecb56e2016-07-06 12:42:35 -0700149 console.log(e)
150 console.log(e.stack)
151 fs.writeFileSync('debug_' + op + '_a.json', JSON.stringify(geoJsonWriter.write(a)))
152 fs.writeFileSync('debug_' + op + '_b.json', JSON.stringify(geoJsonWriter.write(b)))
evansiroky6f9d8f72016-06-21 16:27:54 -0700153 throw e
154 }
evansiroky6f9d8f72016-06-21 16:27:54 -0700155
evansirokybecb56e2016-07-06 12:42:35 -0700156 return result
evansiroky4be1c7a2016-06-16 18:23:34 -0700157}
158
Evan Siroky070bbb92017-03-07 23:48:29 -0800159var fetchIfNeeded = function (file, superCallback, downloadCallback, fetchFn) {
160 // check for file that got downloaded
Evan Siroky7891a6e2016-11-05 11:50:50 -0700161 fs.stat(file, function (err) {
Evan Siroky070bbb92017-03-07 23:48:29 -0800162 if (!err) {
163 // file found, skip download steps
164 return superCallback()
165 }
166 // check for manual file that got fixed and needs validation
167 var fixedFile = file.replace('.json', '_fixed.json')
168 fs.stat(fixedFile, function (err) {
169 if (!err) {
170 // file found, return fixed file
171 return downloadCallback(null, require(fixedFile))
172 }
173 // no manual fixed file found, download from overpass
174 fetchFn()
175 })
evansiroky50216c62016-06-16 17:41:47 -0700176 })
177}
178
Evan Siroky7891a6e2016-11-05 11:50:50 -0700179var geoJsonToGeom = function (geoJson) {
Evan Siroky8326cf02017-03-02 08:27:55 -0800180 try {
181 return geoJsonReader.read(JSON.stringify(geoJson))
182 } catch (e) {
183 console.error('error converting geojson to geometry')
184 fs.writeFileSync('debug_geojson_read_error.json', JSON.stringify(geoJson))
185 throw e
186 }
Evan Siroky5669adc2016-07-07 17:25:31 -0700187}
188
Evan Siroky8b47abe2016-10-02 12:28:52 -0700189var geomToGeoJson = function (geom) {
190 return geoJsonWriter.write(geom)
191}
192
Evan Siroky7891a6e2016-11-05 11:50:50 -0700193var geomToGeoJsonString = function (geom) {
Evan Siroky5669adc2016-07-07 17:25:31 -0700194 return JSON.stringify(geoJsonWriter.write(geom))
195}
196
evansiroky5348a6f2019-01-05 15:39:28 -0800197const downloadProgress = new ProgressStats(
198 'Downloading',
199 Object.keys(osmBoundarySources).length
200)
201
Evan Siroky7891a6e2016-11-05 11:50:50 -0700202var downloadOsmBoundary = function (boundaryId, boundaryCallback) {
203 var cfg = osmBoundarySources[boundaryId]
Evan Siroky1bcd4772017-10-14 23:47:21 -0700204 var query = '[out:json][timeout:60];('
205 if (cfg.way) {
206 query += 'way'
207 } else {
208 query += 'relation'
209 }
Neil Fuller01803192020-08-14 11:19:42 +0100210 var boundaryFilename = downloads_dir + '/' + boundaryId + '.json'
Evan Siroky7891a6e2016-11-05 11:50:50 -0700211 var debug = 'getting data for ' + boundaryId
212 var queryKeys = Object.keys(cfg)
evansiroky63d35e12016-06-16 10:08:15 -0700213
Evan Siroky5669adc2016-07-07 17:25:31 -0700214 for (var i = queryKeys.length - 1; i >= 0; i--) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700215 var k = queryKeys[i]
Evan Siroky1bcd4772017-10-14 23:47:21 -0700216 if (k === 'way') continue
Evan Siroky7891a6e2016-11-05 11:50:50 -0700217 var v = cfg[k]
Evan Siroky5669adc2016-07-07 17:25:31 -0700218
219 query += '["' + k + '"="' + v + '"]'
evansiroky63d35e12016-06-16 10:08:15 -0700220 }
221
evansiroky283ebbc2018-07-16 15:13:07 -0700222 query += ';);out body;>;out meta qt;'
evansiroky4be1c7a2016-06-16 18:23:34 -0700223
evansiroky5348a6f2019-01-05 15:39:28 -0800224 downloadProgress.beginTask(debug, true)
evansiroky63d35e12016-06-16 10:08:15 -0700225
Evan Siroky7891a6e2016-11-05 11:50:50 -0700226 asynclib.auto({
227 downloadFromOverpass: function (cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800228 console.log('downloading from overpass')
Evan Siroky070bbb92017-03-07 23:48:29 -0800229 fetchIfNeeded(boundaryFilename, boundaryCallback, cb, function () {
Evan Sirokyb57a5b92016-11-07 10:22:34 -0800230 var overpassResponseHandler = function (err, data) {
231 if (err) {
232 console.log(err)
233 console.log('Increasing overpass request gap')
234 curRequestGap *= 2
235 makeQuery()
236 } else {
237 console.log('Success, decreasing overpass request gap')
238 curRequestGap = Math.max(minRequestGap, curRequestGap / 2)
239 cb(null, data)
240 }
241 }
242 var makeQuery = function () {
243 console.log('waiting ' + curRequestGap + ' seconds')
244 setTimeout(function () {
245 overpass(query, overpassResponseHandler, { flatProperties: true })
246 }, curRequestGap * 1000)
247 }
248 makeQuery()
evansiroky63d35e12016-06-16 10:08:15 -0700249 })
250 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700251 validateOverpassResult: ['downloadFromOverpass', function (results, cb) {
evansiroky63d35e12016-06-16 10:08:15 -0700252 var data = results.downloadFromOverpass
evansiroky70b35fe2018-04-01 21:06:36 -0700253 if (!data.features) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700254 var err = new Error('Invalid geojson for boundary: ' + boundaryId)
evansiroky63d35e12016-06-16 10:08:15 -0700255 return cb(err)
256 }
evansiroky70b35fe2018-04-01 21:06:36 -0700257 if (data.features.length === 0) {
258 console.error('No data for the following query:')
259 console.error(query)
260 console.error('To read more about this error, please visit https://git.io/vxKQL')
evansiroky0ea1d1e2018-10-30 22:30:51 -0700261 return cb(new Error('No data found for from overpass query'))
evansiroky70b35fe2018-04-01 21:06:36 -0700262 }
evansiroky63d35e12016-06-16 10:08:15 -0700263 cb()
264 }],
Evan Siroky7891a6e2016-11-05 11:50:50 -0700265 saveSingleMultiPolygon: ['validateOverpassResult', function (results, cb) {
266 var data = results.downloadFromOverpass
267 var combined
evansiroky63d35e12016-06-16 10:08:15 -0700268
269 // union all multi-polygons / polygons into one
270 for (var i = data.features.length - 1; i >= 0; i--) {
Evan Siroky5669adc2016-07-07 17:25:31 -0700271 var curOsmGeom = data.features[i].geometry
evansiroky92c15c42018-11-15 20:58:18 -0800272 const curOsmProps = data.features[i].properties
273 if (
274 (curOsmGeom.type === 'Polygon' || curOsmGeom.type === 'MultiPolygon') &&
275 curOsmProps.type === 'boundary' // need to make sure enclaves aren't unioned
276 ) {
evansiroky63d35e12016-06-16 10:08:15 -0700277 console.log('combining border')
evansiroky70b35fe2018-04-01 21:06:36 -0700278 let errors = geojsonhint.hint(curOsmGeom)
279 if (errors && errors.length > 0) {
280 const stringifiedGeojson = JSON.stringify(curOsmGeom, null, 2)
281 errors = geojsonhint.hint(stringifiedGeojson)
282 console.error('Invalid geojson received in Overpass Result')
283 console.error('Overpass query: ' + query)
284 const problemFilename = boundaryId + '_convert_to_geom_error.json'
285 fs.writeFileSync(problemFilename, stringifiedGeojson)
286 console.error('saved problem file to ' + problemFilename)
287 console.error('To read more about this error, please visit https://git.io/vxKQq')
288 return cb(errors)
289 }
Evan Siroky070bbb92017-03-07 23:48:29 -0800290 try {
291 var curGeom = geoJsonToGeom(curOsmGeom)
292 } catch (e) {
293 console.error('error converting overpass result to geojson')
Evan Siroky477ece62017-08-01 07:08:51 -0700294 console.error(e)
evansiroky70b35fe2018-04-01 21:06:36 -0700295
Evan Siroky1bcd4772017-10-14 23:47:21 -0700296 fs.writeFileSync(boundaryId + '_convert_to_geom_error-all-features.json', JSON.stringify(data))
evansiroky70b35fe2018-04-01 21:06:36 -0700297 return cb(e)
Evan Siroky070bbb92017-03-07 23:48:29 -0800298 }
Evan Siroky7891a6e2016-11-05 11:50:50 -0700299 if (!combined) {
evansiroky63d35e12016-06-16 10:08:15 -0700300 combined = curGeom
301 } else {
Evan Siroky5669adc2016-07-07 17:25:31 -0700302 combined = debugGeo('union', curGeom, combined)
evansiroky63d35e12016-06-16 10:08:15 -0700303 }
304 }
305 }
Evan Siroky081c8e42017-05-29 14:53:52 -0700306 try {
307 fs.writeFile(boundaryFilename, geomToGeoJsonString(combined), cb)
308 } catch (e) {
309 console.error('error writing combined border to geojson')
310 fs.writeFileSync(boundaryId + '_combined_border_convert_to_geom_error.json', JSON.stringify(data))
evansiroky70b35fe2018-04-01 21:06:36 -0700311 return cb(e)
Evan Siroky081c8e42017-05-29 14:53:52 -0700312 }
evansiroky63d35e12016-06-16 10:08:15 -0700313 }]
314 }, boundaryCallback)
315}
evansirokyd401c892016-06-16 00:05:14 -0700316
Evan Siroky4fc596c2016-09-25 19:52:30 -0700317var getTzDistFilename = function (tzid) {
Neil Fuller01803192020-08-14 11:19:42 +0100318 return dist_dir + '/' + tzid.replace(/\//g, '__') + '.json'
Evan Siroky4fc596c2016-09-25 19:52:30 -0700319}
320
321/**
322 * Get the geometry of the requested source data
323 *
324 * @return {Object} geom The geometry of the source
325 * @param {Object} source An object representing the data source
326 * must have `source` key and then either:
327 * - `id` if from a file
328 * - `id` if from a file
329 */
Evan Siroky7891a6e2016-11-05 11:50:50 -0700330var getDataSource = function (source) {
evansirokybecb56e2016-07-06 12:42:35 -0700331 var geoJson
Evan Siroky7891a6e2016-11-05 11:50:50 -0700332 if (source.source === 'overpass') {
Neil Fuller01803192020-08-14 11:19:42 +0100333 geoJson = require(downloads_dir + '/' + source.id + '.json')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700334 } else if (source.source === 'manual-polygon') {
evansirokybecb56e2016-07-06 12:42:35 -0700335 geoJson = polygon(source.data).geometry
Evan Siroky7891a6e2016-11-05 11:50:50 -0700336 } else if (source.source === 'manual-multipolygon') {
Evan Siroky8e30a2e2016-08-06 19:55:35 -0700337 geoJson = multiPolygon(source.data).geometry
Evan Siroky7891a6e2016-11-05 11:50:50 -0700338 } else if (source.source === 'dist') {
Evan Siroky4fc596c2016-09-25 19:52:30 -0700339 geoJson = require(getTzDistFilename(source.id))
evansiroky4be1c7a2016-06-16 18:23:34 -0700340 } else {
341 var err = new Error('unknown source: ' + source.source)
342 throw err
343 }
Evan Siroky5669adc2016-07-07 17:25:31 -0700344 return geoJsonToGeom(geoJson)
evansiroky4be1c7a2016-06-16 18:23:34 -0700345}
346
Evan Siroky477ece62017-08-01 07:08:51 -0700347/**
348 * Post process created timezone boundary.
349 * - remove small holes and exclaves
350 * - reduce geometry precision
351 *
352 * @param {Geometry} geom The jsts geometry of the timezone
evansiroky26325842018-04-03 14:10:42 -0700353 * @param {boolean} returnAsObject if true, return as object, otherwise return stringified
354 * @return {Object|String} geojson as object or stringified
Evan Siroky477ece62017-08-01 07:08:51 -0700355 */
evansiroky26325842018-04-03 14:10:42 -0700356var postProcessZone = function (geom, returnAsObject) {
Evan Siroky477ece62017-08-01 07:08:51 -0700357 // reduce precision of geometry
358 const geojson = geomToGeoJson(precisionReducer.reduce(geom))
359
360 // iterate through all polygons
361 const filteredPolygons = []
362 let allPolygons = geojson.coordinates
363 if (geojson.type === 'Polygon') {
364 allPolygons = [geojson.coordinates]
365 }
366
367 allPolygons.forEach((curPolygon, idx) => {
368 // remove any polygon with very small area
369 const polygonFeature = polygon(curPolygon)
370 const polygonArea = area.geometry(polygonFeature.geometry)
371
372 if (polygonArea < 1) return
373
374 // find all holes
375 const filteredLinearRings = []
376
377 curPolygon.forEach((curLinearRing, lrIdx) => {
378 if (lrIdx === 0) {
379 // always keep first linearRing
380 filteredLinearRings.push(curLinearRing)
381 } else {
382 const polygonFromLinearRing = polygon([curLinearRing])
383 const linearRingArea = area.geometry(polygonFromLinearRing.geometry)
384
385 // only include holes with relevant area
386 if (linearRingArea > 1) {
387 filteredLinearRings.push(curLinearRing)
388 }
389 }
390 })
391
392 filteredPolygons.push(filteredLinearRings)
393 })
394
395 // recompile to geojson string
396 const newGeojson = {
397 type: geojson.type
398 }
399
400 if (geojson.type === 'Polygon') {
401 newGeojson.coordinates = filteredPolygons[0]
402 } else {
403 newGeojson.coordinates = filteredPolygons
404 }
405
evansiroky26325842018-04-03 14:10:42 -0700406 return returnAsObject ? newGeojson : JSON.stringify(newGeojson)
Evan Siroky477ece62017-08-01 07:08:51 -0700407}
408
evansiroky5348a6f2019-01-05 15:39:28 -0800409const buildingProgress = new ProgressStats(
410 'Building',
411 Object.keys(zoneCfg).length
412)
413
Evan Siroky7891a6e2016-11-05 11:50:50 -0700414var makeTimezoneBoundary = function (tzid, callback) {
evansiroky3046a3d2019-01-05 21:19:14 -0800415 buildingProgress.beginTask(`makeTimezoneBoundary for ${tzid}`, true)
evansiroky35f64342016-06-16 22:17:04 -0700416
Evan Siroky7891a6e2016-11-05 11:50:50 -0700417 var ops = zoneCfg[tzid]
418 var geom
evansiroky4be1c7a2016-06-16 18:23:34 -0700419
Evan Siroky7891a6e2016-11-05 11:50:50 -0700420 asynclib.eachSeries(ops, function (task, cb) {
evansiroky4be1c7a2016-06-16 18:23:34 -0700421 var taskData = getDataSource(task)
evansiroky6f9d8f72016-06-21 16:27:54 -0700422 console.log('-', task.op, task.id)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700423 if (task.op === 'init') {
evansiroky4be1c7a2016-06-16 18:23:34 -0700424 geom = taskData
Evan Siroky7891a6e2016-11-05 11:50:50 -0700425 } else if (task.op === 'intersect') {
evansiroky6f9d8f72016-06-21 16:27:54 -0700426 geom = debugGeo('intersection', geom, taskData)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700427 } else if (task.op === 'difference') {
evansiroky6f9d8f72016-06-21 16:27:54 -0700428 geom = debugGeo('diff', geom, taskData)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700429 } else if (task.op === 'difference-reverse-order') {
Evan Siroky8ccaf0b2016-09-03 11:36:13 -0700430 geom = debugGeo('diff', taskData, geom)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700431 } else if (task.op === 'union') {
evansiroky6f9d8f72016-06-21 16:27:54 -0700432 geom = debugGeo('union', geom, taskData)
Evan Siroky8ccaf0b2016-09-03 11:36:13 -0700433 } else {
434 var err = new Error('unknown op: ' + task.op)
435 return cb(err)
evansiroky4be1c7a2016-06-16 18:23:34 -0700436 }
evansiroky35f64342016-06-16 22:17:04 -0700437 cb()
Evan Siroky4fc596c2016-09-25 19:52:30 -0700438 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700439 function (err) {
440 if (err) { return callback(err) }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700441 fs.writeFile(getTzDistFilename(tzid),
Evan Siroky477ece62017-08-01 07:08:51 -0700442 postProcessZone(geom),
evansirokybecb56e2016-07-06 12:42:35 -0700443 callback)
evansiroky4be1c7a2016-06-16 18:23:34 -0700444 })
445}
446
Evan Siroky4fc596c2016-09-25 19:52:30 -0700447var loadDistZonesIntoMemory = function () {
448 console.log('load zones into memory')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700449 var zones = Object.keys(zoneCfg)
450 var tzid
Evan Siroky4fc596c2016-09-25 19:52:30 -0700451
452 for (var i = 0; i < zones.length; i++) {
453 tzid = zones[i]
454 distZones[tzid] = getDataSource({ source: 'dist', id: tzid })
455 }
456}
457
458var getDistZoneGeom = function (tzid) {
459 return distZones[tzid]
460}
461
evansiroky92c15c42018-11-15 20:58:18 -0800462var roundDownToTenth = function (n) {
463 return Math.floor(n * 10) / 10
464}
465
466var roundUpToTenth = function (n) {
467 return Math.ceil(n * 10) / 10
468}
469
470var formatBounds = function (bounds) {
471 let boundsStr = '['
472 boundsStr += roundDownToTenth(bounds[0]) + ', '
473 boundsStr += roundDownToTenth(bounds[1]) + ', '
474 boundsStr += roundUpToTenth(bounds[2]) + ', '
475 boundsStr += roundUpToTenth(bounds[3]) + ']'
476 return boundsStr
477}
478
Evan Siroky4fc596c2016-09-25 19:52:30 -0700479var validateTimezoneBoundaries = function () {
evansiroky5348a6f2019-01-05 15:39:28 -0800480 const numZones = Object.keys(zoneCfg).length
481 const validationProgress = new ProgressStats(
482 'Validation',
483 numZones * (numZones + 1) / 2
484 )
485
evansiroky26325842018-04-03 14:10:42 -0700486 console.log('do validation... this may take a few minutes')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700487 var allZonesOk = true
488 var zones = Object.keys(zoneCfg)
evansiroky3046a3d2019-01-05 21:19:14 -0800489 var lastPct = 0
Evan Siroky7891a6e2016-11-05 11:50:50 -0700490 var compareTzid, tzid, zoneGeom
Evan Siroky4fc596c2016-09-25 19:52:30 -0700491
492 for (var i = 0; i < zones.length; i++) {
493 tzid = zones[i]
494 zoneGeom = getDistZoneGeom(tzid)
495
496 for (var j = i + 1; j < zones.length; j++) {
evansiroky3046a3d2019-01-05 21:19:14 -0800497 const curPct = Math.floor(validationProgress.getPercentage())
498 if (curPct % 10 === 0 && curPct !== lastPct) {
evansiroky5348a6f2019-01-05 15:39:28 -0800499 validationProgress.printStats('Validating zones', true)
evansiroky3046a3d2019-01-05 21:19:14 -0800500 lastPct = curPct
evansiroky5348a6f2019-01-05 15:39:28 -0800501 }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700502 compareTzid = zones[j]
503
504 var compareZoneGeom = getDistZoneGeom(compareTzid)
Evan Siroky070bbb92017-03-07 23:48:29 -0800505
506 var intersects = false
507 try {
508 intersects = debugGeo('intersects', zoneGeom, compareZoneGeom)
509 } catch (e) {
510 console.warn('warning, encountered intersection error with zone ' + tzid + ' and ' + compareTzid)
511 }
512 if (intersects) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700513 var intersectedGeom = debugGeo('intersection', zoneGeom, compareZoneGeom)
514 var intersectedArea = intersectedGeom.getArea()
Evan Siroky4fc596c2016-09-25 19:52:30 -0700515
Evan Siroky7891a6e2016-11-05 11:50:50 -0700516 if (intersectedArea > 0.0001) {
evansiroky0ea1d1e2018-10-30 22:30:51 -0700517 // check if the intersected area(s) are one of the expected areas of overlap
518 const allowedOverlapBounds = expectedZoneOverlaps[`${tzid}-${compareTzid}`] || expectedZoneOverlaps[`${compareTzid}-${tzid}`]
519 const overlapsGeoJson = geoJsonWriter.write(intersectedGeom)
520
521 // these zones are allowed to overlap in certain places, make sure the
522 // found overlap(s) all fit within the expected areas of overlap
523 if (allowedOverlapBounds) {
524 // if the overlaps are a multipolygon, make sure each individual
525 // polygon of overlap fits within at least one of the expected
526 // overlaps
527 let overlapsPolygons
528 switch (overlapsGeoJson.type) {
evansiroky92c15c42018-11-15 20:58:18 -0800529 case 'MultiPolygon':
530 overlapsPolygons = overlapsGeoJson.coordinates.map(
531 polygonCoords => ({
532 coordinates: polygonCoords,
533 type: 'Polygon'
534 })
535 )
536 break
evansiroky0ea1d1e2018-10-30 22:30:51 -0700537 case 'Polygon':
538 overlapsPolygons = [overlapsGeoJson]
539 break
evansiroky92c15c42018-11-15 20:58:18 -0800540 case 'GeometryCollection':
541 overlapsPolygons = []
542 overlapsGeoJson.geometries.forEach(geom => {
543 if (geom.type === 'Polygon') {
544 overlapsPolygons.push(geom)
545 } else if (geom.type === 'MultiPolygon') {
546 geom.coordinates.forEach(polygonCoords => {
547 overlapsPolygons.push({
548 coordinates: polygonCoords,
549 type: 'Polygon'
550 })
551 })
552 }
553 })
554 break
evansiroky0ea1d1e2018-10-30 22:30:51 -0700555 default:
evansiroky92c15c42018-11-15 20:58:18 -0800556 console.error('unexpected geojson overlap type')
557 console.log(overlapsGeoJson)
evansiroky0ea1d1e2018-10-30 22:30:51 -0700558 break
559 }
560
561 let allOverlapsOk = true
562 overlapsPolygons.forEach((polygon, idx) => {
563 const bounds = bbox(polygon)
evansiroky92c15c42018-11-15 20:58:18 -0800564 const polygonArea = area.geometry(polygon)
evansiroky0ea1d1e2018-10-30 22:30:51 -0700565 if (
evansiroky92c15c42018-11-15 20:58:18 -0800566 polygonArea > 10 && // ignore small polygons
evansiroky0ea1d1e2018-10-30 22:30:51 -0700567 !allowedOverlapBounds.some(allowedBounds =>
evansiroky92c15c42018-11-15 20:58:18 -0800568 allowedBounds.bounds[0] <= bounds[0] && // minX
569 allowedBounds.bounds[1] <= bounds[1] && // minY
570 allowedBounds.bounds[2] >= bounds[2] && // maxX
571 allowedBounds.bounds[3] >= bounds[3] // maxY
evansiroky0ea1d1e2018-10-30 22:30:51 -0700572 )
573 ) {
evansiroky92c15c42018-11-15 20:58:18 -0800574 console.error(`Unexpected intersection (${polygonArea} area) with bounds: ${formatBounds(bounds)}`)
evansiroky0ea1d1e2018-10-30 22:30:51 -0700575 allOverlapsOk = false
576 }
577 })
578
579 if (allOverlapsOk) continue
580 }
581
evansiroky92c15c42018-11-15 20:58:18 -0800582 // at least one unexpected overlap found, output an error and write debug file
evansiroky70b35fe2018-04-01 21:06:36 -0700583 console.error('Validation error: ' + tzid + ' intersects ' + compareTzid + ' area: ' + intersectedArea)
evansiroky92c15c42018-11-15 20:58:18 -0800584 const debugFilename = tzid.replace(/\//g, '-') + '-' + compareTzid.replace(/\//g, '-') + '-overlap.json'
evansiroky70b35fe2018-04-01 21:06:36 -0700585 fs.writeFileSync(
586 debugFilename,
evansiroky0ea1d1e2018-10-30 22:30:51 -0700587 JSON.stringify(overlapsGeoJson)
evansiroky70b35fe2018-04-01 21:06:36 -0700588 )
589 console.error('wrote overlap area as file ' + debugFilename)
590 console.error('To read more about this error, please visit https://git.io/vx6nx')
Evan Siroky4fc596c2016-09-25 19:52:30 -0700591 allZonesOk = false
592 }
593 }
evansiroky5348a6f2019-01-05 15:39:28 -0800594 validationProgress.logNext()
Evan Siroky4fc596c2016-09-25 19:52:30 -0700595 }
596 }
597
598 return allZonesOk ? null : 'Zone validation unsuccessful'
Evan Siroky4fc596c2016-09-25 19:52:30 -0700599}
600
evansiroky26325842018-04-03 14:10:42 -0700601let oceanZoneBoundaries
evansiroky9fd50512019-07-07 12:06:28 -0700602let oceanZones = [
603 { tzid: 'Etc/GMT-12', left: 172.5, right: 180 },
604 { tzid: 'Etc/GMT-11', left: 157.5, right: 172.5 },
605 { tzid: 'Etc/GMT-10', left: 142.5, right: 157.5 },
606 { tzid: 'Etc/GMT-9', left: 127.5, right: 142.5 },
607 { tzid: 'Etc/GMT-8', left: 112.5, right: 127.5 },
608 { tzid: 'Etc/GMT-7', left: 97.5, right: 112.5 },
609 { tzid: 'Etc/GMT-6', left: 82.5, right: 97.5 },
610 { tzid: 'Etc/GMT-5', left: 67.5, right: 82.5 },
611 { tzid: 'Etc/GMT-4', left: 52.5, right: 67.5 },
612 { tzid: 'Etc/GMT-3', left: 37.5, right: 52.5 },
613 { tzid: 'Etc/GMT-2', left: 22.5, right: 37.5 },
614 { tzid: 'Etc/GMT-1', left: 7.5, right: 22.5 },
615 { tzid: 'Etc/GMT', left: -7.5, right: 7.5 },
616 { tzid: 'Etc/GMT+1', left: -22.5, right: -7.5 },
617 { tzid: 'Etc/GMT+2', left: -37.5, right: -22.5 },
618 { tzid: 'Etc/GMT+3', left: -52.5, right: -37.5 },
619 { tzid: 'Etc/GMT+4', left: -67.5, right: -52.5 },
620 { tzid: 'Etc/GMT+5', left: -82.5, right: -67.5 },
621 { tzid: 'Etc/GMT+6', left: -97.5, right: -82.5 },
622 { tzid: 'Etc/GMT+7', left: -112.5, right: -97.5 },
623 { tzid: 'Etc/GMT+8', left: -127.5, right: -112.5 },
624 { tzid: 'Etc/GMT+9', left: -142.5, right: -127.5 },
625 { tzid: 'Etc/GMT+10', left: -157.5, right: -142.5 },
626 { tzid: 'Etc/GMT+11', left: -172.5, right: -157.5 },
627 { tzid: 'Etc/GMT+12', left: -180, right: -172.5 }
628]
629
Neil Fullerc4ae49b2020-04-30 18:08:43 +0100630if (includedZones.length > 0) {
631 oceanZones = oceanZones.filter(oceanZone => includedZones.indexOf(oceanZone) > -1)
evansiroky9fd50512019-07-07 12:06:28 -0700632}
Neil Fuller2b4b80a2020-04-30 18:20:56 +0100633if (excludedZones.length > 0) {
634 oceanZones = oceanZones.filter(oceanZone => excludedZones.indexOf(oceanZone) === -1)
635}
evansiroky26325842018-04-03 14:10:42 -0700636
637var addOceans = function (callback) {
638 console.log('adding ocean boundaries')
evansiroky26325842018-04-03 14:10:42 -0700639 const zones = Object.keys(zoneCfg)
640
evansiroky3046a3d2019-01-05 21:19:14 -0800641 const oceanProgress = new ProgressStats(
642 'Oceans',
643 oceanZones.length
644 )
645
evansiroky26325842018-04-03 14:10:42 -0700646 oceanZoneBoundaries = oceanZones.map(zone => {
evansiroky3046a3d2019-01-05 21:19:14 -0800647 oceanProgress.beginTask(zone.tzid, true)
evansiroky26325842018-04-03 14:10:42 -0700648 const geoJson = polygon([[
649 [zone.left, 90],
evansiroky0ea1d1e2018-10-30 22:30:51 -0700650 [zone.left, -90],
651 [zone.right, -90],
652 [zone.right, 90],
evansiroky26325842018-04-03 14:10:42 -0700653 [zone.left, 90]
654 ]]).geometry
655
656 let geom = geoJsonToGeom(geoJson)
657
658 // diff against every zone
659 zones.forEach(distZone => {
660 geom = debugGeo('diff', geom, getDistZoneGeom(distZone))
661 })
662
663 return {
664 geom: postProcessZone(geom, true),
665 tzid: zone.tzid
666 }
667 })
668
669 callback()
670}
671
Evan Siroky7891a6e2016-11-05 11:50:50 -0700672var combineAndWriteZones = function (callback) {
Neil Fuller01803192020-08-14 11:19:42 +0100673 var stream = fs.createWriteStream(dist_dir + '/combined.json')
674 var streamWithOceans = fs.createWriteStream(dist_dir + '/combined-with-oceans.json')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700675 var zones = Object.keys(zoneCfg)
676
677 stream.write('{"type":"FeatureCollection","features":[')
evansiroky26325842018-04-03 14:10:42 -0700678 streamWithOceans.write('{"type":"FeatureCollection","features":[')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700679
680 for (var i = 0; i < zones.length; i++) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700681 if (i > 0) {
Evan Siroky8b47abe2016-10-02 12:28:52 -0700682 stream.write(',')
evansiroky26325842018-04-03 14:10:42 -0700683 streamWithOceans.write(',')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700684 }
685 var feature = {
686 type: 'Feature',
687 properties: { tzid: zones[i] },
688 geometry: geomToGeoJson(getDistZoneGeom(zones[i]))
689 }
evansiroky26325842018-04-03 14:10:42 -0700690 const stringified = JSON.stringify(feature)
691 stream.write(stringified)
692 streamWithOceans.write(stringified)
Evan Siroky8b47abe2016-10-02 12:28:52 -0700693 }
evansiroky26325842018-04-03 14:10:42 -0700694 oceanZoneBoundaries.forEach(boundary => {
695 streamWithOceans.write(',')
696 var feature = {
697 type: 'Feature',
698 properties: { tzid: boundary.tzid },
699 geometry: boundary.geom
700 }
701 streamWithOceans.write(JSON.stringify(feature))
702 })
703 asynclib.parallel([
704 cb => {
705 stream.end(']}', cb)
706 },
707 cb => {
708 streamWithOceans.end(']}', cb)
709 }
710 ], callback)
Evan Siroky8b47abe2016-10-02 12:28:52 -0700711}
712
evansiroky5348a6f2019-01-05 15:39:28 -0800713const autoScript = {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700714 makeDownloadsDir: function (cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800715 overallProgress.beginTask('Creating downloads dir')
Neil Fuller01803192020-08-14 11:19:42 +0100716 safeMkdir(downloads_dir, cb)
evansiroky4be1c7a2016-06-16 18:23:34 -0700717 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700718 makeDistDir: function (cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800719 overallProgress.beginTask('Creating dist dir')
Neil Fuller01803192020-08-14 11:19:42 +0100720 safeMkdir(dist_dir, cb)
evansirokyd401c892016-06-16 00:05:14 -0700721 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700722 getOsmBoundaries: ['makeDownloadsDir', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800723 overallProgress.beginTask('Downloading osm boundaries')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700724 asynclib.eachSeries(Object.keys(osmBoundarySources), downloadOsmBoundary, cb)
evansiroky63d35e12016-06-16 10:08:15 -0700725 }],
evansirokya48b3922020-04-27 15:29:06 -0700726 zipInputData: ['makeDistDir', 'getOsmBoundaries', function (results, cb) {
727 overallProgress.beginTask('Zipping up input data')
Neil Fuller01803192020-08-14 11:19:42 +0100728 exec('zip ' + dist_dir + '/input-data.zip ' + downloads_dir
729 + '/* timezones.json osmBoundarySources.json expectedZoneOverlaps.json', cb)
evansirokya48b3922020-04-27 15:29:06 -0700730 }],
Evan Siroky7891a6e2016-11-05 11:50:50 -0700731 createZones: ['makeDistDir', 'getOsmBoundaries', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800732 overallProgress.beginTask('Creating timezone boundaries')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700733 asynclib.each(Object.keys(zoneCfg), makeTimezoneBoundary, cb)
evansiroky50216c62016-06-16 17:41:47 -0700734 }],
Evan Siroky7891a6e2016-11-05 11:50:50 -0700735 validateZones: ['createZones', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800736 overallProgress.beginTask('Validating timezone boundaries')
Evan Siroky4fc596c2016-09-25 19:52:30 -0700737 loadDistZonesIntoMemory()
Neil Fullerc4ae49b2020-04-30 18:08:43 +0100738 if (argv.no_validation) {
Evan Siroky081648a2017-07-04 09:53:36 -0700739 console.warn('WARNING: Skipping validation!')
740 cb()
741 } else {
742 cb(validateTimezoneBoundaries())
743 }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700744 }],
evansiroky26325842018-04-03 14:10:42 -0700745 addOceans: ['validateZones', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800746 overallProgress.beginTask('Adding oceans')
evansiroky26325842018-04-03 14:10:42 -0700747 addOceans(cb)
748 }],
749 mergeZones: ['addOceans', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800750 overallProgress.beginTask('Merging zones')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700751 combineAndWriteZones(cb)
752 }],
753 zipGeoJson: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100754 if (argv.skip_zip) {
755 overallProgress.beginTask('Skipping zip')
Neil Fuller61287092020-07-29 14:46:16 +0100756 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100757 }
Neil Fuller61287092020-07-29 14:46:16 +0100758 overallProgress.beginTask('Zipping geojson')
Neil Fuller01803192020-08-14 11:19:42 +0100759 let zipFile = dist_dir + '/timezones.geojson.zip'
760 let jsonFile = dist_dir + '/combined.json'
Neil Fuller61287092020-07-29 14:46:16 +0100761 exec('zip ' + zipFile + ' ' + jsonFile, cb)
Evan Siroky8b47abe2016-10-02 12:28:52 -0700762 }],
evansiroky26325842018-04-03 14:10:42 -0700763 zipGeoJsonWithOceans: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100764 if (argv.skip_zip) {
765 overallProgress.beginTask('Skipping with oceans zip')
Neil Fuller61287092020-07-29 14:46:16 +0100766 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100767 }
Neil Fuller61287092020-07-29 14:46:16 +0100768 overallProgress.beginTask('Zipping geojson with oceans')
Neil Fuller01803192020-08-14 11:19:42 +0100769 let zipFile = dist_dir + '/timezones-with-oceans.geojson.zip'
770 let jsonFile = dist_dir + '/combined-with-oceans.json'
Neil Fuller61287092020-07-29 14:46:16 +0100771 exec('zip ' + zipFile + ' ' + jsonFile, cb)
evansiroky26325842018-04-03 14:10:42 -0700772 }],
Evan Siroky8b47abe2016-10-02 12:28:52 -0700773 makeShapefile: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100774 if (argv.skip_shapefile) {
775 overallProgress.beginTask('Skipping shapefile creation')
Neil Fuller61287092020-07-29 14:46:16 +0100776 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100777 }
Neil Fuller61287092020-07-29 14:46:16 +0100778 overallProgress.beginTask('Converting from geojson to shapefile')
Neil Fuller01803192020-08-14 11:19:42 +0100779 let shapeFileGlob = dist_dir + '/combined-shapefile.*'
Neil Fuller61287092020-07-29 14:46:16 +0100780 rimraf.sync(shapeFileGlob)
Neil Fuller01803192020-08-14 11:19:42 +0100781 let shapeFile = dist_dir + '/combined-shapefile.shp'
782 let jsonFile = dist_dir + '/combined.json'
Neil Fuller61287092020-07-29 14:46:16 +0100783 exec(
784 'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile,
785 function (err, stdout, stderr) {
786 if (err) { return cb(err) }
Neil Fuller01803192020-08-14 11:19:42 +0100787 let shapeFileZip = dist_dir + '/timezones.shapefile.zip'
Neil Fuller61287092020-07-29 14:46:16 +0100788 exec('zip ' + shapeFileZip + ' ' + shapeFileGlob, cb)
789 }
790 )
evansiroky26325842018-04-03 14:10:42 -0700791 }],
792 makeShapefileWithOceans: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100793 if (argv.skip_shapefile) {
794 overallProgress.beginTask('Skipping with oceans shapefile creation')
Neil Fuller61287092020-07-29 14:46:16 +0100795 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100796 }
Neil Fuller61287092020-07-29 14:46:16 +0100797 overallProgress.beginTask('Converting from geojson with oceans to shapefile')
Neil Fuller01803192020-08-14 11:19:42 +0100798 let shapeFileGlob = dist_dir + '/combined-shapefile-with-oceans.*'
Neil Fuller61287092020-07-29 14:46:16 +0100799 rimraf.sync(shapeFileGlob)
Neil Fuller01803192020-08-14 11:19:42 +0100800 let shapeFile = dist_dir + '/combined-shapefile-with-oceans.shp'
801 let jsonFile = dist_dir + '/combined-with-oceans.json'
Neil Fuller61287092020-07-29 14:46:16 +0100802 exec(
803 'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile,
804 function (err, stdout, stderr) {
805 if (err) { return cb(err) }
Neil Fuller01803192020-08-14 11:19:42 +0100806 let shapeFileZip = dist_dir + '/timezones-with-oceans.shapefile.zip'
Neil Fuller61287092020-07-29 14:46:16 +0100807 exec('zip ' + shapeFileZip + ' ' + shapeFileGlob, cb)
808 }
809 )
evansiroky9fd50512019-07-07 12:06:28 -0700810 }],
811 makeListOfTimeZoneNames: function (cb) {
812 overallProgress.beginTask('Writing timezone names to file')
813 let zoneNames = Object.keys(zoneCfg)
814 oceanZones.forEach(oceanZone => {
815 zoneNames.push(oceanZone.tzid)
816 })
Neil Fullerc4ae49b2020-04-30 18:08:43 +0100817 if (includedZones.length > 0) {
818 zoneNames = zoneNames.filter(zoneName => includedZones.indexOf(zoneName) > -1)
evansiroky9fd50512019-07-07 12:06:28 -0700819 }
Neil Fuller2b4b80a2020-04-30 18:20:56 +0100820 if (excludedZones.length > 0) {
821 zoneNames = zoneNames.filter(zoneName => excludedZones.indexOf(zoneName) === -1)
822 }
evansiroky9fd50512019-07-07 12:06:28 -0700823 fs.writeFile(
Neil Fuller01803192020-08-14 11:19:42 +0100824 dist_dir + '/timezone-names.json',
evansiroky9fd50512019-07-07 12:06:28 -0700825 JSON.stringify(zoneNames),
826 cb
827 )
828 }
evansiroky5348a6f2019-01-05 15:39:28 -0800829}
830
831const overallProgress = new ProgressStats('Overall', Object.keys(autoScript).length)
832
833asynclib.auto(autoScript, function (err, results) {
evansirokyd401c892016-06-16 00:05:14 -0700834 console.log('done')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700835 if (err) {
evansirokyd401c892016-06-16 00:05:14 -0700836 console.log('error!', err)
evansirokyd401c892016-06-16 00:05:14 -0700837 }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700838})