Skip to content

Instantly share code, notes, and snippets.

@grovduck
Last active November 15, 2017 21:30
Show Gist options
  • Save grovduck/c1444d2ff1ab5f594efa05be2cd607be to your computer and use it in GitHub Desktop.
Save grovduck/c1444d2ff1ab5f594efa05be2cd607be to your computer and use it in GitHub Desktop.
[Google Earth Engine snippets] #google_earth_engine
// Examples of using filters with collections
// See https://groups.google.com/forum/#!topic/google-earth-engine-developers/J50mCM-LEMk
// for context
// Set up two constant images with 'a', 'b' and 'c' properties
var im1 = ee.Image.constant(0).set({
a: [1,2,3], b: 4, c: 4
});
var im2 = ee.Image.constant(0).set({
a: [4,5,6], b: 4, c: 5
});
// Create a collection of the two images
var coll = ee.ImageCollection([im1, im2]);
// Equals filters
var f1 = ee.Filter.equals('a', [1,2,3]);
print(coll.filter(f1)); // returns im1
var f2 = ee.Filter.equals('b', 4);
print(coll.filter(f2)); // returns both im1, im2
var f3 = ee.Filter.equals('b', null, 'c');
print(coll.filter(f3)); // returns im1
// List contains filters
var f4 = ee.Filter.listContains('a', 3);
print(coll.filter(f4)); // returns im1
var f5 = ee.Filter.listContains('a', null, 'b');
print(coll.filter(f5)); // returns im2
var f6 = ee.Filter.listContains(null, null, 'c', [5, 6]);
print(coll.filter(f6)); // returns im2
// Landsat collections
// TOA (top of atmosphere)
var L4_TOA = ee.ImageCollection('LANDSAT/LT4_L1T_TOA');
var L5_TOA = ee.ImageCollection('LANDSAT/LT5_L1T_TOA');
var L7_TOA = ee.ImageCollection('LANDSAT/LE7_L1T_TOA');
var L8_TOA = ee.ImageCollection('LANDSAT/LC8_L1T_TOA');
// SR (surface reflectance)
var L4_SR = ee.ImageCollection('LANDSAT/LT4_SR');
var L5_SR = ee.ImageCollection('LANDSAT/LT5_SR');
var L7_SR = ee.ImageCollection('LANDSAT/LE7_SR');
var L8_SR = ee.ImageCollection('LANDSAT/LC8_SR');
// Other data sources
// Elevation
var NED = ee.Image('USGS/NED'); // NAD83, 1/3 arc second (~10m)
var SRTM30 = ee.Image('USGS/SRTMGL1_003'); // WGS84, 30m
var SRTM90 = ee.Image('CGIAR/SRTM90_V4'); // WGS84, 90m (filled SRTM30)
// NAIP
var NAIP = ee.ImageCollection("USDA/NAIP/DOQQ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment