如何使用 BigQuery 从经纬度坐标获取时区?

How to get the time zone from latitude and longitude coordinates with BigQuery?

在给定纬度和经度的情况下,我如何使用 BigQuery 知道该位置的有效时区

假设我有一个有 100 个坐标的 table:

SELECT (RAND()-0.5)*90 as latitude, (RAND()-0.5)*180 as longitude FROM UNNEST(GENERATE_ARRAY(1, 100))
Row latitude longitude
1 -24.66121614027115 31.92125752510383
2 -17.060823106878654 30.070053747514052
3 1.5425276266633903 32.30384245018918

我搜索最简单的获取方式:

timezone
Africa/Maputo
Africa/Harare
Africa/Kampala

我将从上传时区多边形边界开始。

例如你可以从这里得到它们 https://github.com/evansiroky/timezone-boundary-builder. This project offers shapefile and geojson file formats, you'll need to convert to one of the formats supported by BigQuery, e.g. new-line-delimited geojson, or CSV, and upload to BigQuery. Open source ogr2ogr 工具可以做到这一点,还有许多专有工具。

在 BigQuery 中获得数据后,您可以加入具有时区多边形的位置,例如

WITH points AS (
  SELECT (RAND()-0.5)*90 as latitude, (RAND()-0.5)*180 as longitude 
  FROM UNNEST(GENERATE_ARRAY(1, 100))
)
SELECT * FROM points p CROSS JOIN time_zones tz
ON ST_Intersects(ST_GeogPoint(p.longitude, p.latitude), tz.geometry)