Browse Source

Add source for geonames.mil data

pull/1079/head
Tyler Pedelose 7 years ago
parent
commit
c08f8adde5
  1. 26
      helper/type_mapping.js
  2. 1
      middleware/dedupe.js
  3. 2
      middleware/normalizeParentIds.js
  4. 8
      sanitizer/_geonames_deprecation.js
  5. 13
      sanitizer/_geonames_warnings.js

26
helper/type_mapping.js

@ -16,7 +16,12 @@ function addStandardTargetsToAliases(standard, aliases) {
*/ */
// a list of all sources // a list of all sources
var SOURCES = ['openstreetmap', 'openaddresses', 'geonames', 'whosonfirst']; var SOURCES = [
'openstreetmap',
'openaddresses',
'geonames',
'geonames-mil',
'whosonfirst'];
/* /*
* A list of alternate names for sources, mostly used to save typing * A list of alternate names for sources, mostly used to save typing
@ -25,6 +30,7 @@ var SOURCE_ALIASES = {
'osm': ['openstreetmap'], 'osm': ['openstreetmap'],
'oa': ['openaddresses'], 'oa': ['openaddresses'],
'gn': ['geonames'], 'gn': ['geonames'],
'gnm': ['geonames-mil'],
'wof': ['whosonfirst'] 'wof': ['whosonfirst']
}; };
@ -44,14 +50,16 @@ var SOURCE_MAPPING = addStandardTargetsToAliases(SOURCES, SOURCE_ALIASES);
* not going to match any records and will return no results. * not going to match any records and will return no results.
*/ */
var LAYERS_BY_SOURCE = { var LAYERS_BY_SOURCE = {
openstreetmap: [ 'address', 'venue', 'street' ], openstreetmap: [ 'address', 'venue', 'street' ],
openaddresses: [ 'address' ], openaddresses: [ 'address' ],
geonames: [ 'country','macroregion', 'region', 'county','localadmin', geonames: [ 'country', 'macroregion', 'region', 'county','localadmin',
'locality','borough', 'neighbourhood', 'venue' ], 'locality','borough', 'neighbourhood', 'venue' ],
whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region', geonames-mil: [ 'country', 'macroregion', 'region', 'county','localadmin',
'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough', 'locality','borough', 'neighbourhood', 'venue' ],
'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode', whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region',
'continent', 'ocean', 'marinearea'] 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough',
'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode',
'continent', 'ocean', 'marinearea']
}; };
/* /*

1
middleware/dedupe.js

@ -77,6 +77,7 @@ function isPreferred(existing, candidateReplacement) {
var trumpsFunc = trumps.bind(null, existing, candidateReplacement); var trumpsFunc = trumps.bind(null, existing, candidateReplacement);
return trumpsFunc('geonames', 'whosonfirst') || // WOF has bbox and is generally preferred return trumpsFunc('geonames', 'whosonfirst') || // WOF has bbox and is generally preferred
trumpsFunc('geonames-mil', 'whosonfirst') || // WOF has bbox and is generally preferred
trumpsFunc('openstreetmap', 'openaddresses') || // addresses are better in OA trumpsFunc('openstreetmap', 'openaddresses') || // addresses are better in OA
trumpsFunc('whosonfirst', 'openstreetmap'); // venues are better in OSM, at this time trumpsFunc('whosonfirst', 'openstreetmap'); // venues are better in OSM, at this time
} }

2
middleware/normalizeParentIds.js

@ -43,6 +43,8 @@ function normalizeParentIds(place) {
// it's always WOF ids and hardcode to that // it's always WOF ids and hardcode to that
if (place.source === 'geonames' && place.source_id === placetype_ids[0]) { if (place.source === 'geonames' && place.source_id === placetype_ids[0]) {
source = place.source; source = place.source;
} elseif (place.source === 'geonames-mil' && place.source_id === placetype_ids[0]) {
source = place.source; {
} }
place[`${placeType}_gid`] = [ makeNewId(source, placeType, placetype_ids[0]) ]; place[`${placeType}_gid`] = [ makeNewId(source, placeType, placetype_ids[0]) ];

8
sanitizer/_geonames_deprecation.js

@ -29,6 +29,14 @@ function _sanitize( raw, clean, opts ) {
messages.warnings.push(coarse_reverse_message); messages.warnings.push(coarse_reverse_message);
} }
if (_.isEqual(clean.sources, ['geonamesmil']) || _.isEqual(clean.sources, ['gnm'])) {
messages.errors.push(coarse_reverse_message);
} else if (_.includes(clean.sources, 'geonamesmil') || _.includes(clean.sources, 'gnm')) {
clean.sources = _.without(clean.sources, 'geonamesmil', 'gnm');
messages.warnings.push(coarse_reverse_message);
}
return messages; return messages;
} }

13
sanitizer/_geonames_warnings.js

@ -31,6 +31,19 @@ function _sanitize( raw, clean ){
} }
// the analysis is admin-only, so add errors or warnings if geonames.mil was requested
if (_.isEqual(clean.sources, ['geonamesmil'])) {
// if requested sources is only geonames, return an error
messages.errors.push('input contains only administrative area data, ' +
'no results will be returned when sources=geonamesmil');
} else if (_.includes(clean.sources, 'geonamesmil')) {
// if there are other sources besides geonames, return an warning
messages.warnings.push('input contains only administrative area data, ' +
'geonamesmil results will not be returned');
}
return messages; return messages;
} }

Loading…
Cancel
Save