diff options
-rwxr-xr-x | bin/vicmap2osm.js | 5 | ||||
-rw-r--r-- | lib/filterOSM.js | 11 | ||||
-rw-r--r-- | lib/filterSource.js | 41 |
3 files changed, 50 insertions, 7 deletions
diff --git a/bin/vicmap2osm.js b/bin/vicmap2osm.js index 8559e8a..695a08c 100755 --- a/bin/vicmap2osm.js +++ b/bin/vicmap2osm.js @@ -9,6 +9,7 @@ const { Transform, pipeline } = require('readable-stream') const ndjson = require('ndjson') const toOSM = require('../lib/toOSM.js') const filterOSM = require('../lib/filterOSM.js') +const filterSource = require('../lib/filterSource.js') const argv = require('yargs/yargs')(process.argv.slice(2)) .option('debug', { @@ -44,9 +45,7 @@ const transform = new Transform({ }) // some addresses we skip importing into OSM, see README.md#omitted-addresses - if (filterOSM(osm, { - debug: argv.debug - })) { + if (filterOSM(osm) && filterSource(feature)) { this.push(osm) } diff --git a/lib/filterOSM.js b/lib/filterOSM.js index 0a22b8b..2c96ece 100644 --- a/lib/filterOSM.js +++ b/lib/filterOSM.js @@ -1,12 +1,15 @@ -module.exports = (feature, options) => { +/** + * Filters features based on the OSM schema from toOSM + * + * @param {Object} feature + * @returns {boolean} + */ +module.exports = (feature) => { // skip any addresses without a housenumber if ( !('addr:housenumber' in feature.properties) ) { - if (options && options.debug) { - console.log(`PFI ${feature.properties._pfi} has no addr:housenumber, filtering`) - } return false } diff --git a/lib/filterSource.js b/lib/filterSource.js new file mode 100644 index 0000000..bf5d113 --- /dev/null +++ b/lib/filterSource.js @@ -0,0 +1,41 @@ +// whitelist of building unit types to include +// other building unit types like carspace we skip +const buildingUnitTypeWhitelist = [ + 'APT', // apartment + 'BLDG', // building + 'CHAL', // chalet + 'CTGE', // cottage + 'FLAT', // flat + 'HSE', // house + 'OFFC', // office + 'SAPT', // studio apartment + 'SE', // suite + 'SHOP', // shop + 'STR', // strata unit + 'TNHS', // townhouse + 'UNIT', // unit + 'VLLA' // villa +] + +/** + * Filters features based on the source schema + * + * @param {Object} feature + * @returns {boolean} + */ +module.exports = (feature) => { + + // if the address has a building unit type, only allow a few whitelisted types + if ('BLGUNTTYP' in feature.properties) { + if (buildingUnitTypeWhitelist.includes(feature.properties.BLGUNTTYP)) { + // building unit type in the whitelist, include feature + return true + } else { + // building unit type is set and not in the whitelist, drop feature + return false + } + } else { + // building unit type not set, include feature + return true + } +} |