ee.FeatureCollection.randomColumn

  • This function adds a column of deterministic pseudorandom numbers to a FeatureCollection.

  • The random numbers can follow either a 'uniform' distribution (range [0, 1)) or a 'normal' distribution (mean 0, standard deviation 1).

  • Arguments control the column name, the seed for reproducibility, the distribution type, and the properties used to uniquely identify elements for number generation.

  • The function returns the modified FeatureCollection with the added random column.

Adds a column of deterministic pseudorandom numbers to a collection. The outputs are double-precision floating point numbers. When using the 'uniform' distribution (default), outputs are in the range of [0, 1). Using the 'normal' distribution, outputs have μ=0, σ=1, but have no explicit limits.
Usage Returns
FeatureCollection. randomColumn ( columnName , seed , distribution , rowKeys ) FeatureCollection
Argument Type Details
this: collection
FeatureCollection The input collection to which to add a random column.
columnName
String, default: "random" The name of the column to add.
seed
Long, default: 0 A seed used when generating the random numbers.
distribution
String, default: "uniform" The distribution type of random numbers to produce; one of 'uniform' or 'normal'.
rowKeys
List, optional A list of properties that should uniquely and repeatably identify an element of the collection, used to generate the random number. Defaults to [system:index].

Examples

Code Editor (JavaScript)

 // FeatureCollection of power plants in Belgium. 
 var 
  
 fc 
  
 = 
  
 ee 
 . 
 FeatureCollection 
 ( 
 'WRI/GPPD/power_plants' 
 ) 
  
 . 
 filter 
 ( 
 'country_lg == "Belgium"' 
 ); 
 print 
 ( 
 'N features in collection' 
 , 
  
 fc 
 . 
 size 
 ()); 
 // Add a uniform distribution random value column to the FeatureCollection. 
 fc 
  
 = 
  
 fc 
 . 
 randomColumn 
 (); 
 // Randomly split the collection into two sets, 30% and 70% of the total. 
 var 
  
 randomSample30 
  
 = 
  
 fc 
 . 
 filter 
 ( 
 'random < 0.3' 
 ); 
 print 
 ( 
 'N features in 30% sample' 
 , 
  
 randomSample30 
 . 
 size 
 ()); 
 var 
  
 randomSample70 
  
 = 
  
 fc 
 . 
 filter 
 ( 
 'random >= 0.3' 
 ); 
 print 
 ( 
 'N features in 70% sample' 
 , 
  
 randomSample70 
 . 
 size 
 ()); 

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

 import 
  
 ee 
 import 
  
 geemap.core 
  
 as 
  
 geemap 

Colab (Python)

 # FeatureCollection of power plants in Belgium. 
 fc 
 = 
 ee 
 . 
 FeatureCollection 
 ( 
 'WRI/GPPD/power_plants' 
 ) 
 . 
 filter 
 ( 
 'country_lg == "Belgium"' 
 ) 
 display 
 ( 
 'N features in collection:' 
 , 
 fc 
 . 
 size 
 ()) 
 # Add a uniform distribution random value column to the FeatureCollection. 
 fc 
 = 
 fc 
 . 
 randomColumn 
 () 
 # Randomly split the collection into two sets, 30% and 70% of the total. 
 random_sample_30 
 = 
 fc 
 . 
 filter 
 ( 
 'random < 0.3' 
 ) 
 display 
 ( 
 'N features in 30 
 % s 
 ample:' 
 , 
 random_sample_30 
 . 
 size 
 ()) 
 random_sample_70 
 = 
 fc 
 . 
 filter 
 ( 
 'random >= 0.3' 
 ) 
 display 
 ( 
 'N features in 70 
 % s 
 ample:' 
 , 
 random_sample_70 
 . 
 size 
 ()) 
Design a Mobile Site
View Site in Mobile | Classic
Share by: