在BigQuery中是否存在从Easting,Northing转换为纬度,经度的UDF?

时间:2016-10-27 10:57:01

标签: r google-bigquery udf

我在BigQuery中使用BNG系统加载了Easting,Northing点。

通常我将它们读入r然后转换(从CRS(“+ init = epsg:27700”)到CRS(“+ init = epsg:4326”))。

是否有可能实际使用UDF在BigQuery中执行此操作?

这里有JS代码:http://www.movable-type.co.uk/scripts/latlong-os-gridref.html进行转换。

我如何实际将其转换为UDF,特别是能够在bigrquery中使用UDF?

谢谢!

1 个答案:

答案 0 :(得分:0)

要在UDF中使用此JavaScript代码,您可以:

  • GCS上存储您要使用的JavaScript文件的副本。
  • Enable standard SQL查询。
  • 在查询本身中,使用CREATE TEMP FUNCTION来定义UDF。使用OPTIONS子句并指定要加载的library paths

最终查询看起来像这样:

CREATE TEMP FUNCTION ConvertCoordinate(input STRING)
  RETURNS STRING
  LANGUAGE js AS
"""
    // Assumes 'jsConvertCoordinate' is defined in one of the library files.
    return jsConvertCoordinate(input);
"""
OPTIONS (
  library="gs://my-bucket/path/to/lib1.js",
  library="gs://my-bucket/path/to/lib2.js"
);

SELECT ConvertCoordinate(coordinate) AS converted_coordinate
FROM MyTable;