aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorevansiroky <evan.siroky@yahoo.com>2018-10-30 22:30:51 -0700
committerevansiroky <evan.siroky@yahoo.com>2018-10-30 22:30:51 -0700
commit0ea1d1ea25c28ceb1501b5d3599b23095d43964f (patch)
treea1baaa983b3da4f9fd2d8f7ea0963a5e4cb9bbe1
parent76d2c8e628005921567ffb54cfa5e0a8ef5e9a23 (diff)
downloadtimezone-boundary-builder-0ea1d1ea25c28ceb1501b5d3599b23095d43964f.tar.gz
Modify script to allow overlaps of certain zones during validation.
Fixes #41
-rw-r--r--CHANGELOG.md10
-rw-r--r--expectedZoneOverlaps.json3
-rw-r--r--index.js55
-rw-r--r--package.json3
-rw-r--r--timezones.json4
5 files changed, 62 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6240be2..940089d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,9 +1,19 @@
## Unreleased
+### Zone Changes
+
+* Switch geometries of America/Danmarkshavn and America/Scoresbysund ([#40](https://github.com/evansiroky/timezone-boundary-builder/issues/40))
+* Add timezones in Antarctica ([#42](https://github.com/evansiroky/timezone-boundary-builder/issues/42))
+* Fix northern border of America/Argentina/Rio_Gallegos ([#46](https://github.com/evansiroky/timezone-boundary-builder/issues/46))
+* Update to latest OSM data
+
### Other Changes
* Added more libraries to list of lookup libraries using this project's data
* Fixed overpass querying ([#43](https://github.com/evansiroky/timezone-boundary-builder/issues/43))
+* Allow timezone boundaries to overlap. ([#41](https://github.com/evansiroky/timezone-boundary-builder/issues/41))
+ * This change now means that the following zones overlap:
+ * Asia/Shanghai, Asia/Urumqi
## 2018d
diff --git a/expectedZoneOverlaps.json b/expectedZoneOverlaps.json
new file mode 100644
index 0000000..96d2d6c
--- /dev/null
+++ b/expectedZoneOverlaps.json
@@ -0,0 +1,3 @@
+{
+ "Asia/Shanghai-Asia/Urumqi": [[73.4, 34.3, 96.4, 49.2]]
+}
diff --git a/index.js b/index.js
index 879016d..e1dee6a 100644
--- a/index.js
+++ b/index.js
@@ -3,6 +3,7 @@ var fs = require('fs')
var area = require('@mapbox/geojson-area')
var geojsonhint = require('@mapbox/geojsonhint')
+var bbox = require('@turf/bbox').default
var helpers = require('@turf/helpers')
var multiPolygon = helpers.multiPolygon
var polygon = helpers.polygon
@@ -13,11 +14,12 @@ var overpass = require('query-overpass')
var osmBoundarySources = require('./osmBoundarySources.json')
var zoneCfg = require('./timezones.json')
+var expectedZoneOverlaps = require('./expectedZoneOverlaps.json')
// allow building of only a specified zones
var filteredIndex = process.argv.indexOf('--filtered-zones')
if (filteredIndex > -1 && process.argv[filteredIndex + 1]) {
- filteredZones = process.argv[filteredIndex + 1].split(',')
+ const filteredZones = process.argv[filteredIndex + 1].split(',')
var newZoneCfg = {}
filteredZones.forEach((zoneName) => {
newZoneCfg[zoneName] = zoneCfg[zoneName]
@@ -194,8 +196,7 @@ var downloadOsmBoundary = function (boundaryId, boundaryCallback) {
console.error('No data for the following query:')
console.error(query)
console.error('To read more about this error, please visit https://git.io/vxKQL')
- var err = new Error('No data found for from overpass query')
- return cb(err)
+ return cb(new Error('No data found for from overpass query'))
}
cb()
}],
@@ -413,11 +414,50 @@ var validateTimezoneBoundaries = function () {
var intersectedArea = intersectedGeom.getArea()
if (intersectedArea > 0.0001) {
+ // check if the intersected area(s) are one of the expected areas of overlap
+ const allowedOverlapBounds = expectedZoneOverlaps[`${tzid}-${compareTzid}`] || expectedZoneOverlaps[`${compareTzid}-${tzid}`]
+ const overlapsGeoJson = geoJsonWriter.write(intersectedGeom)
+
+ // these zones are allowed to overlap in certain places, make sure the
+ // found overlap(s) all fit within the expected areas of overlap
+ if (allowedOverlapBounds) {
+ // if the overlaps are a multipolygon, make sure each individual
+ // polygon of overlap fits within at least one of the expected
+ // overlaps
+ let overlapsPolygons
+ switch (overlapsGeoJson.type) {
+ case 'Polygon':
+ overlapsPolygons = [overlapsGeoJson]
+ break
+ default:
+ break
+ }
+
+ let allOverlapsOk = true
+ overlapsPolygons.forEach((polygon, idx) => {
+ const bounds = bbox(polygon)
+ if (
+ !allowedOverlapBounds.some(allowedBounds =>
+ allowedBounds[0] <= bounds[0] && // minX
+ allowedBounds[1] <= bounds[1] && // minY
+ allowedBounds[2] >= bounds[2] && // maxX
+ allowedBounds[3] >= bounds[3] // maxY
+ )
+ ) {
+ console.error('Unexpected intersection with bounds: ', bounds)
+ allOverlapsOk = false
+ }
+ })
+
+ if (allOverlapsOk) continue
+ }
+
+ // not an expected overlap, output an error
console.error('Validation error: ' + tzid + ' intersects ' + compareTzid + ' area: ' + intersectedArea)
const debugFilename = tzid.replace('/', '-') + '-' + compareTzid.replace('/', '-') + '-overlap.json'
fs.writeFileSync(
debugFilename,
- JSON.stringify(geoJsonWriter.write(intersectedGeom))
+ JSON.stringify(overlapsGeoJson)
)
console.error('wrote overlap area as file ' + debugFilename)
console.error('To read more about this error, please visit https://git.io/vx6nx')
@@ -468,9 +508,9 @@ var addOceans = function (callback) {
console.log(zone.tzid)
const geoJson = polygon([[
[zone.left, 90],
- [zone.left,-90],
- [zone.right,-90],
- [zone.right,90],
+ [zone.left, -90],
+ [zone.right, -90],
+ [zone.right, 90],
[zone.left, 90]
]]).geometry
@@ -599,6 +639,5 @@ asynclib.auto({
console.log('done')
if (err) {
console.log('error!', err)
- return
}
})
diff --git a/package.json b/package.json
index 8b01e83..5038cd9 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,8 @@
"dependencies": {
"@mapbox/geojson-area": "^0.2.2",
"@mapbox/geojsonhint": "^2.1.0",
- "@turf/helpers": "^3.10.3",
+ "@turf/bbox": "^6.0.1",
+ "@turf/helpers": "^6.1.4",
"async": "^2.1.5",
"jsts": "^1.3.0",
"query-overpass": "^1.1.3",
diff --git a/timezones.json b/timezones.json
index beb6e30..de4a3d7 100644
--- a/timezones.json
+++ b/timezones.json
@@ -3212,10 +3212,6 @@
}, {
"op": "difference",
"source": "overpass",
- "id": "Xinjiang"
- }, {
- "op": "difference",
- "source": "overpass",
"id": "Hong Kong"
}, {
"op": "difference",