Analytics Toolbox for BigQuery

Analytics Toolbox for BigQuery

random

This module contains functions to generate random geographies.

ST_GENERATEPOINTS

Description

Generates randomly placed points inside a polygon and returns them in an array of geographies.

  • geog: GEOGRAPHY a polygon; the random points generated will be inside this polygon.
  • npoints: INT64 number of points to generate.

Return type

ARRAY<GEOGRAPHY>

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
WITH blocks AS (
  SELECT d.total_pop, g.blockgroup_geom
  FROM `bigquery-public-data.geo_census_blockgroups.us_blockgroups_national` AS g
  INNER JOIN `bigquery-public-data.census_bureau_acs.blockgroup_2018_5yr` AS d ON g.geo_id = d.geo_id
  WHERE g.county_name = 'Sonoma County'
),
point_lists AS (
  SELECT carto-st.random.ST_GENERATEPOINTS(blockgroup_geom, CAST(total_pop AS INT64)) AS points
  FROM blocks
)
SELECT points FROM point_lists CROSS JOIN point_lists.points

VERSION

Description

Returns the current version of the random module.

Return type

STRING

Example

1
2
SELECT carto-st.random.VERSION();
-- 1.0.0