diff --git a/env.example.yml b/env.example.yml index 9408353..39e5b48 100644 --- a/env.example.yml +++ b/env.example.yml @@ -2,4 +2,6 @@ LAMBDA_EXEC_SG: Insert AWS Security Group ID Here (it must be in the same VPC as LAMBDA_EXEC_SUBNET: Insert AWS Subnet ID Here (it must be in the same VPC as the security group) BUGSNAG_NOTIFIER_KEY: INSERT BUGSNAG NOTIFIER KEY HERE GEOCODERS: -BACKUP_GEOCODERS: +BACKUP_GEOCODERS: + +COORDINATE_COMPARISON_PRECISION_DIGITS: defaults to 4 (~10m). What precision to use when comparing if two locations are the same diff --git a/package.json b/package.json index 2f36e15..afedb8c 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@bugsnag/js": "^7.11.0", "@bugsnag/plugin-aws-lambda": "^7.11.0", "@conveyal/lonlat": "^1.4.1", - "@opentripplanner/geocoder": "^2.2.0", + "@opentripplanner/geocoder": "^2.2.1", "geolib": "^3.3.1", "node-fetch": "^2.6.1", "serverless-api-gateway-caching": "^1.8.1", diff --git a/serverless.yml b/serverless.yml index d34b179..08350b4 100644 --- a/serverless.yml +++ b/serverless.yml @@ -12,6 +12,7 @@ provider: GEOCODERS: ${self:custom.secrets.GEOCODERS} BACKUP_GEOCODERS: ${self:custom.secrets.BACKUP_GEOCODERS} BUGSNAG_NOTIFIER_KEY: ${self:custom.secrets.BUGSNAG_NOTIFIER_KEY} + COORDINATE_COMPARISON_PRECISION_DIGITS: ${self:custom.secrets.COORDINATE_COMPARISON_PRECISION_DIGITS, 4} package: patterns: - pois.json diff --git a/utils.ts b/utils.ts index 60790ed..d0692bf 100644 --- a/utils.ts +++ b/utils.ts @@ -30,6 +30,8 @@ export type ServerlessResponse = { // Consts const PREFERRED_LAYERS = ['venue', 'address', 'street', 'intersection'] +const { COORDINATE_COMPARISON_PRECISION_DIGITS } = process.env + /** * This method removes all characters Pelias doesn't support. * Unfortunately, these characters not only don't match if they're found in the @@ -97,17 +99,22 @@ export const convertQSPToGeocoderArgs = ( /** * Compares two GeoJSON positions and returns if they are equal within 10m accuracy - * @param a One GeoJSON Position object - * @param b One GeoJSON Position Object + * @param a One GeoJSON Position object + * @param b One GeoJSON Position Object + * @param precision How many digits after the decimal point to use when comparing * @returns True if the positions describe the same place, false if they are different */ -export const arePointsRoughlyEqual = (a: Position, b: Position): boolean => { +export const arePointsRoughlyEqual = ( + a: Position, + b: Position, + precision = 4 +): boolean => { // 4 decimal places is approximately 10 meters, which is acceptable error const aRounded = a?.map((point: number): number => - parseFloat(point?.toFixed(4)) + parseFloat(point?.toFixed(precision)) ) const bRounded = b?.map((point: number): number => - parseFloat(point?.toFixed(4)) + parseFloat(point?.toFixed(precision)) ) return ( @@ -174,7 +181,10 @@ const filterOutDuplicateStops = ( // duplicate return arePointsRoughlyEqual( feature.geometry.coordinates, - otherFeature.geometry.coordinates + otherFeature.geometry.coordinates, + COORDINATE_COMPARISON_PRECISION_DIGITS + ? parseInt(COORDINATE_COMPARISON_PRECISION_DIGITS) + : undefined ) }) } diff --git a/yarn.lock b/yarn.lock index 109ca56..fc61b37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2521,10 +2521,10 @@ dependencies: "@octokit/openapi-types" "^12.11.0" -"@opentripplanner/geocoder@^2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-2.2.0.tgz#071f91664e898b06705c781fddd4f75dfcb3cc3f" - integrity sha512-V41WOCIpvwLRHEchBg3vRzGOOxoI+SdxczLGgLGPJ/Q/XiqaTqUgsK8WUv+hAUAGYNxI7jZbx7zdC2pXCH0m4w== +"@opentripplanner/geocoder@^2.2.1": + version "2.2.1" + resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-2.2.1.tgz#c833c7a965291daf04e712adcf25a8d4d9c5c065" + integrity sha512-JkiydCToqivnz8gN57nx14MmaUoLco/K08xIrafYO6akvZHnwVZGi9enIigfxmAH+y1hu3uCviHgu3ATUmO/NQ== dependencies: "@conveyal/geocoder-arcgis-geojson" "^0.0.3" "@conveyal/lonlat" "^1.4.1"