【问题标题】:find geographic coordinates in a radius of kilometers查找以公里为半径的地理坐标
【发布时间】:2015-12-29 04:11:01
【问题描述】:

我有一个包含大约 300.000 个向量的数据集,它们使用纬度和经度随机分布在地球周围。 假设我在北纬 51.9167°,东经 4.5000°,如何找到我周围半径为 100 公里的所有矢量? 简单的数学是首选。 Java 和伪代码也可以。

【问题讨论】:

标签: java math


【解决方案1】:

假设你有一个 Location 类和一个你想要处理的 lat/long 和一个 Collection<Location>,你可以这样做:

Collection<Location> locations; // filled somewhere
final Location here;

List<Location> within100km = locations.stream()
    .filter(l -> haversine(l.getLatitude(), l.getLongitude(),
      here.getLatitude(), here.getLongitude()) <= 100)
    .collect(Collectors.toList());

public static double haversine(
        double lat1, double lng1, double lat2, double lng2) {
    int r = 6371; // average radius of the earth in km
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
       Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) 
      * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = r * c;
    return d;
}

【讨论】:

    【解决方案2】:

    找到了一些相同的公式

    从纬度/经度到n向量

    地球表面上一点 φ,λ 的 n 向量,其中纬度 = φ 和经度 = λ,定义为

                 cosφ·cosλ   
    v{x,y,z} =   cosφ·sinλ   
                 sinφ   
    

    参考this page

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-09
      • 2010-09-28
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 2019-12-18
      • 2019-09-17
      • 1970-01-01
      相关资源
      最近更新 更多