【问题标题】:List all points within radius using Hive使用 Hive 列出半径内的所有点
【发布时间】:2017-03-17 15:19:05
【问题描述】:

我有一张如下表:

id_center|latitude_of_center|longitude_of_center|id_point|latitude_of_point|longitude_of_point

表格有数百万行

我正在尝试获取输出,该输出将显示每个 id_center 哪些 id_points 在 5 英里半径范围内,以及距离有多远,按降序排序。每一行都是完全填充的,因此每个 id_center 在单独的行中都有所有可能的 id_point。这是我迄今为止尝试过的,但我得到的结果是空的:

hive> add jar /home/me/gis-tools-for-hadoop/samples/lib/esri-geometry-api.jar;
Added [/home/me/gis-tools-for-hadoop/samples/lib/esri-geometry-api.jar] to class path
Added resources: [/home/me/gis-tools-for-hadoop/samples/lib/esri-geometry-api.jar]
hive> add jar /home/me/gis-tools-for-hadoop/samples/lib/spatial-sdk-hadoop.jar;
Added [/home/me/gis-tools-for-hadoop/samples/lib/spatial-sdk-hadoop.jar] to class path
Added resources: [/home/me/gis-tools-for-hadoop/samples/lib/spatial-sdk-hadoop.jar]
hive> create temporary function ST_GeodesicLengthWGS84 AS 'com.esri.hadoop.hive.ST_GeodesicLengthWGS84';
OK
Time taken: 0.014 seconds
hive> create temporary function ST_SetSRID AS 'com.esri.hadoop.hive.ST_SetSRID';
OK
Time taken: 0.008 seconds
hive> create temporary function ST_LineString AS 'com.esri.hadoop.hive.ST_LineString';

SELECT * FROM mytable WHERE ST_GeodesicLengthWGS84(ST_SetSRID(ST_LineString(latitude_of_center, longitude_of_center, latitude_of_point, longitude_of_point), 4326)) <= 8046.72

【问题讨论】:

    标签: hive gis esri


    【解决方案1】:

    对于 ST_LineString,您首先需要经度,然后是纬度 - (X,Y) 顺序。 (在 GIS-SE https://gis.stackexchange.com/questions/178950/hive-gis-st-geodesiclengthwgs84-not-returning-expected-distance 上也讨论过)

    【讨论】:

    • 我确实翻转了纬度/经度值,查询似乎有效,但没有将距离作为字段返回。我想我需要在 HQL 语句中添加一些内容以将其创建为一个字段......关于必须发生的事情有什么想法吗?
    • 代替select *试试select ST_GeodesicLength...
    【解决方案2】:

    在处理类似任务时,我在 ST_LineString 中使用了 ST_Point。在docs 中选中此选项。 在你的情况下:

    SELECT * FROM mytable
    WHERE ST_GeodesicLengthWGS84(ST_SetSRID(ST_LineString(array(ST_Point(longitude_of_center, latitude_of_center), ST_Point(longitude_of_point, latitude_of_point))), 4326)) <= 8046.72;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      • 2015-08-23
      • 1970-01-01
      相关资源
      最近更新 更多