I have a Shapefile containing point data that has three variables (i.e. name, width, height). I ingested it as a Feature Collection in Google Earth Engine (GEE). I want to make rectangles of varying dimensions using the 'width' and 'height' data in GEE. I do not know how to start doing this. In GEE, the closest thing I can do is to create square buffers around a point using .buffer() and .bounds() as I show in the sample code below but that is not what I want.

Can anyone advise on how I can code to create geometries of varying dimensions from point data in GEE? I have made this GEE asset publicly available for anyone to use.

This is the attribute table of the ee.FeatureCollection.

enter image description here

Here is the sample code I mentioned that creates a fixed distance square buffer around each point. I am not sure if this can be modified to create rectangles of varying widths and heights according to the values in the attribute table.

//  Load point data
var points = ee.FeatureCollection('users/earthorbgis/GEE_help/gee_point_sample');

//  Buffer points to 500 x 500 m squares
var buffer_interval01_MMR = points.map(function(f) {
  return f.buffer(250).bounds(); 

//  Create custom rectangles using point data columns Width and Height
//  Unsure how to start ...

You can achieve the result using the same .bounds() and .buffer() method. Follow these steps:

  1. Create buffers of height/2 and width/2
  2. retrieve min-max coordinates of the buffers and save it as separate properties in the points FeatureCollection
  3. Use the saved coordinates to draw rectangles around each point

Link to complete code.

Example of result: enter image description here

  • I used your code on a small subset of my data. I created the rectangles and exported them out of GEE as Shapefiles. I inspected them in QGIS and was very happy to see that the solution works exactly as desired. Thank you @kkrao for the crisp, efficient and creative solution! Feb 23 at 7:48
  • The current code results in ee.FeatureCollection as intended. However, it does not preserve the initial information in the 'points' input layer. How would I tweak the code such that I would preserve information per feature on the column 'Name'? I would like to avoid a spatial join because there may be overlapping rectangles, and would like to just preserve the Name information in the output Feature Collection. Aug 12 at 12:42
  • Since my previous comment is a different question, I will add a new post linking this one. Aug 12 at 14:17

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.