Skip to content

Commit

Permalink
feat: Merge pull request #122 from pelias/lbl_bbox
Browse files Browse the repository at this point in the history
Use lbl:bbox property when present
  • Loading branch information
orangejulius authored Aug 9, 2016
2 parents 855709e + cdf2372 commit 0f4e787
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/extractFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function getLon(properties) {
}
}

function getBoundingBox(properties) {
if (properties.hasOwnProperty('lbl:bbox')) {
return properties['lbl:bbox'];
} else {
return properties['geom:bbox'];
}
}

/*
This function extracts the fields from the json_object that we're interested
in for creating Pelias Document objects. If there is no hierarchy then a
Expand All @@ -54,7 +62,7 @@ module.exports.create = function map_fields_stream() {
parent_id: json_object.properties['wof:parent_id'],
lat: getLat(json_object.properties),
lon: getLon(json_object.properties),
bounding_box: json_object.properties['geom:bbox'],
bounding_box: getBoundingBox(json_object.properties),
iso2: json_object.properties['iso:country'],
population: getPopulation(json_object.properties),
popularity: json_object.properties['misc:photo_sum']
Expand Down
78 changes: 78 additions & 0 deletions test/components/extractFieldsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,82 @@ tape('readStreamComponents', function(test) {
t.end();
});
});

test.test('label bounding box should take precedence over math bounding box', function(t) {
var input = [
{
id: 12345,
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
'lbl:bbox': '-14.691314,50.909613,2.771169,61.847886',
'qs:a2_alt': 'qs:a2_alt value'
}
}
];

var expected = [
{
id: 12345,
name: 'wof:name value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: undefined,
population: undefined,
popularity: undefined,
bounding_box: '-14.691314,50.909613,2.771169,61.847886',
abbreviation: undefined
}
];

test_stream(input, extractFields.create(), function(err, actual) {
t.deepEqual(actual, expected, 'label geometry is used');
t.end();
});
});

test.test('label bounding box should take precedence over math bounding box even if empty', function(t) {
var input = [
{
id: 12345,
properties: {
'wof:name': 'wof:name value',
'wof:placetype': 'county',
'wof:parent_id': 'parent id',
'geom:latitude': 12.121212,
'geom:longitude': 21.212121,
'geom:bbox': '-13.691314,49.909613,1.771169,60.847886',
'lbl:bbox': '',
'qs:a2_alt': 'qs:a2_alt value'
}
}
];

var expected = [
{
id: 12345,
name: 'wof:name value',
place_type: 'county',
parent_id: 'parent id',
lat: 12.121212,
lon: 21.212121,
iso2: undefined,
population: undefined,
popularity: undefined,
bounding_box: '',
abbreviation: undefined
}
];

test_stream(input, extractFields.create(), function(err, actual) {
t.deepEqual(actual, expected, 'label geometry is used');
t.end();
});
});
});

0 comments on commit 0f4e787

Please sign in to comment.