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
    bqcarto.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 bqcarto.random.VERSION();
-- 1.0.0