我有一个邮政编码-假设是“ 94304”。如何找到附近的邮政编码?
答案 0 :(得分:1)
更新:现在有了官方的公共数据集:
SELECT *
FROM (
SELECT b.zip_code neighbor, b.city, b.county, ST_DISTANCE(a.zcta_geom, b.zcta_geom) distance
FROM `bigquery-public-data.geo_us_boundaries.us_zip_codes` a,
`bigquery-public-data.geo_us_boundaries.us_zip_codes` b
WHERE a.zip_code != b.zip_code
AND a.zip_code = '94304'
)
WHERE distance < 2000 # 2 KM
ORDER BY distance
-- 5.4s elapsed, 130 MB processed
借助BigQuery GIS和可用的公共数据,这非常简单,快捷:
SELECT *
FROM (
SELECT b.zipcode neighbor, b.city, b.county, ST_DISTANCE(a.geog, b.geog) distance
FROM `fh-bigquery.gis.zipcodes` a,
`fh-bigquery.gis.zipcodes` b
WHERE a.zipcode != b.zipcode
AND a.zipcode = '94304'
)
WHERE distance < 2000 # 2 KM
ORDER BY distance
-- Query complete (4.2s elapsed, 130 MB processed)
要获得这种快速性能,首先我转换了可用的公共数据,以便将文本中的几何图形解析为GIS几何图形:
CREATE TABLE `gis.zipcodes`
AS
SELECT *, ST_GEOGFROMTEXT(zipcode_geom) AS geog
FROM `bigquery-public-data.utility_us.zipcode_area`
基于: