[英]How to get nearest X points to a given point with Lat and Long?
我有一个具有经度和纬度坐标的点列表,我想从该点输入一个点,例如X。我需要一个算法来确定最接近该点x的3个列表成员。
You can basically just approach this as a 3D nearest point problem. 您基本上可以将其作为3D最近点问题来解决。 (I don't have the Lat / Lon to Cartesian (x,y,z) calc at hand right now, but you can easily find that using google).
(我现在手边没有纬度/经度到直角坐标(x,y,z)的计算,但您可以使用Google轻松找到它)。
public class LatLonPoint
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public double X
{
get
{
.......
}
}
public double Y ....
public double Z .....
public double DistanceTo(LatLonPoint point)
{
double dX = point.X - X;
double dY = point.Y - Y;
double dZ = point.Z - Z;
return Math.Sqrt(dX * dX + dY * dY + dZ * dZ);
}
}
Your class code: 您的课程代码:
// Your list of points
private List<LatLonPoint> _points = new List<LatLonPoint>();
public LatLonPoint FindClosestPoint(LatLonPoint x)
{
var closestPoint = null;
double closestDistance = double.MaxValue;
foreach (var point in latLonList)
{
double distanceToPoint = point.DistanceTo(x);
if (distanceToPoint < closestDistance)
{
closestPoint = point;
closestDistance = distanceToPoint;
}
}
return closestPoint;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.