blob: 3425eb586ed3b7ef1d8d24cde296f65926bbfa7a [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')
evansirokyd401c892016-06-16 00:05:14 -070015
evansiroky5348a6f2019-01-05 15:39:28 -080016const ProgressStats = require('./progressStats')
17
Evan Siroky7891a6e2016-11-05 11:50:50 -070018var osmBoundarySources = require('./osmBoundarySources.json')
19var zoneCfg = require('./timezones.json')
evansiroky0ea1d1e2018-10-30 22:30:51 -070020var expectedZoneOverlaps = require('./expectedZoneOverlaps.json')
Evan Siroky081648a2017-07-04 09:53:36 -070021
Neil Fullerc4ae49b2020-04-30 18:08:43 +010022const argv = yargs
23 .option('included_zones', {
24 description: 'Include specified zones',
25 type: 'array'
26 })
Neil Fuller2b4b80a2020-04-30 18:20:56 +010027 .option('excluded_zones', {
28 description: 'Exclude specified zones',
29 type: 'array'
30 })
Neil Fullera4e73272020-04-30 18:25:44 +010031 .option('downloads_dir', {
32 description: 'Set the download location',
33 default: './downloads',
34 type: 'string'
35 })
36 .option('dist_dir', {
37 description: 'Set the dist location',
38 default: './dist',
39 type: 'string'
40 })
Neil Fullerc4ae49b2020-04-30 18:08:43 +010041 .option('no_validation', {
42 description: 'Skip validation',
43 type: 'boolean'
44 })
Neil Fullera83cc6d2020-04-30 18:37:08 +010045 .option('skip_zip', {
46 description: 'Skip zip creation',
47 type: 'boolean'
48 })
49 .option('skip_shapefile', {
50 description: 'Skip shapefile creation',
51 type: 'boolean'
52 })
Neil Fullerc4ae49b2020-04-30 18:08:43 +010053 .help()
54 .strict()
55 .alias('help', 'h')
56 .argv
57
Evan Siroky081648a2017-07-04 09:53:36 -070058// allow building of only a specified zones
Neil Fullerc4ae49b2020-04-30 18:08:43 +010059let includedZones = []
Neil Fuller2b4b80a2020-04-30 18:20:56 +010060let excludedZones = []
61if (argv.included_zones || argv.excluded_zones) {
62 if (argv.included_zones) {
63 let newZoneCfg = {}
64 includedZones = argv.included_zones
65 includedZones.forEach((zoneName) => {
66 newZoneCfg[zoneName] = zoneCfg[zoneName]
67 })
68 zoneCfg = newZoneCfg
69 }
70 if (argv.excluded_zones) {
71 let newZoneCfg = {}
72 excludedZones = argv.excluded_zones
73 Object.keys(zoneCfg).forEach((zoneName) => {
74 if (!excludedZones.includes(zoneName)) {
75 newZoneCfg[zoneName] = zoneCfg[zoneName]
76 }
77 })
78 zoneCfg = newZoneCfg
79 }
Evan Siroky081648a2017-07-04 09:53:36 -070080
81 // filter out unneccessary downloads
82 var newOsmBoundarySources = {}
83 Object.keys(zoneCfg).forEach((zoneName) => {
84 zoneCfg[zoneName].forEach((op) => {
85 if (op.source === 'overpass') {
86 newOsmBoundarySources[op.id] = osmBoundarySources[op.id]
87 }
88 })
89 })
90
91 osmBoundarySources = newOsmBoundarySources
92}
93
Evan Siroky7891a6e2016-11-05 11:50:50 -070094var geoJsonReader = new jsts.io.GeoJSONReader()
95var geoJsonWriter = new jsts.io.GeoJSONWriter()
Evan Siroky477ece62017-08-01 07:08:51 -070096var precisionModel = new jsts.geom.PrecisionModel(1000000)
97var precisionReducer = new jsts.precision.GeometryPrecisionReducer(precisionModel)
Evan Siroky7891a6e2016-11-05 11:50:50 -070098var distZones = {}
Evan Sirokyb57a5b92016-11-07 10:22:34 -080099var minRequestGap = 4
100var curRequestGap = 4
evansirokyd401c892016-06-16 00:05:14 -0700101
Evan Siroky7891a6e2016-11-05 11:50:50 -0700102var safeMkdir = function (dirname, callback) {
103 fs.mkdir(dirname, function (err) {
104 if (err && err.code === 'EEXIST') {
evansiroky4be1c7a2016-06-16 18:23:34 -0700105 callback()
106 } else {
107 callback(err)
108 }
109 })
110}
111
Evan Sirokyb173fd42017-03-08 15:16:27 -0800112var debugGeo = function (op, a, b, reducePrecision) {
evansirokybecb56e2016-07-06 12:42:35 -0700113 var result
114
Evan Sirokyb173fd42017-03-08 15:16:27 -0800115 if (reducePrecision) {
Evan Sirokyb173fd42017-03-08 15:16:27 -0800116 a = precisionReducer.reduce(a)
117 b = precisionReducer.reduce(b)
118 }
119
evansiroky6f9d8f72016-06-21 16:27:54 -0700120 try {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700121 switch (op) {
evansiroky6f9d8f72016-06-21 16:27:54 -0700122 case 'union':
evansirokybecb56e2016-07-06 12:42:35 -0700123 result = a.union(b)
evansiroky6f9d8f72016-06-21 16:27:54 -0700124 break
125 case 'intersection':
evansirokybecb56e2016-07-06 12:42:35 -0700126 result = a.intersection(b)
evansiroky6f9d8f72016-06-21 16:27:54 -0700127 break
Evan Siroky070bbb92017-03-07 23:48:29 -0800128 case 'intersects':
129 result = a.intersects(b)
130 break
evansiroky6f9d8f72016-06-21 16:27:54 -0700131 case 'diff':
Evan Sirokyb173fd42017-03-08 15:16:27 -0800132 result = a.difference(b)
evansiroky6f9d8f72016-06-21 16:27:54 -0700133 break
134 default:
135 var err = new Error('invalid op: ' + op)
136 throw err
137 }
Evan Siroky7891a6e2016-11-05 11:50:50 -0700138 } catch (e) {
Evan Sirokyb173fd42017-03-08 15:16:27 -0800139 if (e.name === 'TopologyException') {
140 console.log('Encountered TopologyException, retry with GeometryPrecisionReducer')
141 return debugGeo(op, a, b, true)
142 }
evansiroky6f9d8f72016-06-21 16:27:54 -0700143 console.log('op err')
evansirokybecb56e2016-07-06 12:42:35 -0700144 console.log(e)
145 console.log(e.stack)
146 fs.writeFileSync('debug_' + op + '_a.json', JSON.stringify(geoJsonWriter.write(a)))
147 fs.writeFileSync('debug_' + op + '_b.json', JSON.stringify(geoJsonWriter.write(b)))
evansiroky6f9d8f72016-06-21 16:27:54 -0700148 throw e
149 }
evansiroky6f9d8f72016-06-21 16:27:54 -0700150
evansirokybecb56e2016-07-06 12:42:35 -0700151 return result
evansiroky4be1c7a2016-06-16 18:23:34 -0700152}
153
Evan Siroky070bbb92017-03-07 23:48:29 -0800154var fetchIfNeeded = function (file, superCallback, downloadCallback, fetchFn) {
155 // check for file that got downloaded
Evan Siroky7891a6e2016-11-05 11:50:50 -0700156 fs.stat(file, function (err) {
Evan Siroky070bbb92017-03-07 23:48:29 -0800157 if (!err) {
158 // file found, skip download steps
159 return superCallback()
160 }
161 // check for manual file that got fixed and needs validation
162 var fixedFile = file.replace('.json', '_fixed.json')
163 fs.stat(fixedFile, function (err) {
164 if (!err) {
165 // file found, return fixed file
166 return downloadCallback(null, require(fixedFile))
167 }
168 // no manual fixed file found, download from overpass
169 fetchFn()
170 })
evansiroky50216c62016-06-16 17:41:47 -0700171 })
172}
173
Evan Siroky7891a6e2016-11-05 11:50:50 -0700174var geoJsonToGeom = function (geoJson) {
Evan Siroky8326cf02017-03-02 08:27:55 -0800175 try {
176 return geoJsonReader.read(JSON.stringify(geoJson))
177 } catch (e) {
178 console.error('error converting geojson to geometry')
179 fs.writeFileSync('debug_geojson_read_error.json', JSON.stringify(geoJson))
180 throw e
181 }
Evan Siroky5669adc2016-07-07 17:25:31 -0700182}
183
Evan Siroky8b47abe2016-10-02 12:28:52 -0700184var geomToGeoJson = function (geom) {
185 return geoJsonWriter.write(geom)
186}
187
Evan Siroky7891a6e2016-11-05 11:50:50 -0700188var geomToGeoJsonString = function (geom) {
Evan Siroky5669adc2016-07-07 17:25:31 -0700189 return JSON.stringify(geoJsonWriter.write(geom))
190}
191
evansiroky5348a6f2019-01-05 15:39:28 -0800192const downloadProgress = new ProgressStats(
193 'Downloading',
194 Object.keys(osmBoundarySources).length
195)
196
Evan Siroky7891a6e2016-11-05 11:50:50 -0700197var downloadOsmBoundary = function (boundaryId, boundaryCallback) {
198 var cfg = osmBoundarySources[boundaryId]
Evan Siroky1bcd4772017-10-14 23:47:21 -0700199 var query = '[out:json][timeout:60];('
200 if (cfg.way) {
201 query += 'way'
202 } else {
203 query += 'relation'
204 }
Neil Fullera4e73272020-04-30 18:25:44 +0100205 var boundaryFilename = argv.downloads_dir + '/' + boundaryId + '.json'
Evan Siroky7891a6e2016-11-05 11:50:50 -0700206 var debug = 'getting data for ' + boundaryId
207 var queryKeys = Object.keys(cfg)
evansiroky63d35e12016-06-16 10:08:15 -0700208
Evan Siroky5669adc2016-07-07 17:25:31 -0700209 for (var i = queryKeys.length - 1; i >= 0; i--) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700210 var k = queryKeys[i]
Evan Siroky1bcd4772017-10-14 23:47:21 -0700211 if (k === 'way') continue
Evan Siroky7891a6e2016-11-05 11:50:50 -0700212 var v = cfg[k]
Evan Siroky5669adc2016-07-07 17:25:31 -0700213
214 query += '["' + k + '"="' + v + '"]'
evansiroky63d35e12016-06-16 10:08:15 -0700215 }
216
evansiroky283ebbc2018-07-16 15:13:07 -0700217 query += ';);out body;>;out meta qt;'
evansiroky4be1c7a2016-06-16 18:23:34 -0700218
evansiroky5348a6f2019-01-05 15:39:28 -0800219 downloadProgress.beginTask(debug, true)
evansiroky63d35e12016-06-16 10:08:15 -0700220
Evan Siroky7891a6e2016-11-05 11:50:50 -0700221 asynclib.auto({
222 downloadFromOverpass: function (cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800223 console.log('downloading from overpass')
Evan Siroky070bbb92017-03-07 23:48:29 -0800224 fetchIfNeeded(boundaryFilename, boundaryCallback, cb, function () {
Evan Sirokyb57a5b92016-11-07 10:22:34 -0800225 var overpassResponseHandler = function (err, data) {
226 if (err) {
227 console.log(err)
228 console.log('Increasing overpass request gap')
229 curRequestGap *= 2
230 makeQuery()
231 } else {
232 console.log('Success, decreasing overpass request gap')
233 curRequestGap = Math.max(minRequestGap, curRequestGap / 2)
234 cb(null, data)
235 }
236 }
237 var makeQuery = function () {
238 console.log('waiting ' + curRequestGap + ' seconds')
239 setTimeout(function () {
240 overpass(query, overpassResponseHandler, { flatProperties: true })
241 }, curRequestGap * 1000)
242 }
243 makeQuery()
evansiroky63d35e12016-06-16 10:08:15 -0700244 })
245 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700246 validateOverpassResult: ['downloadFromOverpass', function (results, cb) {
evansiroky63d35e12016-06-16 10:08:15 -0700247 var data = results.downloadFromOverpass
evansiroky70b35fe2018-04-01 21:06:36 -0700248 if (!data.features) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700249 var err = new Error('Invalid geojson for boundary: ' + boundaryId)
evansiroky63d35e12016-06-16 10:08:15 -0700250 return cb(err)
251 }
evansiroky70b35fe2018-04-01 21:06:36 -0700252 if (data.features.length === 0) {
253 console.error('No data for the following query:')
254 console.error(query)
255 console.error('To read more about this error, please visit https://git.io/vxKQL')
evansiroky0ea1d1e2018-10-30 22:30:51 -0700256 return cb(new Error('No data found for from overpass query'))
evansiroky70b35fe2018-04-01 21:06:36 -0700257 }
evansiroky63d35e12016-06-16 10:08:15 -0700258 cb()
259 }],
Evan Siroky7891a6e2016-11-05 11:50:50 -0700260 saveSingleMultiPolygon: ['validateOverpassResult', function (results, cb) {
261 var data = results.downloadFromOverpass
262 var combined
evansiroky63d35e12016-06-16 10:08:15 -0700263
264 // union all multi-polygons / polygons into one
265 for (var i = data.features.length - 1; i >= 0; i--) {
Evan Siroky5669adc2016-07-07 17:25:31 -0700266 var curOsmGeom = data.features[i].geometry
evansiroky92c15c42018-11-15 20:58:18 -0800267 const curOsmProps = data.features[i].properties
268 if (
269 (curOsmGeom.type === 'Polygon' || curOsmGeom.type === 'MultiPolygon') &&
270 curOsmProps.type === 'boundary' // need to make sure enclaves aren't unioned
271 ) {
evansiroky63d35e12016-06-16 10:08:15 -0700272 console.log('combining border')
evansiroky70b35fe2018-04-01 21:06:36 -0700273 let errors = geojsonhint.hint(curOsmGeom)
274 if (errors && errors.length > 0) {
275 const stringifiedGeojson = JSON.stringify(curOsmGeom, null, 2)
276 errors = geojsonhint.hint(stringifiedGeojson)
277 console.error('Invalid geojson received in Overpass Result')
278 console.error('Overpass query: ' + query)
279 const problemFilename = boundaryId + '_convert_to_geom_error.json'
280 fs.writeFileSync(problemFilename, stringifiedGeojson)
281 console.error('saved problem file to ' + problemFilename)
282 console.error('To read more about this error, please visit https://git.io/vxKQq')
283 return cb(errors)
284 }
Evan Siroky070bbb92017-03-07 23:48:29 -0800285 try {
286 var curGeom = geoJsonToGeom(curOsmGeom)
287 } catch (e) {
288 console.error('error converting overpass result to geojson')
Evan Siroky477ece62017-08-01 07:08:51 -0700289 console.error(e)
evansiroky70b35fe2018-04-01 21:06:36 -0700290
Evan Siroky1bcd4772017-10-14 23:47:21 -0700291 fs.writeFileSync(boundaryId + '_convert_to_geom_error-all-features.json', JSON.stringify(data))
evansiroky70b35fe2018-04-01 21:06:36 -0700292 return cb(e)
Evan Siroky070bbb92017-03-07 23:48:29 -0800293 }
Evan Siroky7891a6e2016-11-05 11:50:50 -0700294 if (!combined) {
evansiroky63d35e12016-06-16 10:08:15 -0700295 combined = curGeom
296 } else {
Evan Siroky5669adc2016-07-07 17:25:31 -0700297 combined = debugGeo('union', curGeom, combined)
evansiroky63d35e12016-06-16 10:08:15 -0700298 }
299 }
300 }
Evan Siroky081c8e42017-05-29 14:53:52 -0700301 try {
302 fs.writeFile(boundaryFilename, geomToGeoJsonString(combined), cb)
303 } catch (e) {
304 console.error('error writing combined border to geojson')
305 fs.writeFileSync(boundaryId + '_combined_border_convert_to_geom_error.json', JSON.stringify(data))
evansiroky70b35fe2018-04-01 21:06:36 -0700306 return cb(e)
Evan Siroky081c8e42017-05-29 14:53:52 -0700307 }
evansiroky63d35e12016-06-16 10:08:15 -0700308 }]
309 }, boundaryCallback)
310}
evansirokyd401c892016-06-16 00:05:14 -0700311
Evan Siroky4fc596c2016-09-25 19:52:30 -0700312var getTzDistFilename = function (tzid) {
Neil Fullera4e73272020-04-30 18:25:44 +0100313 return argv.dist_dir + '/' + tzid.replace(/\//g, '__') + '.json'
Evan Siroky4fc596c2016-09-25 19:52:30 -0700314}
315
316/**
317 * Get the geometry of the requested source data
318 *
319 * @return {Object} geom The geometry of the source
320 * @param {Object} source An object representing the data source
321 * must have `source` key and then either:
322 * - `id` if from a file
323 * - `id` if from a file
324 */
Evan Siroky7891a6e2016-11-05 11:50:50 -0700325var getDataSource = function (source) {
evansirokybecb56e2016-07-06 12:42:35 -0700326 var geoJson
Evan Siroky7891a6e2016-11-05 11:50:50 -0700327 if (source.source === 'overpass') {
Neil Fullera4e73272020-04-30 18:25:44 +0100328 geoJson = require(argv.downloads_dir + '/' + source.id + '.json')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700329 } else if (source.source === 'manual-polygon') {
evansirokybecb56e2016-07-06 12:42:35 -0700330 geoJson = polygon(source.data).geometry
Evan Siroky7891a6e2016-11-05 11:50:50 -0700331 } else if (source.source === 'manual-multipolygon') {
Evan Siroky8e30a2e2016-08-06 19:55:35 -0700332 geoJson = multiPolygon(source.data).geometry
Evan Siroky7891a6e2016-11-05 11:50:50 -0700333 } else if (source.source === 'dist') {
Evan Siroky4fc596c2016-09-25 19:52:30 -0700334 geoJson = require(getTzDistFilename(source.id))
evansiroky4be1c7a2016-06-16 18:23:34 -0700335 } else {
336 var err = new Error('unknown source: ' + source.source)
337 throw err
338 }
Evan Siroky5669adc2016-07-07 17:25:31 -0700339 return geoJsonToGeom(geoJson)
evansiroky4be1c7a2016-06-16 18:23:34 -0700340}
341
Evan Siroky477ece62017-08-01 07:08:51 -0700342/**
343 * Post process created timezone boundary.
344 * - remove small holes and exclaves
345 * - reduce geometry precision
346 *
347 * @param {Geometry} geom The jsts geometry of the timezone
evansiroky26325842018-04-03 14:10:42 -0700348 * @param {boolean} returnAsObject if true, return as object, otherwise return stringified
349 * @return {Object|String} geojson as object or stringified
Evan Siroky477ece62017-08-01 07:08:51 -0700350 */
evansiroky26325842018-04-03 14:10:42 -0700351var postProcessZone = function (geom, returnAsObject) {
Evan Siroky477ece62017-08-01 07:08:51 -0700352 // reduce precision of geometry
353 const geojson = geomToGeoJson(precisionReducer.reduce(geom))
354
355 // iterate through all polygons
356 const filteredPolygons = []
357 let allPolygons = geojson.coordinates
358 if (geojson.type === 'Polygon') {
359 allPolygons = [geojson.coordinates]
360 }
361
362 allPolygons.forEach((curPolygon, idx) => {
363 // remove any polygon with very small area
364 const polygonFeature = polygon(curPolygon)
365 const polygonArea = area.geometry(polygonFeature.geometry)
366
367 if (polygonArea < 1) return
368
369 // find all holes
370 const filteredLinearRings = []
371
372 curPolygon.forEach((curLinearRing, lrIdx) => {
373 if (lrIdx === 0) {
374 // always keep first linearRing
375 filteredLinearRings.push(curLinearRing)
376 } else {
377 const polygonFromLinearRing = polygon([curLinearRing])
378 const linearRingArea = area.geometry(polygonFromLinearRing.geometry)
379
380 // only include holes with relevant area
381 if (linearRingArea > 1) {
382 filteredLinearRings.push(curLinearRing)
383 }
384 }
385 })
386
387 filteredPolygons.push(filteredLinearRings)
388 })
389
390 // recompile to geojson string
391 const newGeojson = {
392 type: geojson.type
393 }
394
395 if (geojson.type === 'Polygon') {
396 newGeojson.coordinates = filteredPolygons[0]
397 } else {
398 newGeojson.coordinates = filteredPolygons
399 }
400
evansiroky26325842018-04-03 14:10:42 -0700401 return returnAsObject ? newGeojson : JSON.stringify(newGeojson)
Evan Siroky477ece62017-08-01 07:08:51 -0700402}
403
evansiroky5348a6f2019-01-05 15:39:28 -0800404const buildingProgress = new ProgressStats(
405 'Building',
406 Object.keys(zoneCfg).length
407)
408
Evan Siroky7891a6e2016-11-05 11:50:50 -0700409var makeTimezoneBoundary = function (tzid, callback) {
evansiroky3046a3d2019-01-05 21:19:14 -0800410 buildingProgress.beginTask(`makeTimezoneBoundary for ${tzid}`, true)
evansiroky35f64342016-06-16 22:17:04 -0700411
Evan Siroky7891a6e2016-11-05 11:50:50 -0700412 var ops = zoneCfg[tzid]
413 var geom
evansiroky4be1c7a2016-06-16 18:23:34 -0700414
Evan Siroky7891a6e2016-11-05 11:50:50 -0700415 asynclib.eachSeries(ops, function (task, cb) {
evansiroky4be1c7a2016-06-16 18:23:34 -0700416 var taskData = getDataSource(task)
evansiroky6f9d8f72016-06-21 16:27:54 -0700417 console.log('-', task.op, task.id)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700418 if (task.op === 'init') {
evansiroky4be1c7a2016-06-16 18:23:34 -0700419 geom = taskData
Evan Siroky7891a6e2016-11-05 11:50:50 -0700420 } else if (task.op === 'intersect') {
evansiroky6f9d8f72016-06-21 16:27:54 -0700421 geom = debugGeo('intersection', geom, taskData)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700422 } else if (task.op === 'difference') {
evansiroky6f9d8f72016-06-21 16:27:54 -0700423 geom = debugGeo('diff', geom, taskData)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700424 } else if (task.op === 'difference-reverse-order') {
Evan Siroky8ccaf0b2016-09-03 11:36:13 -0700425 geom = debugGeo('diff', taskData, geom)
Evan Siroky7891a6e2016-11-05 11:50:50 -0700426 } else if (task.op === 'union') {
evansiroky6f9d8f72016-06-21 16:27:54 -0700427 geom = debugGeo('union', geom, taskData)
Evan Siroky8ccaf0b2016-09-03 11:36:13 -0700428 } else {
429 var err = new Error('unknown op: ' + task.op)
430 return cb(err)
evansiroky4be1c7a2016-06-16 18:23:34 -0700431 }
evansiroky35f64342016-06-16 22:17:04 -0700432 cb()
Evan Siroky4fc596c2016-09-25 19:52:30 -0700433 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700434 function (err) {
435 if (err) { return callback(err) }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700436 fs.writeFile(getTzDistFilename(tzid),
Evan Siroky477ece62017-08-01 07:08:51 -0700437 postProcessZone(geom),
evansirokybecb56e2016-07-06 12:42:35 -0700438 callback)
evansiroky4be1c7a2016-06-16 18:23:34 -0700439 })
440}
441
Evan Siroky4fc596c2016-09-25 19:52:30 -0700442var loadDistZonesIntoMemory = function () {
443 console.log('load zones into memory')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700444 var zones = Object.keys(zoneCfg)
445 var tzid
Evan Siroky4fc596c2016-09-25 19:52:30 -0700446
447 for (var i = 0; i < zones.length; i++) {
448 tzid = zones[i]
449 distZones[tzid] = getDataSource({ source: 'dist', id: tzid })
450 }
451}
452
453var getDistZoneGeom = function (tzid) {
454 return distZones[tzid]
455}
456
evansiroky92c15c42018-11-15 20:58:18 -0800457var roundDownToTenth = function (n) {
458 return Math.floor(n * 10) / 10
459}
460
461var roundUpToTenth = function (n) {
462 return Math.ceil(n * 10) / 10
463}
464
465var formatBounds = function (bounds) {
466 let boundsStr = '['
467 boundsStr += roundDownToTenth(bounds[0]) + ', '
468 boundsStr += roundDownToTenth(bounds[1]) + ', '
469 boundsStr += roundUpToTenth(bounds[2]) + ', '
470 boundsStr += roundUpToTenth(bounds[3]) + ']'
471 return boundsStr
472}
473
Evan Siroky4fc596c2016-09-25 19:52:30 -0700474var validateTimezoneBoundaries = function () {
evansiroky5348a6f2019-01-05 15:39:28 -0800475 const numZones = Object.keys(zoneCfg).length
476 const validationProgress = new ProgressStats(
477 'Validation',
478 numZones * (numZones + 1) / 2
479 )
480
evansiroky26325842018-04-03 14:10:42 -0700481 console.log('do validation... this may take a few minutes')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700482 var allZonesOk = true
483 var zones = Object.keys(zoneCfg)
evansiroky3046a3d2019-01-05 21:19:14 -0800484 var lastPct = 0
Evan Siroky7891a6e2016-11-05 11:50:50 -0700485 var compareTzid, tzid, zoneGeom
Evan Siroky4fc596c2016-09-25 19:52:30 -0700486
487 for (var i = 0; i < zones.length; i++) {
488 tzid = zones[i]
489 zoneGeom = getDistZoneGeom(tzid)
490
491 for (var j = i + 1; j < zones.length; j++) {
evansiroky3046a3d2019-01-05 21:19:14 -0800492 const curPct = Math.floor(validationProgress.getPercentage())
493 if (curPct % 10 === 0 && curPct !== lastPct) {
evansiroky5348a6f2019-01-05 15:39:28 -0800494 validationProgress.printStats('Validating zones', true)
evansiroky3046a3d2019-01-05 21:19:14 -0800495 lastPct = curPct
evansiroky5348a6f2019-01-05 15:39:28 -0800496 }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700497 compareTzid = zones[j]
498
499 var compareZoneGeom = getDistZoneGeom(compareTzid)
Evan Siroky070bbb92017-03-07 23:48:29 -0800500
501 var intersects = false
502 try {
503 intersects = debugGeo('intersects', zoneGeom, compareZoneGeom)
504 } catch (e) {
505 console.warn('warning, encountered intersection error with zone ' + tzid + ' and ' + compareTzid)
506 }
507 if (intersects) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700508 var intersectedGeom = debugGeo('intersection', zoneGeom, compareZoneGeom)
509 var intersectedArea = intersectedGeom.getArea()
Evan Siroky4fc596c2016-09-25 19:52:30 -0700510
Evan Siroky7891a6e2016-11-05 11:50:50 -0700511 if (intersectedArea > 0.0001) {
evansiroky0ea1d1e2018-10-30 22:30:51 -0700512 // check if the intersected area(s) are one of the expected areas of overlap
513 const allowedOverlapBounds = expectedZoneOverlaps[`${tzid}-${compareTzid}`] || expectedZoneOverlaps[`${compareTzid}-${tzid}`]
514 const overlapsGeoJson = geoJsonWriter.write(intersectedGeom)
515
516 // these zones are allowed to overlap in certain places, make sure the
517 // found overlap(s) all fit within the expected areas of overlap
518 if (allowedOverlapBounds) {
519 // if the overlaps are a multipolygon, make sure each individual
520 // polygon of overlap fits within at least one of the expected
521 // overlaps
522 let overlapsPolygons
523 switch (overlapsGeoJson.type) {
evansiroky92c15c42018-11-15 20:58:18 -0800524 case 'MultiPolygon':
525 overlapsPolygons = overlapsGeoJson.coordinates.map(
526 polygonCoords => ({
527 coordinates: polygonCoords,
528 type: 'Polygon'
529 })
530 )
531 break
evansiroky0ea1d1e2018-10-30 22:30:51 -0700532 case 'Polygon':
533 overlapsPolygons = [overlapsGeoJson]
534 break
evansiroky92c15c42018-11-15 20:58:18 -0800535 case 'GeometryCollection':
536 overlapsPolygons = []
537 overlapsGeoJson.geometries.forEach(geom => {
538 if (geom.type === 'Polygon') {
539 overlapsPolygons.push(geom)
540 } else if (geom.type === 'MultiPolygon') {
541 geom.coordinates.forEach(polygonCoords => {
542 overlapsPolygons.push({
543 coordinates: polygonCoords,
544 type: 'Polygon'
545 })
546 })
547 }
548 })
549 break
evansiroky0ea1d1e2018-10-30 22:30:51 -0700550 default:
evansiroky92c15c42018-11-15 20:58:18 -0800551 console.error('unexpected geojson overlap type')
552 console.log(overlapsGeoJson)
evansiroky0ea1d1e2018-10-30 22:30:51 -0700553 break
554 }
555
556 let allOverlapsOk = true
557 overlapsPolygons.forEach((polygon, idx) => {
558 const bounds = bbox(polygon)
evansiroky92c15c42018-11-15 20:58:18 -0800559 const polygonArea = area.geometry(polygon)
evansiroky0ea1d1e2018-10-30 22:30:51 -0700560 if (
evansiroky92c15c42018-11-15 20:58:18 -0800561 polygonArea > 10 && // ignore small polygons
evansiroky0ea1d1e2018-10-30 22:30:51 -0700562 !allowedOverlapBounds.some(allowedBounds =>
evansiroky92c15c42018-11-15 20:58:18 -0800563 allowedBounds.bounds[0] <= bounds[0] && // minX
564 allowedBounds.bounds[1] <= bounds[1] && // minY
565 allowedBounds.bounds[2] >= bounds[2] && // maxX
566 allowedBounds.bounds[3] >= bounds[3] // maxY
evansiroky0ea1d1e2018-10-30 22:30:51 -0700567 )
568 ) {
evansiroky92c15c42018-11-15 20:58:18 -0800569 console.error(`Unexpected intersection (${polygonArea} area) with bounds: ${formatBounds(bounds)}`)
evansiroky0ea1d1e2018-10-30 22:30:51 -0700570 allOverlapsOk = false
571 }
572 })
573
574 if (allOverlapsOk) continue
575 }
576
evansiroky92c15c42018-11-15 20:58:18 -0800577 // at least one unexpected overlap found, output an error and write debug file
evansiroky70b35fe2018-04-01 21:06:36 -0700578 console.error('Validation error: ' + tzid + ' intersects ' + compareTzid + ' area: ' + intersectedArea)
evansiroky92c15c42018-11-15 20:58:18 -0800579 const debugFilename = tzid.replace(/\//g, '-') + '-' + compareTzid.replace(/\//g, '-') + '-overlap.json'
evansiroky70b35fe2018-04-01 21:06:36 -0700580 fs.writeFileSync(
581 debugFilename,
evansiroky0ea1d1e2018-10-30 22:30:51 -0700582 JSON.stringify(overlapsGeoJson)
evansiroky70b35fe2018-04-01 21:06:36 -0700583 )
584 console.error('wrote overlap area as file ' + debugFilename)
585 console.error('To read more about this error, please visit https://git.io/vx6nx')
Evan Siroky4fc596c2016-09-25 19:52:30 -0700586 allZonesOk = false
587 }
588 }
evansiroky5348a6f2019-01-05 15:39:28 -0800589 validationProgress.logNext()
Evan Siroky4fc596c2016-09-25 19:52:30 -0700590 }
591 }
592
593 return allZonesOk ? null : 'Zone validation unsuccessful'
Evan Siroky4fc596c2016-09-25 19:52:30 -0700594}
595
evansiroky26325842018-04-03 14:10:42 -0700596let oceanZoneBoundaries
evansiroky9fd50512019-07-07 12:06:28 -0700597let oceanZones = [
598 { tzid: 'Etc/GMT-12', left: 172.5, right: 180 },
599 { tzid: 'Etc/GMT-11', left: 157.5, right: 172.5 },
600 { tzid: 'Etc/GMT-10', left: 142.5, right: 157.5 },
601 { tzid: 'Etc/GMT-9', left: 127.5, right: 142.5 },
602 { tzid: 'Etc/GMT-8', left: 112.5, right: 127.5 },
603 { tzid: 'Etc/GMT-7', left: 97.5, right: 112.5 },
604 { tzid: 'Etc/GMT-6', left: 82.5, right: 97.5 },
605 { tzid: 'Etc/GMT-5', left: 67.5, right: 82.5 },
606 { tzid: 'Etc/GMT-4', left: 52.5, right: 67.5 },
607 { tzid: 'Etc/GMT-3', left: 37.5, right: 52.5 },
608 { tzid: 'Etc/GMT-2', left: 22.5, right: 37.5 },
609 { tzid: 'Etc/GMT-1', left: 7.5, right: 22.5 },
610 { tzid: 'Etc/GMT', left: -7.5, right: 7.5 },
611 { tzid: 'Etc/GMT+1', left: -22.5, right: -7.5 },
612 { tzid: 'Etc/GMT+2', left: -37.5, right: -22.5 },
613 { tzid: 'Etc/GMT+3', left: -52.5, right: -37.5 },
614 { tzid: 'Etc/GMT+4', left: -67.5, right: -52.5 },
615 { tzid: 'Etc/GMT+5', left: -82.5, right: -67.5 },
616 { tzid: 'Etc/GMT+6', left: -97.5, right: -82.5 },
617 { tzid: 'Etc/GMT+7', left: -112.5, right: -97.5 },
618 { tzid: 'Etc/GMT+8', left: -127.5, right: -112.5 },
619 { tzid: 'Etc/GMT+9', left: -142.5, right: -127.5 },
620 { tzid: 'Etc/GMT+10', left: -157.5, right: -142.5 },
621 { tzid: 'Etc/GMT+11', left: -172.5, right: -157.5 },
622 { tzid: 'Etc/GMT+12', left: -180, right: -172.5 }
623]
624
Neil Fullerc4ae49b2020-04-30 18:08:43 +0100625if (includedZones.length > 0) {
626 oceanZones = oceanZones.filter(oceanZone => includedZones.indexOf(oceanZone) > -1)
evansiroky9fd50512019-07-07 12:06:28 -0700627}
Neil Fuller2b4b80a2020-04-30 18:20:56 +0100628if (excludedZones.length > 0) {
629 oceanZones = oceanZones.filter(oceanZone => excludedZones.indexOf(oceanZone) === -1)
630}
evansiroky26325842018-04-03 14:10:42 -0700631
632var addOceans = function (callback) {
633 console.log('adding ocean boundaries')
evansiroky26325842018-04-03 14:10:42 -0700634 const zones = Object.keys(zoneCfg)
635
evansiroky3046a3d2019-01-05 21:19:14 -0800636 const oceanProgress = new ProgressStats(
637 'Oceans',
638 oceanZones.length
639 )
640
evansiroky26325842018-04-03 14:10:42 -0700641 oceanZoneBoundaries = oceanZones.map(zone => {
evansiroky3046a3d2019-01-05 21:19:14 -0800642 oceanProgress.beginTask(zone.tzid, true)
evansiroky26325842018-04-03 14:10:42 -0700643 const geoJson = polygon([[
644 [zone.left, 90],
evansiroky0ea1d1e2018-10-30 22:30:51 -0700645 [zone.left, -90],
646 [zone.right, -90],
647 [zone.right, 90],
evansiroky26325842018-04-03 14:10:42 -0700648 [zone.left, 90]
649 ]]).geometry
650
651 let geom = geoJsonToGeom(geoJson)
652
653 // diff against every zone
654 zones.forEach(distZone => {
655 geom = debugGeo('diff', geom, getDistZoneGeom(distZone))
656 })
657
658 return {
659 geom: postProcessZone(geom, true),
660 tzid: zone.tzid
661 }
662 })
663
664 callback()
665}
666
Evan Siroky7891a6e2016-11-05 11:50:50 -0700667var combineAndWriteZones = function (callback) {
Neil Fullera4e73272020-04-30 18:25:44 +0100668 var stream = fs.createWriteStream(argv.dist_dir + '/combined.json')
669 var streamWithOceans = fs.createWriteStream(argv.dist_dir + '/combined-with-oceans.json')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700670 var zones = Object.keys(zoneCfg)
671
672 stream.write('{"type":"FeatureCollection","features":[')
evansiroky26325842018-04-03 14:10:42 -0700673 streamWithOceans.write('{"type":"FeatureCollection","features":[')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700674
675 for (var i = 0; i < zones.length; i++) {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700676 if (i > 0) {
Evan Siroky8b47abe2016-10-02 12:28:52 -0700677 stream.write(',')
evansiroky26325842018-04-03 14:10:42 -0700678 streamWithOceans.write(',')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700679 }
680 var feature = {
681 type: 'Feature',
682 properties: { tzid: zones[i] },
683 geometry: geomToGeoJson(getDistZoneGeom(zones[i]))
684 }
evansiroky26325842018-04-03 14:10:42 -0700685 const stringified = JSON.stringify(feature)
686 stream.write(stringified)
687 streamWithOceans.write(stringified)
Evan Siroky8b47abe2016-10-02 12:28:52 -0700688 }
evansiroky26325842018-04-03 14:10:42 -0700689 oceanZoneBoundaries.forEach(boundary => {
690 streamWithOceans.write(',')
691 var feature = {
692 type: 'Feature',
693 properties: { tzid: boundary.tzid },
694 geometry: boundary.geom
695 }
696 streamWithOceans.write(JSON.stringify(feature))
697 })
698 asynclib.parallel([
699 cb => {
700 stream.end(']}', cb)
701 },
702 cb => {
703 streamWithOceans.end(']}', cb)
704 }
705 ], callback)
Evan Siroky8b47abe2016-10-02 12:28:52 -0700706}
707
evansiroky5348a6f2019-01-05 15:39:28 -0800708const autoScript = {
Evan Siroky7891a6e2016-11-05 11:50:50 -0700709 makeDownloadsDir: function (cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800710 overallProgress.beginTask('Creating downloads dir')
Neil Fullera4e73272020-04-30 18:25:44 +0100711 safeMkdir(argv.downloads_dir, cb)
evansiroky4be1c7a2016-06-16 18:23:34 -0700712 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700713 makeDistDir: function (cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800714 overallProgress.beginTask('Creating dist dir')
Neil Fullera4e73272020-04-30 18:25:44 +0100715 safeMkdir(argv.dist_dir, cb)
evansirokyd401c892016-06-16 00:05:14 -0700716 },
Evan Siroky7891a6e2016-11-05 11:50:50 -0700717 getOsmBoundaries: ['makeDownloadsDir', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800718 overallProgress.beginTask('Downloading osm boundaries')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700719 asynclib.eachSeries(Object.keys(osmBoundarySources), downloadOsmBoundary, cb)
evansiroky63d35e12016-06-16 10:08:15 -0700720 }],
evansirokya48b3922020-04-27 15:29:06 -0700721 zipInputData: ['makeDistDir', 'getOsmBoundaries', function (results, cb) {
722 overallProgress.beginTask('Zipping up input data')
723 exec('zip dist/input-data.zip downloads/* timezones.json osmBoundarySources.json expectedZoneOverlaps.json', cb)
724 }],
Evan Siroky7891a6e2016-11-05 11:50:50 -0700725 createZones: ['makeDistDir', 'getOsmBoundaries', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800726 overallProgress.beginTask('Creating timezone boundaries')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700727 asynclib.each(Object.keys(zoneCfg), makeTimezoneBoundary, cb)
evansiroky50216c62016-06-16 17:41:47 -0700728 }],
Evan Siroky7891a6e2016-11-05 11:50:50 -0700729 validateZones: ['createZones', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800730 overallProgress.beginTask('Validating timezone boundaries')
Evan Siroky4fc596c2016-09-25 19:52:30 -0700731 loadDistZonesIntoMemory()
Neil Fullerc4ae49b2020-04-30 18:08:43 +0100732 if (argv.no_validation) {
Evan Siroky081648a2017-07-04 09:53:36 -0700733 console.warn('WARNING: Skipping validation!')
734 cb()
735 } else {
736 cb(validateTimezoneBoundaries())
737 }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700738 }],
evansiroky26325842018-04-03 14:10:42 -0700739 addOceans: ['validateZones', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800740 overallProgress.beginTask('Adding oceans')
evansiroky26325842018-04-03 14:10:42 -0700741 addOceans(cb)
742 }],
743 mergeZones: ['addOceans', function (results, cb) {
evansiroky5348a6f2019-01-05 15:39:28 -0800744 overallProgress.beginTask('Merging zones')
Evan Siroky8b47abe2016-10-02 12:28:52 -0700745 combineAndWriteZones(cb)
746 }],
747 zipGeoJson: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100748 if (argv.skip_zip) {
749 overallProgress.beginTask('Skipping zip')
Neil Fuller61287092020-07-29 14:46:16 +0100750 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100751 }
Neil Fuller61287092020-07-29 14:46:16 +0100752 overallProgress.beginTask('Zipping geojson')
753 let zipFile = argv.dist_dir + '/timezones.geojson.zip'
754 let jsonFile = argv.dist_dir + '/combined.json'
755 exec('zip ' + zipFile + ' ' + jsonFile, cb)
Evan Siroky8b47abe2016-10-02 12:28:52 -0700756 }],
evansiroky26325842018-04-03 14:10:42 -0700757 zipGeoJsonWithOceans: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100758 if (argv.skip_zip) {
759 overallProgress.beginTask('Skipping with oceans zip')
Neil Fuller61287092020-07-29 14:46:16 +0100760 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100761 }
Neil Fuller61287092020-07-29 14:46:16 +0100762 overallProgress.beginTask('Zipping geojson with oceans')
763 let zipFile = argv.dist_dir + '/timezones-with-oceans.geojson.zip'
764 let jsonFile = argv.dist_dir + '/combined-with-oceans.json'
765 exec('zip ' + zipFile + ' ' + jsonFile, cb)
evansiroky26325842018-04-03 14:10:42 -0700766 }],
Evan Siroky8b47abe2016-10-02 12:28:52 -0700767 makeShapefile: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100768 if (argv.skip_shapefile) {
769 overallProgress.beginTask('Skipping shapefile creation')
Neil Fuller61287092020-07-29 14:46:16 +0100770 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100771 }
Neil Fuller61287092020-07-29 14:46:16 +0100772 overallProgress.beginTask('Converting from geojson to shapefile')
773 let shapeFileGlob = argv.dist_dir + '/combined-shapefile.*'
774 rimraf.sync(shapeFileGlob)
775 let shapeFile = argv.dist_dir + '/combined-shapefile.shp'
776 let jsonFile = argv.dist_dir + '/combined.json'
777 exec(
778 'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile,
779 function (err, stdout, stderr) {
780 if (err) { return cb(err) }
781 let shapeFileZip = argv.dist_dir + '/timezones.shapefile.zip'
782 exec('zip ' + shapeFileZip + ' ' + shapeFileGlob, cb)
783 }
784 )
evansiroky26325842018-04-03 14:10:42 -0700785 }],
786 makeShapefileWithOceans: ['mergeZones', function (results, cb) {
Neil Fullera83cc6d2020-04-30 18:37:08 +0100787 if (argv.skip_shapefile) {
788 overallProgress.beginTask('Skipping with oceans shapefile creation')
Neil Fuller61287092020-07-29 14:46:16 +0100789 return cb()
Neil Fullera83cc6d2020-04-30 18:37:08 +0100790 }
Neil Fuller61287092020-07-29 14:46:16 +0100791 overallProgress.beginTask('Converting from geojson with oceans to shapefile')
792 let shapeFileGlob = argv.dist_dir + '/combined-shapefile-with-oceans.*'
793 rimraf.sync(shapeFileGlob)
794 let shapeFile = argv.dist_dir + '/combined-shapefile-with-oceans.shp'
795 let jsonFile = argv.dist_dir + '/combined-with-oceans.json'
796 exec(
797 'ogr2ogr -f "ESRI Shapefile" ' + shapeFile + ' ' + jsonFile,
798 function (err, stdout, stderr) {
799 if (err) { return cb(err) }
800 let shapeFileZip = argv.dist_dir + '/timezones-with-oceans.shapefile.zip'
801 exec('zip ' + shapeFileZip + ' ' + shapeFileGlob, cb)
802 }
803 )
evansiroky9fd50512019-07-07 12:06:28 -0700804 }],
805 makeListOfTimeZoneNames: function (cb) {
806 overallProgress.beginTask('Writing timezone names to file')
807 let zoneNames = Object.keys(zoneCfg)
808 oceanZones.forEach(oceanZone => {
809 zoneNames.push(oceanZone.tzid)
810 })
Neil Fullerc4ae49b2020-04-30 18:08:43 +0100811 if (includedZones.length > 0) {
812 zoneNames = zoneNames.filter(zoneName => includedZones.indexOf(zoneName) > -1)
evansiroky9fd50512019-07-07 12:06:28 -0700813 }
Neil Fuller2b4b80a2020-04-30 18:20:56 +0100814 if (excludedZones.length > 0) {
815 zoneNames = zoneNames.filter(zoneName => excludedZones.indexOf(zoneName) === -1)
816 }
evansiroky9fd50512019-07-07 12:06:28 -0700817 fs.writeFile(
Neil Fullera4e73272020-04-30 18:25:44 +0100818 argv.dist_dir + '/timezone-names.json',
evansiroky9fd50512019-07-07 12:06:28 -0700819 JSON.stringify(zoneNames),
820 cb
821 )
822 }
evansiroky5348a6f2019-01-05 15:39:28 -0800823}
824
825const overallProgress = new ProgressStats('Overall', Object.keys(autoScript).length)
826
827asynclib.auto(autoScript, function (err, results) {
evansirokyd401c892016-06-16 00:05:14 -0700828 console.log('done')
Evan Siroky7891a6e2016-11-05 11:50:50 -0700829 if (err) {
evansirokyd401c892016-06-16 00:05:14 -0700830 console.log('error!', err)
evansirokyd401c892016-06-16 00:05:14 -0700831 }
Evan Siroky4fc596c2016-09-25 19:52:30 -0700832})