2

Here is a code snippet for creating a sectoral geometry with customized parameters in Google Earth Engine.

// random center point for sector var center = ee.Geometry.Point([-73, 0]); var coords=ee.List(center.coordinates()); var longitude=ee.Number(coords.get(0)); var latitude=ee.Number(coords.get(1)); // Parameters var radius = 5000; var startAngle = 45; var endAngle = 90; // Convert degrees to radians var startRad = ee.Number(startAngle).multiply(Math.PI/180); var endRad = ee.Number(endAngle).multiply(Math.PI/180); var radDiff = startRad.subtract(endRad); // Distance in meter of 1 degree longitude/latitude radian var loninMeter=111320; var latRad=latitude.multiply(Math.PI/180); var latinMeter=ee.Number(ee.Number(latRad).cos()).multiply(111320); // Define the number of points for the arc var numPoints = 10; // Function to calculate points for the arc var arcPoints = function(radius) { var points = ee.List.sequence(1, numPoints).map(function(i) { var percentage = ee.Number(i).divide(numPoints); var currentRad = startRad.add(radDiff.multiply(percentage)); var x = longitude.add(ee.Number(currentRad).cos().multiply(radius).divide(loninMeter)); var y = latitude.add(ee.Number(currentRad).sin().multiply(radius).divide(latinMeter)); return ee.Geometry.Point([x, y]); }); return points; }; var arcPoints = arcPoints(radius).add(center); // close the shape var sector=ee.Geometry.Polygon(arcPoints); Map.addLayer(sector,{color:'red'},'sectoral'); 

If startAngle and endAngle are set to 45 and 90, respectively, one radius of the sector will extends horizontally and forms a 45 degree angle with the other radius, which is strange already as arcPints are created based on coordinates of center, radius should be horizontal when startAngle is 0. Furthermore, if I set them to 45 and 75, angle between radii are 30 degree but none of the radius extends horizontally. It looks like the direction of sector is random. Why is this happening? direction of the sector when startAngle and endAngle are 45 and 75, respectively.

2 Answers 2

2

The steps for your points are starting at 1 instead of 0, so the first 1/10th of the arc is missing. Additionally, if you want your angles to go counter-clockwise, then your radDiff calculation is backwards, you want end-start.

2
  • Thank you for explaining. When I set center of the sector in high latitude, the visualization of the geometry is stretched like part of a ellipse, I think that's the result of projection, does this stretching affects calculation of area? Commented Mar 2 at 14:32
  • You should not trust Cartesian area calculated in Web Mercator at any latitude, but especially at high latitude. Commented Mar 3 at 4:04
0

From what I can tell it seems that the conversion of meters to degrees has swapped latitude and longitude. The variable "latinMeter" should be constant and "loninMeter" should vary (source: USGS). The code reads:

var loninMeter=111320; var latRad=latitude.multiply(Math.PI/180); var latinMeter=ee.Number(ee.Number(latRad).cos()).multiply(111320); 

But it should be:

var latinMeter=111320; var latRad=latitude.multiply(Math.PI/180); var loninMeter=ee.Number(ee.Number(latRad).cos()).multiply(111320); 
New contributor
GustavoCF is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.