osm-compare
Compare functions are small atomic functions that are designed identify what changed during a feature edit on OpenStreetMap. Compare functions can be broadly split up into two categories:
- Property (tags) checking compare function
- Geometry checking compare functions
Compare functions take as inputs the following:
oldVersion
- GeoJSON of the feature's old versionnewVersion
- GeoJSON of the feature's new versioncallback
- A function to call after processing.
Compare functions output the following:
error
- Error if any during processing or null
.result
- Object containing key value pairs representing findings of the compare function or an empty object.
Versioning
The version of the compare function is returned as part of the result as cfVersion
. Every time a compare function is modified, we increment the value of cfVersion
.
A sample compare function would look something like this:
function place_removed(newVersion, oldVersion, callback) {
var cfVersion = 2;
var oldProps = oldVersion.properties;
var newProps = newVersion.properties;
var placeRemoved = false;
if (oldProps.hasOwnProperty('place') && !newProps.hasOwnProperty('place')) {
placeRemoved = true;
}
return callback(null, {'result:place_removed': {
'cfVersion': cfVersion,
'placeRemoved': placeRemoved
}});
}
How do I create a new compare function?
- Clone this repository with
git clone https://github.com/mapbox/compare-geojson
cd compare-geojson
npm install
- Check if all tests pass before making your changes with
npm test
- Create a new test fixture in the directory
tests/fixtures/
- Create a new compare function in the directory
comparators/
- Test your new compare function with
npm test
How do I test a single compare function against a new fixture?
cd compare-geojson/tests/
- Create new fixture file in
tests/fixtures/
folder (check other fixtures for format). - Update name of compare function you want to run the fixture against.
- Test your fixture with
node test_compare_function.js fixtures/new_mapper.json
How do I build an npm package?