c# - How to interpolate latitude and longitude coordinates -
i need find interpolation points between set of 2 coordinates lie on line. pseudo c# code thinking of this:
private static list<coordinate> sampleline(coordinate start, coordinate end, int samples) { list<coordinate> linestringsample = new list<coordinate>(); // calculate equal interval between 2 points var diff_x = start.x - end.x; //latitudes var diff_y = start.y - end.y; //longitudes var length = math.sqrt(diff_x * diff_x + diff_y * diff_y); var interval_x = diff_x / length; var interval_y = diff_y / length; coordinate last = start; (int = 1; <= samples; i++) { linestringsample.add(new coordinate(start.x + interval_x * i, start.y + interval_y * i)); } } where example start = (49.13512,6.4321) end = (49.13515,6.4333) samples=1000 ,which latitude , longitude coordinates. need know if right way of interpolating 2 coordinate points of polyline, or if there way of doing this?
this interpolation not exact, , errors increase when coordinate difference grows. might still suitable small lines example.
better approach - find interpolation points @ big circle arc. here in part "intermediate point".
formula: = sin((1−f)⋅δ) / sin δ b = sin(f⋅δ) / sin δ x = ⋅ cos φ1 ⋅ cos λ1 + b ⋅ cos φ2 ⋅ cos λ2 y = ⋅ cos φ1 ⋅ sin λ1 + b ⋅ cos φ2 ⋅ sin λ2 z = ⋅ sin φ1 + b ⋅ sin φ2 φi = atan2(z, √x² + y²) λi = atan2(y, x) f fraction along great circle route (f=0 point 1, f=1 point 2), δ angular distance d/r between 2 points.
Comments
Post a Comment