aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/reduceRangeDuplicates.js12
-rw-r--r--test/reduceRangeDuplicates.js34
2 files changed, 40 insertions, 6 deletions
diff --git a/bin/reduceRangeDuplicates.js b/bin/reduceRangeDuplicates.js
index 6322e94..67dbf4e 100755
--- a/bin/reduceRangeDuplicates.js
+++ b/bin/reduceRangeDuplicates.js
@@ -234,11 +234,13 @@ const reduceNonRange = new Transform({
const range = ranges[i]
// if the range wasn't just removed in filter A, and the feature is within the range
if (!(hash(range) in rangesRemovedInFilterA) && withinRange(feature, range)) {
- // found within a range, drop feature unless would drop addr:unit information
- if ('addr:unit' in feature.properties) {
- // safe to drop if the same addr:unit is also on the range
- if ('addr:unit' in range.properties &&
- feature.properties['addr:unit'] === range.properties['addr:unit']) {
+ // found within a range, drop feature unless would drop addr:unit or addr:flats information
+ if ('addr:unit' in feature.properties || 'addr:flats' in feature.properties) {
+ // safe to drop if the same addr:unit and addr:flats is also on the range
+ if (
+ 'addr:unit' in feature.properties ? ('addr:unit' in range.properties && feature.properties['addr:unit'] === range.properties['addr:unit']) : true &&
+ 'addr:flats' in feature.properties ? ('addr:flats' in range.properties && feature.properties['addr:flats'] === range.properties['addr:flats']) : true
+ ) {
dropFeature = true
} else {
// since the non-range feature has a unit that the range doesn't have, don't drop it
diff --git a/test/reduceRangeDuplicates.js b/test/reduceRangeDuplicates.js
index 04b69e1..091390c 100644
--- a/test/reduceRangeDuplicates.js
+++ b/test/reduceRangeDuplicates.js
@@ -3,10 +3,11 @@ const fs = require('fs')
const child_process = require('child_process')
const mktemp = require('mktemp')
-function createFeature(unit, housenumber, street, suburb) {
+function createFeature(unit, housenumber, street, suburb, flats) {
return {
type: 'Feature',
properties: {
+ ...(flats && {'addr:flats': flats}),
...(unit && {'addr:unit': unit}),
'addr:housenumber': housenumber,
'addr:street': street,
@@ -111,3 +112,34 @@ test('reduceRangeDuplicates', t => {
t.end()
})
+
+test('reduceRangeDuplicates', t => {
+ const inputFile = mktemp.createFileSync('/tmp/input_XXXXX.geojson')
+ const outputFile = mktemp.createFileSync('/tmp/output_XXXXX.geojson')
+ const expectedFile = mktemp.createFileSync('/tmp/expected_XXXXX.geojson')
+
+ const AC = createFeature(null, '249-263', 'Faraday Street', 'Carlton')
+ const B = createFeature(null, '251', 'Faraday Street', 'Carlton', '1;2;3')
+
+ // both features to appear in input
+ fs.appendFileSync(inputFile, JSON.stringify(AC) + '\n')
+ fs.appendFileSync(inputFile, JSON.stringify(B) + '\n')
+
+ // output expected to both features because dropping the midpoint would loose the unit
+ fs.appendFileSync(expectedFile, JSON.stringify(AC) + '\n')
+ fs.appendFileSync(expectedFile, JSON.stringify(B) + '\n')
+
+ child_process.execSync(`./bin/reduceRangeDuplicates.js ${inputFile} ${outputFile}`)
+
+ t.same(
+ fs.readFileSync(outputFile),
+ fs.readFileSync(expectedFile),
+ 'midpoint with flats not dropped'
+ )
+
+ fs.unlinkSync(inputFile)
+ fs.unlinkSync(outputFile)
+ fs.unlinkSync(expectedFile)
+
+ t.end()
+})