1

I want to extract lat/lon values in GEE and I found the following code on stack exchange which does the job. However, when I try to print the lat/ lon values in GEE, it starts to crash. I am going to take a guess here and say it most likely because there is a large number of values ( I could be wrong). Therefore I am trying to export the lists (var point_list in this instance) into a csv, but not quite sure to go on doing that.

Any ideas?

var dataset = ee.ImageCollection('USDA/NASS/CDL')
              .filter(ee.Filter.date('2017-01-01', '2018-12-31'))
              .first()
var ROI = ee.Geometry.Polygon(
[[[-98.32711839622601,43.77454409032633],
  [-98.32711839622601,43.296678036299085],
  [-97.40426683372601,43.3126679077047],
  [-97.44821214622601,43.80626716084386],
  [-98.32711839622601,43.77454409032633]]]

var image_clipped = dataset.clip(ROI)

var proj = image_clipped.select('cropland').projection()

var latlon = ee.Image.pixelLonLat().reproject(proj)

var coords = latlon.select(['longitude','latitude']).reduceRegion({
             reducer:ee.Reducer.toList(),
             geometry:ROI
             })

var lat = ee.List(coords.get('latitude'))
var lon = ee.List(coords.get('longitude'))

var point_list = lon.zip(lat)

var coords = cropLandcover.pixelLonLat()
1

A common technique in Earth Engine to export things like lists, values etc which are too large is to first create a feature collection from them and then export them. The feature collection need not have any geometry, so you can create features with empty geometry with the values of interest as properties.

In your case, the following snippet does the trick

var fc = ee.FeatureCollection(point_list.map(function(point) {
  return ee.Feature(null, {'value': point})
}))

Then you can export fc to get the output as CSV

https://code.earthengine.google.com/ce57a9662fc76c726f70d01b1c01a974

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.