From c08f8adde5fb5d4d819b0ce33904d587e3097e3c Mon Sep 17 00:00:00 2001 From: Tyler Pedelose Date: Tue, 5 Dec 2017 14:31:00 -0500 Subject: [PATCH] Add source for geonames.mil data --- helper/type_mapping.js | 26 +++++++++++++++++--------- middleware/dedupe.js | 1 + middleware/normalizeParentIds.js | 6 ++++-- sanitizer/_geonames_deprecation.js | 8 ++++++++ sanitizer/_geonames_warnings.js | 13 +++++++++++++ 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/helper/type_mapping.js b/helper/type_mapping.js index 41303583..3f23cc7f 100644 --- a/helper/type_mapping.js +++ b/helper/type_mapping.js @@ -16,7 +16,12 @@ function addStandardTargetsToAliases(standard, aliases) { */ // 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 @@ -25,6 +30,7 @@ var SOURCE_ALIASES = { 'osm': ['openstreetmap'], 'oa': ['openaddresses'], 'gn': ['geonames'], + 'gnm': ['geonames-mil'], 'wof': ['whosonfirst'] }; @@ -44,14 +50,16 @@ var SOURCE_MAPPING = addStandardTargetsToAliases(SOURCES, SOURCE_ALIASES); * not going to match any records and will return no results. */ var LAYERS_BY_SOURCE = { - openstreetmap: [ 'address', 'venue', 'street' ], - openaddresses: [ 'address' ], - geonames: [ 'country','macroregion', 'region', 'county','localadmin', - 'locality','borough', 'neighbourhood', 'venue' ], - whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region', - 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough', - 'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode', - 'continent', 'ocean', 'marinearea'] + openstreetmap: [ 'address', 'venue', 'street' ], + openaddresses: [ 'address' ], + geonames: [ 'country', 'macroregion', 'region', 'county','localadmin', + 'locality','borough', 'neighbourhood', 'venue' ], + geonames-mil: [ 'country', 'macroregion', 'region', 'county','localadmin', + 'locality','borough', 'neighbourhood', 'venue' ], + whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region', + 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough', + 'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode', + 'continent', 'ocean', 'marinearea'] }; /* diff --git a/middleware/dedupe.js b/middleware/dedupe.js index 129d157e..41d442a8 100644 --- a/middleware/dedupe.js +++ b/middleware/dedupe.js @@ -77,6 +77,7 @@ function isPreferred(existing, candidateReplacement) { var trumpsFunc = trumps.bind(null, existing, candidateReplacement); 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('whosonfirst', 'openstreetmap'); // venues are better in OSM, at this time } diff --git a/middleware/normalizeParentIds.js b/middleware/normalizeParentIds.js index 67a4874a..ce87da10 100644 --- a/middleware/normalizeParentIds.js +++ b/middleware/normalizeParentIds.js @@ -39,12 +39,14 @@ function normalizeParentIds(place) { const placetype_ids = _.get(place, `${placeType}_gid`, [null]); // looking forward to the day we can remove all geonames specific hacks, but until then... - // geonames sometimes has its own ids in the parent hierarchy, so it's dangerous to assume that + // geonames sometimes has its own ids in the parent hierarchy, so it's dangerous to assume that // it's always WOF ids and hardcode to that if (place.source === 'geonames' && place.source_id === placetype_ids[0]) { 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]) ]; } }); diff --git a/sanitizer/_geonames_deprecation.js b/sanitizer/_geonames_deprecation.js index 2cdef1d1..31c50b8a 100644 --- a/sanitizer/_geonames_deprecation.js +++ b/sanitizer/_geonames_deprecation.js @@ -29,6 +29,14 @@ function _sanitize( raw, clean, opts ) { 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; } diff --git a/sanitizer/_geonames_warnings.js b/sanitizer/_geonames_warnings.js index 3422c4f6..7a006348 100644 --- a/sanitizer/_geonames_warnings.js +++ b/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; }