已知某点的 中纬度 取出 集合中 与这点最近的点 的经纬度(高分求思路)
已知某点的 经纬度 取出 集合中 与这点最近的点 的经纬度(高分求思路)
如题
我是不是要依次和各点比较求出距离
然后进行排序
得到距离最近的点
有没有更好的办法
------解决方案--------------------
用GIS平台还是自己写啊?
有的GIS平台提供了SearchNearest这个方法能找到最近的对象
自己写的话就得遍历每个对象吧,当然可以通过一些条件先筛选出一部分不需要遍历的对象
------解决方案--------------------
private static double Fun_Rad(double d)
{
return d * Math.PI / 180.0;
}
//得到两点间的距离
private static double Fun_GetDistance(double lat1, double lng1, double lat2, double lng2)
{
double d_EarthRadius = 6378.137;
double radLat1 = Fun_Rad(lat1);
double radLat2 = Fun_Rad(lat2);
double radLat = Fun_Rad(lat1) - Fun_Rad(lat2);
double radLng = Fun_Rad(lng1) - Fun_Rad(lng2);
double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(radLat / 2), 2) +
Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(radLng / 2), 2)));
s = s * d_EarthRadius;
s = Math.Round(s * 10000) / 10000;
return s;
}
/// <summary>
/// 返回距离最短的对象
/// </summary>
/// <param name="lat"></param>
/// <param name="log"></param>
/// <returns></returns>
public static PostHelper GetMinPost(double lat,double log)
{
IList<SignPost> postlist = DBHelper.GetSignpost();
List<PostHelper> post = new List<PostHelper>();
for(int i=0;i<postlist.Count;i++)
{
SignPost signpost=postlist[i];
PostHelper ph = new PostHelper();
如题
我是不是要依次和各点比较求出距离
然后进行排序
得到距离最近的点
有没有更好的办法
------解决方案--------------------
用GIS平台还是自己写啊?
有的GIS平台提供了SearchNearest这个方法能找到最近的对象
自己写的话就得遍历每个对象吧,当然可以通过一些条件先筛选出一部分不需要遍历的对象
------解决方案--------------------
private static double Fun_Rad(double d)
{
return d * Math.PI / 180.0;
}
//得到两点间的距离
private static double Fun_GetDistance(double lat1, double lng1, double lat2, double lng2)
{
double d_EarthRadius = 6378.137;
double radLat1 = Fun_Rad(lat1);
double radLat2 = Fun_Rad(lat2);
double radLat = Fun_Rad(lat1) - Fun_Rad(lat2);
double radLng = Fun_Rad(lng1) - Fun_Rad(lng2);
double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(radLat / 2), 2) +
Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(radLng / 2), 2)));
s = s * d_EarthRadius;
s = Math.Round(s * 10000) / 10000;
return s;
}
/// <summary>
/// 返回距离最短的对象
/// </summary>
/// <param name="lat"></param>
/// <param name="log"></param>
/// <returns></returns>
public static PostHelper GetMinPost(double lat,double log)
{
IList<SignPost> postlist = DBHelper.GetSignpost();
List<PostHelper> post = new List<PostHelper>();
for(int i=0;i<postlist.Count;i++)
{
SignPost signpost=postlist[i];
PostHelper ph = new PostHelper();