1

Having watched GEE tutorials, pieced together code from several StackExchange questions and received help from Kuik and Jobbo90 I managed to write a code for a MODIS/006/MOD11A1 surface temperature time series; https://code.earthengine.google.com/e66a97bf90ceff11d81331be86e0f969.

I would now like to adapt the code so that the CSV output file includes three new columns; 1) Pixel longitude 2) Pixel latitude 3) Pixel area name (either a Tokyo district name or if not within a district and within the rectangle then labelled vicinity).

Having watched the GEE Tables and Vectors tutorial; https://www.youtube.com/watch?v=XLE-apehUCk and sought help from StackExchange questions such as; Extract Pixel Values for Multiple Polygons and Images and Extracting pixel values by points and converting to table in Google Earth Engine? I attempted to adjust the code but have failed to do so.

In the Tables and Vectors tutorial Nick Clinton states "here`s one way" to make a table which suggests that there are multiple ways to formulate a table and perhaps this explains why I am struggling to adjust my code with information from different sources.

I predict that I need to adjust something in the following section of my code from the first link but I can`t figure out how/where;

function spacedPoints(fc, proj) {
  var latlon = ee.Image.pixelLonLat().reproject(proj);
  var coords = latlon.select(['longitude', 'latitude'])
                 .reduceRegion({reducer: ee.Reducer.toList(),
                                geometry: fc.geometry(1).buffer(proj.nominalScale().toInt()),
                                scale: proj.nominalScale().toInt()
  });
  var point_list = ee.List(coords.get('longitude')).zip(ee.List(coords.get('latitude')));
  print(point_list);
  var list = ee.List([0]);
  var feats = ee.FeatureCollection(point_list.map(function(point){
    var ind = point_list.indexOf(point);
    var feat = ee.Feature(ee.Geometry.Point(point_list.get(ind)), {'ID': ind});
    return list.add(feat);
  }).flatten().removeAll([0]));
  return feats.filterBounds(fc.geometry(1));
}

How can I adjust the above code so that three new columns; 1) Pixel longitude 2) Pixel latitude 3) Pixel area name are added to the exported CSV file?

  • To make this possible, please transform all geometries to a featurecollection with each feature a property named to the state it belongs to, like this: link – Kuik Dec 9 '19 at 17:46
0

Like the comment above points out, you will need to turn your geometries into a ee.FeatureCollection, with their name as a property. Then you can map over your temperatures, extract the name from intersecting region, and the latitude/longitude from the geometry. Something like this:

var regions = ee.FeatureCollection([
  ee.Feature(Adachi, {name: 'Adachi'}),
  ee.Feature(Katsushika, {name: 'Katsushika'}),
  ee.Feature(Edogawa, {name: 'Edogawa'}),
  ee.Feature(Arakawa, {name: 'Arakawa'}),
  ee.Feature(Sumida, {name: 'Sumida'}),
  ee.Feature(Taito, {name: 'Taito'}),
  ee.Feature(Kita, {name: 'Kita'}),
  ee.Feature(Bunkyo, {name: 'Bunkyo'}),
  ee.Feature(Toshima, {name: 'Toshima'}),
  ee.Feature(Itabashi, {name: 'Itabashi'}),
  ee.Feature(Nerima, {name: 'Nerima'}),
  ee.Feature(Koto, {name: 'Koto'}),
  ee.Feature(Chuo, {name: 'Chuo'}),
  ee.Feature(Chiyoda, {name: 'Chiyoda'}),
  ee.Feature(Minato, {name: 'Minato'}),  
  ee.Feature(Shinagawa, {name: 'Shinagawa'}),  
  ee.Feature(Meguro, {name: 'Meguro'}),
  ee.Feature(Setagaya, {name: 'Setagaya'}),
  ee.Feature(Shibuya, {name: 'Shibuya'})
])
// Add geometry for part of AOI not in one of the regions
var vicinity = fc.geometry().difference(regions.geometry(), 30) 
regions = regions.merge(ee.FeatureCollection([ee.Feature(vicinity, {name: 'Vicinity'})]))

// calculate the temperature over the time span at every point in the AOI
var temperatures = multiband
  .reduceRegions({
    collection: points, 
    reducer: ee.Reducer.mean(), 
    scale: 1000
  })
  .map(function (feature) {
    var geometry = feature.geometry()
    var name = regions
      .filterBounds(geometry)
      .first()
      .get('name')
    var coords = geometry.centroid().coordinates()
    var additionalData = ee.Feature(null, {
      name: name, 
      longitude: coords.get(0), 
      latitude: coords.get(1)
    })
    return feature.copyProperties(additionalData)
  })
print('feature collection of temperatures', temperatures);

Export.table.toDrive({
  collection: temperatures,
  description: '2018August', 
  fileNamePrefix: '2018August', 
  fileFormat: 'CSV'
});

https://code.earthengine.google.com/4d8097ed300142e689f38b2475681a54

  • Thank you very much Daniel, your code has been a great help. – COM Dec 16 '19 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.