Skip to content

Commit

Permalink
Merge pull request #160 from pelias/remove-iso2-support
Browse files Browse the repository at this point in the history
Remove iso2 support
  • Loading branch information
trescube authored Oct 21, 2016
2 parents 875c01d + aca4e27 commit 6ace55f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 63 deletions.
16 changes: 11 additions & 5 deletions src/components/extractFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var through2 = require('through2');
var _ = require('lodash');

// this function is used to verify that a US county QS altname is available
function isUsCounty(base_record, qs_a2_alt) {
return 'US' === base_record.iso2 &&
function isUsCounty(base_record, wof_country, qs_a2_alt) {
return 'US' === wof_country &&
'county' === base_record.place_type &&
!_.isUndefined(qs_a2_alt);
}
Expand Down Expand Up @@ -54,6 +54,13 @@ function getName(properties) {
}
}

function getAbbreviation(properties) {
if (properties['wof:placetype'] === 'country' && properties['wof:country']) {
return properties['wof:country'];
}
return properties['wof:abbreviation'];
}

/*
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 @@ -65,19 +72,18 @@ module.exports.create = function map_fields_stream() {
var record = {
id: json_object.id,
name: getName(json_object.properties),
abbreviation: json_object.properties['wof:abbreviation'],
abbreviation: getAbbreviation(json_object.properties),
place_type: json_object.properties['wof:placetype'],
lat: getLat(json_object.properties),
lon: getLon(json_object.properties),
bounding_box: getBoundingBox(json_object.properties),
iso2: json_object.properties['iso:country'],
population: getPopulation(json_object.properties),
popularity: json_object.properties['misc:photo_sum'],
hierarchies: _.get(json_object, 'properties.wof:hierarchy', [])
};

// use the QS altname if US county and available
if (isUsCounty(record, json_object.properties['qs:a2_alt'])) {
if (isUsCounty(record, json_object.properties['wof:country'], json_object.properties['qs:a2_alt'])) {
record.name = json_object.properties['qs:a2_alt'];
}

Expand Down
6 changes: 3 additions & 3 deletions src/peliasDocGenerators.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function assignField(hierarchyElement, wofDoc) {
}
break;
case 'country':
// this is placetype=country, so lookup and set the iso3 from iso2
if (iso3166.is2(hierarchyElement.iso2)) {
var iso3 = iso3166.to3(hierarchyElement.iso2);
// this is placetype=country, so lookup and set the iso3 from abbreviation
if (iso3166.is2(hierarchyElement.abbreviation)) {
var iso3 = iso3166.to3(hierarchyElement.abbreviation);

wofDoc.setAlpha3(iso3);
wofDoc.addParent('country', hierarchyElement.name, hierarchyElement.id.toString(), iso3);
Expand Down
Loading

0 comments on commit 6ace55f

Please sign in to comment.