diff options
author | Andrew Harvey <andrew@alantgeo.com.au> | 2021-07-05 23:41:35 +1000 |
---|---|---|
committer | Andrew Harvey <andrew@alantgeo.com.au> | 2021-07-05 23:41:35 +1000 |
commit | 9e3708dca0c07765ea047846fac0015c067308a2 (patch) | |
tree | 82ab801189141e189ee61603126c0dfff2501458 | |
parent | 6a9a77e4860b9c64ee1fd6de86025268570696cb (diff) |
fix reduce overlap where range is first
-rw-r--r-- | .vscode/launch.json | 4 | ||||
-rwxr-xr-x | bin/conflate.js | 10 | ||||
-rwxr-xr-x | bin/reduceOverlap.js | 6 | ||||
-rw-r--r-- | lib/withinRange.js | 8 |
4 files changed, 24 insertions, 4 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index c1725d9..4c058d3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,7 +7,7 @@ { "type": "pwa-node", "request": "launch", - "name": "reduceOverlap", + "name": "bin/reduceOverlap", "skipFiles": [ "<node_internals>/**" ], @@ -17,7 +17,7 @@ { "type": "pwa-node", "request": "launch", - "name": "reduceOverlap AndersonStreet", + "name": "bin/reduceOverlap AndersonStreet", "skipFiles": [ "<node_internals>/**" ], diff --git a/bin/conflate.js b/bin/conflate.js index a1b0b60..5af586c 100755 --- a/bin/conflate.js +++ b/bin/conflate.js @@ -15,6 +15,7 @@ const centroid = require('@turf/centroid').default const booleanIntersects = require('@turf/boolean-intersects').default const distance = require('@turf/distance').default const { lcs } = require('string-comparison') +const withinRange = require('../lib/withinRange') const argv = require('yargs/yargs')(process.argv.slice(2)) .option('debug', { @@ -191,7 +192,14 @@ const conflate = new Transform({ // ignoring differences between "Foo - Bar Street" and "Foo-Bar Street", these kinds of names are common in country victoria const isMatched = feature.properties['addr:street'] && osmStreet && feature.properties['addr:street'].toLowerCase().replaceAll(' - ', '-').replaceAll('-', '') === osmStreet.toLowerCase().replaceAll(' - ', '-').replaceAll('-', '') - && osmHouseNumber !== null && feature.properties['addr:housenumber'].replaceAll(' ', '').toLowerCase() === osmHouseNumber.replaceAll(' ', '').toLowerCase() + && osmHouseNumber !== null + && ( + // housenumber can be an exact match + feature.properties['addr:housenumber'].replaceAll(' ', '').toLowerCase() === osmHouseNumber.replaceAll(' ', '').toLowerCase() + // or it can just intersect the range + // eg 182 St Georges Road Fitzroy North + || withinRange(feature, osmAddr, { checkStreet: false, checkHigherOrderAddrKeys: false }) + ) && (vicmapUnit === osmUnit) // if matched but the match came from exploding X/Y into Unit X, Number Y, then automate this to be changed in OSM diff --git a/bin/reduceOverlap.js b/bin/reduceOverlap.js index 0941f49..695d5f6 100755 --- a/bin/reduceOverlap.js +++ b/bin/reduceOverlap.js @@ -120,6 +120,9 @@ const reduce = new Transform({ if (cur && cur.split('-').length === 2) { cur = cur.split('-')[0] } + if (acc && acc.split('-').length === 2) { + acc = acc.split('-')[0] + } return (cur < acc) ? cur : acc }) : null @@ -127,6 +130,9 @@ const reduce = new Transform({ if (cur && cur.split('-').length === 2) { cur = cur.split('-')[1] } + if (acc && acc.split('-').length === 2) { + acc = acc.split('-')[1] + } return (cur > acc) ? cur : acc }) : null diff --git a/lib/withinRange.js b/lib/withinRange.js index b86da82..f8b61ad 100644 --- a/lib/withinRange.js +++ b/lib/withinRange.js @@ -53,12 +53,18 @@ module.exports = (feature, rangeFeature, options) => { let iFrom let iTo let iRange = false + let match if (iParts.length === 2) { iRange = true iFrom = iParts[0].match(regexp).groups iTo = iParts[1].match(regexp).groups + } else { + match = feature.properties['addr:housenumber'].match(regexp) + if (!match) { + console.log(`${feature.properties['addr:housenumber']} didn't match regexp`, feature) + } } - const i = !iRange ? feature.properties['addr:housenumber'].match(regexp).groups : null + const i = iRange ? null : match.groups if ( iRange ? ( Number.isInteger(Number(iFrom.num)) && Number.isInteger(Number(iTo.num)) && Number.isInteger(Number(from.num)) && Number.isInteger(Number(to.num)) && |