Skip to content

Instantly share code, notes, and snippets.

@JoaoCarabetta
Last active February 4, 2019 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoaoCarabetta/aa4972267a8010364c955c6e64e07eb9 to your computer and use it in GitHub Desktop.
Save JoaoCarabetta/aa4972267a8010364c955c6e64e07eb9 to your computer and use it in GitHub Desktop.
CREATE TABLE waze.polygons_geo
WITH (
external_location = 's3://...',
format = 'Parquet') AS
WITH dataset AS (
SELECT
polygons
FROM waze.polygons)
SELECT
pol.polygon,
pol.polygon_slug,
pol.url_base,
ST_Polygon(concat(
'polygon ((',
array_join(
transform(
split(pol.polygon, ';'),
l -> replace(l, ',', ' ')
),','),'))')) as polygon_geo
FROM dataset
CROSS JOIN UNNEST(polygons) as t(pol)
SELECT
*
FROM test.main
WHERE polygon_slug IN (
SELECT polygon_slug
FROM (SELECT
polygon_slug,
st_intersects(polygon_geo,
st_polygon('polygon ((-96.984 19.583, -96.974 19.498, 96.875 19.589))')) as inte
FROM polygons) WHERE inte = true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment