From fef04b6fe43e8fdbcd7560d6c98dca28d4636c3c Mon Sep 17 00:00:00 2001 From: Rub21 Date: Thu, 3 Nov 2016 19:33:15 +0530 Subject: [PATCH] add cf big buildings --- comparators/big_buildings.js | 31 ++++++ tests/fixtures/big_buildings.json | 159 ++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 comparators/big_buildings.js create mode 100644 tests/fixtures/big_buildings.json diff --git a/comparators/big_buildings.js b/comparators/big_buildings.js new file mode 100644 index 0000000..d38965e --- /dev/null +++ b/comparators/big_buildings.js @@ -0,0 +1,31 @@ +'use strict'; +// Goal: Catch big buildings which are modificated greater than ten times. +var turfArea = require('turf-area'); +var turfFC = require('turf-featurecollection'); + +module.exports = big_buildings; + +/** + * Identify big buildings. + * @param {object} newVersion Features new version in GeoJSON. + * @param {object} oldVersion Features old version in GeoJSON. + * @param {Function} callback called with (error, result). + * @returns {undefined} calls callback. + */ +function big_buildings(newVersion, oldVersion, callback) { + + if (!newVersion || !oldVersion) { + return callback(null, {}); + } + // Note: newVersion does not have any tags, so using oldVersion. + var oldArea = oldVersion ? turfArea(turfFC([oldVersion])) : null; + var newArea = turfArea(turfFC([newVersion])); + var maxBig = 10000; //square meters + var flag = false; + if (oldArea && ((newArea / oldArea > 10) || (newArea >= maxBig))) { + flag = true; + } + callback(null, { + 'result:big_buildings': flag + }); +} diff --git a/tests/fixtures/big_buildings.json b/tests/fixtures/big_buildings.json new file mode 100644 index 0000000..e7f974d --- /dev/null +++ b/tests/fixtures/big_buildings.json @@ -0,0 +1,159 @@ +{ + "compareFunction": "big_buildings", + "fixtures": [{ + "description": "Test big buildings", + "newVersion": { + "type": "Feature", + "properties": { + "building": "yes", + "addr:province": "Huamanga", + "addr:housenumber": 10, + "addr:full": "Asoc. Micaela Bastidas MZ D1, Lt 10", + "addr:district": "Jesús Nazareno", + "addr:street": "Jr. S. Rosa de Lima", + "addr:postcode": "05011" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-74.21691866464, -13.15067938123], + [-74.21658829794, -13.15114551595], + [-74.21759636893, -13.1518220887], + [-74.21771629656, -13.15190354884], + [-74.21798669944, -13.15152340127], + [-74.21792221005, -13.15148040836], + [-74.21798330527, -13.15139329112], + [-74.21691866464, -13.15067938123] + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "building": "yes", + "addr:province": "Huamanga", + "addr:housenumber": 10, + "addr:full": "Asoc. Micaela Bastidas MZ D1, Lt 10", + "addr:district": "Jesús Nazareno", + "addr:street": "Jr. S. Rosa de Lima", + "addr:postcode": "05011" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-74.21747974338, -13.15135578908], + [-74.21745054338, -13.15139698908], + [-74.21753964338, -13.15145678908], + [-74.21755024338, -13.15146398908], + [-74.21757414338, -13.15143038908], + [-74.21756844338, -13.15142658908], + [-74.21757384338, -13.15141888908], + [-74.21747974338, -13.15135578908] + ] + ] + } + }, + "expectedResult": { + "result:big_buildings": true + } + }, { + "description": "Test big buildings", + "newVersion": { + "type": "FeatureCollection", + "features": [{ + "type": "Feature", + "properties": { + "building": "yes", + "addr:province": "Huamanga", + + "addr:housenumber": 10, + "addr:full": "Asoc. Micaela Bastidas MZ D1, Lt 10", + "addr:district": "Jesús Nazareno", + "addr:street": "Jr. S. Rosa de Lima", + "addr:postcode": "05011" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-74.21747974338, -13.15135578908], + [-74.21740472316742, -13.151422059028356], + [-74.21753964338, -13.15145678908], + [-74.21755024338, -13.15146398908], + [-74.21757414338, -13.15143038908], + [-74.21756844338, -13.15142658908], + [-74.21757384338, -13.15141888908], + [-74.21747974338, -13.15135578908] + ] + ] + } + }] + }, + "oldVersion": { + "type": "Feature", + "properties": { + "building": "yes", + "addr:province": "Huamanga", + "addr:housenumber": 10, + "addr:full": "Asoc. Micaela Bastidas MZ D1, Lt 10", + "addr:district": "Jesús Nazareno", + "addr:street": "Jr. S. Rosa de Lima", + "addr:postcode": "05011" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-74.21747974338, -13.15135578908], + [-74.21745054338, -13.15139698908], + [-74.21753964338, -13.15145678908], + [-74.21755024338, -13.15146398908], + [-74.21757414338, -13.15143038908], + [-74.21756844338, -13.15142658908], + [-74.21757384338, -13.15141888908], + [-74.21747974338, -13.15135578908] + ] + ] + } + }, + "expectedResult": { + "result:big_buildings": false + } + }, { + "description": "Test big buildings", + "newVersion": { + "type": "Feature", + "properties": { + "building": "yes", + "addr:province": "Huamanga", + "addr:housenumber": 10, + "addr:full": "Asoc. Micaela Bastidas MZ D1, Lt 10", + "addr:district": "Jesús Nazareno", + "addr:street": "Jr. S. Rosa de Lima", + "addr:postcode": "05011" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-74.21691866464, -13.15067938123], + [-74.21658829794, -13.15114551595], + [-74.21759636893, -13.1518220887], + [-74.21771629656, -13.15190354884], + [-74.21798669944, -13.15152340127], + [-74.21792221005, -13.15148040836], + [-74.21798330527, -13.15139329112], + [-74.21691866464, -13.15067938123] + ] + ] + } + }, + "oldVersion": null, + "expectedResult": { + "result:big_buildings": true + } + }] +} \ No newline at end of file