aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorEvan Siroky <evan.siroky@yahoo.com>2017-03-07 23:48:29 -0800
committerEvan Siroky <evan.siroky@yahoo.com>2017-03-07 23:48:29 -0800
commit070bbb97e8ba0a0b2bf9e136bf1ad2d4c24953ec (patch)
tree72ec9e7108e214426b6f259cbce0ba04bae991d9 /index.js
parent8326cf09bf88b24fa6c86f18f255216038224919 (diff)
downloadtimezone-boundary-builder-070bbb97e8ba0a0b2bf9e136bf1ad2d4c24953ec.tar.gz
Manually build America/Chicago and America/Mexico_City
Also includes some changes to America/Denver to make it line up with America/Chicago Refs #8
Diffstat (limited to 'index.js')
-rw-r--r--index.js43
1 files changed, 36 insertions, 7 deletions
diff --git a/index.js b/index.js
index 6a24b7c..3c4f184 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,7 @@ var exec = require('child_process').exec
var fs = require('fs')
var helpers = require('@turf/helpers')
-var multiPolygon = helpers.multipolygon
+var multiPolygon = helpers.multiPolygon
var polygon = helpers.polygon
var asynclib = require('async')
var jsts = require('jsts')
@@ -38,6 +38,9 @@ var debugGeo = function (op, a, b) {
case 'intersection':
result = a.intersection(b)
break
+ case 'intersects':
+ result = a.intersects(b)
+ break
case 'diff':
try {
result = a.difference(b)
@@ -72,10 +75,23 @@ var debugGeo = function (op, a, b) {
return result
}
-var fetchIfNeeded = function (file, superCallback, fetchFn) {
+var fetchIfNeeded = function (file, superCallback, downloadCallback, fetchFn) {
+ // check for file that got downloaded
fs.stat(file, function (err) {
- if (!err) { return superCallback() }
- fetchFn()
+ if (!err) {
+ // file found, skip download steps
+ return superCallback()
+ }
+ // check for manual file that got fixed and needs validation
+ var fixedFile = file.replace('.json', '_fixed.json')
+ fs.stat(fixedFile, function (err) {
+ if (!err) {
+ // file found, return fixed file
+ return downloadCallback(null, require(fixedFile))
+ }
+ // no manual fixed file found, download from overpass
+ fetchFn()
+ })
})
}
@@ -118,7 +134,7 @@ var downloadOsmBoundary = function (boundaryId, boundaryCallback) {
asynclib.auto({
downloadFromOverpass: function (cb) {
console.log('downloading from overpass')
- fetchIfNeeded(boundaryFilename, boundaryCallback, function () {
+ fetchIfNeeded(boundaryFilename, boundaryCallback, cb, function () {
var overpassResponseHandler = function (err, data) {
if (err) {
console.log(err)
@@ -157,7 +173,13 @@ var downloadOsmBoundary = function (boundaryId, boundaryCallback) {
var curOsmGeom = data.features[i].geometry
if (curOsmGeom.type === 'Polygon' || curOsmGeom.type === 'MultiPolygon') {
console.log('combining border')
- var curGeom = geoJsonToGeom(curOsmGeom)
+ try {
+ var curGeom = geoJsonToGeom(curOsmGeom)
+ } catch (e) {
+ console.error('error converting overpass result to geojson')
+ fs.writeFileSync(boundaryId + '_fixed.json', JSON.stringify(data))
+ throw e
+ }
if (!combined) {
combined = curGeom
} else {
@@ -262,7 +284,14 @@ var validateTimezoneBoundaries = function () {
compareTzid = zones[j]
var compareZoneGeom = getDistZoneGeom(compareTzid)
- if (zoneGeom.intersects(compareZoneGeom)) {
+
+ var intersects = false
+ try {
+ intersects = debugGeo('intersects', zoneGeom, compareZoneGeom)
+ } catch (e) {
+ console.warn('warning, encountered intersection error with zone ' + tzid + ' and ' + compareTzid)
+ }
+ if (intersects) {
var intersectedGeom = debugGeo('intersection', zoneGeom, compareZoneGeom)
var intersectedArea = intersectedGeom.getArea()