Skip to content

Commit

Permalink
feat(shapefile): placetype local using English fallback and non-latin…
Browse files Browse the repository at this point in the history
… (latin) names (#48)

* Placetype local using English fallback and () latin names

---------

Co-authored-by: Peter Johnson <[email protected]>
  • Loading branch information
nvkelso and missinglink authored Oct 2, 2023
1 parent 425fecb commit 03b8fb3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
12 changes: 9 additions & 3 deletions whosonfirst/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ feature.getLocalLanguages = (feat, type = 'official') => {
// see: https://github.com/whosonfirst-data/whosonfirst-data/issues/2154
feature.getPlacetypeLocal = (feat) => _.flatten(
feature.getLocalLanguages(feat, 'official')
.map(lang => `label:${lang}_x_preferred_placetype`)
.concat(['wof:placetype_local'])
.map(prop => _.get(feat, `properties.${prop}`))
.concat(['eng']) // fallback to English when no other languages are available
.map(lang => {
const endonym = _.get(feat, `properties.label:${lang}_x_preferred_placetype`)

// When a localized placetype isn't in a latin char set then WOF often provides
// a transliteration we can include in a parenthetical, like: مقاطعة (muhafazah)
const latinized = _.get(feat, `properties.label:${lang}_latn_x_preferred_placetype`)
return (endonym && latinized) ? endonym + ` (${latinized})` : endonym
})
).filter(val => _.isString(val) && !_.isEmpty(val))

module.exports = feature
36 changes: 31 additions & 5 deletions whosonfirst/feature.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,45 @@ module.exports.getLocalLanguages = (test) => {
module.exports.getPlacetypeLocal = (test) => {
test('getPlacetypeLocal', (t) => {
t.deepEqual([], feature.getPlacetypeLocal({}))
t.deepEqual(['LOCAL_PLACETYPE'], feature.getPlacetypeLocal({
t.deepEqual([], feature.getPlacetypeLocal({
properties: { 'wof:placetype_local': 'LOCAL_PLACETYPE' }
}))
t.deepEqual(['LOCAL_PLACETYPE'], feature.getPlacetypeLocal({
properties: { 'wof:placetype_local': ['LOCAL_PLACETYPE'] }
}))
t.deepEqual(['ENDONYM_PLACETYPE', 'LOCAL_PLACETYPE'], feature.getPlacetypeLocal({
t.deepEqual(['ENDONYM_PLACETYPE'], feature.getPlacetypeLocal({
properties: {
'wof:lang_x_official': 'und',
'label:und_x_preferred_placetype': 'ENDONYM_PLACETYPE',
'wof:placetype_local': 'LOCAL_PLACETYPE'
}
}))
// Makkah, Saudi Arabia
t.deepEqual(['مقاطعة (muhafazah)', 'region'], feature.getPlacetypeLocal({
properties: {
'wof:lang_x_official': 'ara',
'label:ara_x_preferred_placetype': 'مقاطعة',
'label:ara_latn_x_preferred_placetype': 'muhafazah',
'label:eng_x_preferred_placetype': 'region',
'wof:placetype': 'region'
}
}))
// Glasgow, Scotland, UK
t.deepEqual(['unitary district'], feature.getPlacetypeLocal({
properties: {
'wof:lang_x_official': 'und',
'label:eng_x_preferred_placetype': 'unitary district',
'wof:placetype_local': 'unitary district',
'wof:placetype': 'county'
}
}))
// Madrid, province in Spain
t.deepEqual(['provincia', 'province'], feature.getPlacetypeLocal({
properties: {
'wof:lang_x_official': 'spa',
'label:spa_x_preferred_placetype': 'provincia',
'label:eng_x_preferred_placetype': 'province',
'wof:placetype_local': 'autonomous community', // old junk data
'wof:placetype': 'region'
}
}))
t.end()
})
}
2 changes: 1 addition & 1 deletion whosonfirst/view/shapefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = (feat, params) => {
parent_id: spr.parent_id,
name: spr.name,
placetype: spr.placetype,
placelocal: _.first(feature.getPlacetypeLocal(feat)) || '', // note: not a SPR field
placelocal: feature.getPlaceTypeLocal(feat),
country: spr.country,
repo: spr.repo,
lat: spr.latitude,
Expand Down

0 comments on commit 03b8fb3

Please sign in to comment.