Skip to content

Commit

Permalink
Merge pull request #30 from ibi-group/configurable-stop-filtering-radius
Browse files Browse the repository at this point in the history
Configurable stop filtering radius
  • Loading branch information
miles-grant-ibigroup authored May 8, 2024
2 parents b0f3581 + 24c66dc commit 7f7e460
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion env.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Stringified JSON Array of OTP-UI `GeocoderConfig`s>
BACKUP_GEOCODERS: <Stringified JSON Array of OTP-UI `GeocoderConfig`'s. Same length and order as GEOCODERS>
BACKUP_GEOCODERS: <Stringified JSON Array of OTP-UI `GeocoderConfig`'s. Same length and order as GEOCODERS>

COORDINATE_COMPARISON_PRECISION_DIGITS: defaults to 4 (~10m). What precision to use when comparing if two locations are the same
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
)
})
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7f7e460

Please sign in to comment.