suredream
11/30/2016 - 5:08 PM

Gridding & Subset Toolkit

Gridding & Subset Toolkit

# create grid kml file
head = """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
"""
tail = """
</Document>
</kml>
"""

place = """
<Placemark>
<ExtendedData>
<Data name='id'>
<value>%s</value>
</Data>    
</ExtendedData>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>%f,%f %f,%f %f,%f %f,%f %f,%f </coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>"""
step = 15
with open('grid15x15.kml', 'w') as f:
    f.write(head)
    for lon in range(-28, 65, step): # -28
        for lat in range(-48, 38, step): # -48
            p1 = 'N' if lat>=0 else 'S'
            p2 = 'E' if lon>=0 else 'W'
            id = '%s%02d%s%02d' % (p1, abs(lat), p2, abs(lon))
#             print(id)
            x2, y2, x3, y3, x4, y4 = lon+step, lat, lon+step, lat+step, lon, lat+step
            f.write(place % (id, lon, lat, x2, y2, x3, y3, x4, y4, lon, lat))
    f.write(tail)
// Author: Jun Xiong

// This toolkit is used to help release 30-m products in 15d x 15d grids on GEE.
// 1. use grid.py to create a KML file in AOI;
// 2. import the exported KML to fusion table;
// 3. open batch-export.js in google earth engine playground, use the fusion table created.

var box = ee.FeatureCollection('ft:1fM786Wbri6CqIz3JvyQ_vvMIBGbdUmTOGacZTnb-') // continent border to speed it up
var image = ee.Image('') // layer to be exported
image = image.updateMask(ee.Image().byte().paint(box).eq(0))
var grids = ee.FeatureCollection('ft:1lF1RWuu5bbL2YJ_IbPVvQ1zij3a_VNMrBhb-rDVw') // uploaded grid kml

var ngrids = grids.size().getInfo()
grids = grids.toList(ngrids)

for (var i = 0; i < ngrids; i++) { 
    var ft = ee.Feature(grids.get(i)).buffer(100)
    var fd = ["GFSAD30AFCE", "2015", ft.get('id').getInfo(), "001-201610071122"]; // time stamp need to be modified
    Export.image.toCloudStorage({image: afce, description: fd.join('-'), 
      bucket:'gfsad2daac', region: ft.geometry(), scale: 30, maxPixels: 1e13})
    // Export.image.toDrive({image: afce, description: fd.join('-'), folder: '', region: ft.geometry(), scale: 30, maxPixels:  1e13})
  }

Author: Jun Xiong

This toolkit is used to help release 30-m products in 15d x 15d grids on GEE.

  1. use grid.py to create a KML file in AOI;
  2. import the exported KML to fusion table;
  3. open batch-export.js in google earth engine playground, use the fusion table created.