# Get Lon / Lat of a top left corner for geometry in Google Earth Engine

I want to extract latitude and longitude of a top left corner of a bounding box (bbox) for my geometry (aoi).

How do I do it in Earth Engine (preferably using server-side methods)?

I guess, it could be solved with some way of using `iterate()` over coordinate List's, but I failed to construct a valid way to do it.

``````var aoi = ee.Geometry.Polygon(
[[[103.6725886730469, 1.535723242616683],
[103.5187800792969, 1.2117201436706377],
[103.7494929699219, 1.1087444479525173],
[104.1450007824219, 1.2309418499697466],
[104.26173051875003, 1.5082671124456866]]]);

var bbox = aoi.bounds();
``````
• Since bbox is rectangle, this should work: `var coords = bbox.coordinates()`. – TomazicM Apr 16 '19 at 11:36
• This still returns a nested list of - points - x,y, but the question is how to find min / max of that nested list? – Basile Apr 16 '19 at 11:51
• I admit I've never used Earth Engine, but this nested list must have some inherent order from which you can deduce which element is top left corner. – TomazicM Apr 16 '19 at 12:48

Assuming you do bounds on each geometry, you will have indeed a simplified rectangle on which you should do coordinates() to get a nested list of coordinates:

``````// return the list of coordinates
var listCoords = ee.Array.cat(bbox.coordinates(), 1);
``````

Casting it to an array makes it possible to slice out the x and y coordinates:

``````// get the X-coordinates
var xCoords = listCoords.slice(1, 0, 1); print('xCoords', xCoords);
var yCoords = listCoords.slice(1, 1, 2); print('yCoords', yCoords);
``````

Reducing each array reveals then the min and max values:

``````// reduce the arrays to find the max (or min) value
var xMin = xCoords.reduce('min', ).get([0,0]); print('xMin',xMin);
var xMax = xCoords.reduce('max', ).get([0,0]); print('xMax',xMax);
var yMin = yCoords.reduce('min', ).get([0,0]); print('yMin',yMin);
var yMax = yCoords.reduce('max', ).get([0,0]); print('yMax',yMax);
``````

It works even on more complex geometries: link code. If you have a feature collection, first get the geometry of the complete feature collection: link