-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent results from Polyline.distance #27
Comments
I wonder if this is related to the Earth radius constant we’re using: #26. /cc @frederoni @bsudekum |
I'm having the same issue in 0.2.0. Calculating distance from 2 different points less than 1 meter apart are giving me results that are 90 meters apart. Original PolyLine: Location = 49.120403526377203, -122.6529443631224 polylineIndex = polyline.closestCoordinate(to: location.coordinate)! Fake Point (calculated mid-point between points 7 & 8) = 49.120405, -122.652945 The coordinates all share 5 decimal places of accuracy (49.12040xxx, -122.65294xxx), so these distances are minuscule. So, the ultimate test: polyline.distance(from: location.coordinate, to: (49.120405, -122.652945)) = 96.294054777557619 polyline.distance(from: polylineIndex.coordinate, to: (49.120405, -122.652945)) = 96.29387058143422 I removed the variable and tested some data directly, and narrowed down the miscalculation to a very small area: I have no idea what causes a significant distance change between -122.65294499876 & -122.65294499875, but it's definitely wrong. |
Here’s a subset of the polyline above: let polyline = Polyline([
CLLocationCoordinate2D(latitude: 49.119869999999999, longitude: -122.65477),
CLLocationCoordinate2D(latitude: 49.119949999999996, longitude: -122.65477),
CLLocationCoordinate2D(latitude: 49.120129999999996, longitude: -122.65477),
CLLocationCoordinate2D(latitude: 49.120129999999996, longitude: -122.65401),
CLLocationCoordinate2D(latitude: 49.12032, longitude: -122.65401),
CLLocationCoordinate2D(latitude: 49.120689999999996, longitude: -122.65401),
CLLocationCoordinate2D(latitude: 49.120689999999996, longitude: -122.65401),
CLLocationCoordinate2D(latitude: 49.120619999999995, longitude: -122.65352),
])
let start = CLLocationCoordinate2D(latitude: 49.120403526377203, longitude: -122.6529443631224)
let end = CLLocationCoordinate2D(latitude: 49.120405, longitude: -122.652945)
XCTAssertLessThan(start.distance(to: end), 1)
XCTAssertLessThan(polyline.distance(from: start, to: end), 1) Here’s what
When appending the following coordinate onto the polyline, causing the polyline to go through both points, things get weird: CLLocationCoordinate2D(latitude: 49.120189999999994, longitude: -122.65237)
|
The following line in turf-swift/Sources/Turf/LineString.swift Line 190 in e5471bc
|
I'm getting small inconsistencies from Polyline.distance. By tracing intermediate points along a polyline from start to end - including between vertices - the resulting
distance(to: point)
doesn't consistently increment from 0 to (total distance), but jumps up and down.My suspicion is that there's something screwy going on with the interaction with closestCoordinate but I've not been able to nail it down.
For my purposes I only need the distance to a point from the start of the polyline, so I was able to get round it by hacking a
baseIndex
property onto closestCoordinate which always contains the value ofindex
(notindex+1
) and then building this round it:but I thought it worth flagging in case anyone else encounters this.
The text was updated successfully, but these errors were encountered: