ee.Geometry.closestPoint

Trả về điểm trên đầu vào bên phải gần nhất với đầu vào bên trái. Nếu một trong hai giá trị đầu vào trống, thì giá trị rỗng sẽ được trả về. Nếu cả hai đầu vào đều không bị giới hạn, thì một điểm tuỳ ý sẽ được trả về. Nếu một đầu vào không có ranh giới, thì một điểm tuỳ ý trong đầu vào có ranh giới sẽ được trả về.

Cách sử dụngGiá trị trả về
Geometry.closestPoint(right, maxError, proj)Đối tượng
Đối sốLoạiThông tin chi tiết
this: leftHình họcHình học được dùng làm toán hạng bên trái của phép toán.
rightHình họcHình học được dùng làm toán hạng bên phải của thao tác.
maxErrorErrorMargin, mặc định: nullLượng lỗi tối đa được chấp nhận khi thực hiện bất kỳ phép chiếu lại cần thiết nào.
projPhép chiếu, mặc định: nullPhép chiếu để thực hiện thao tác. Nếu không được chỉ định, thao tác sẽ được thực hiện trong hệ toạ độ cầu và khoảng cách tuyến tính sẽ tính bằng mét trên quả cầu.

Ví dụ

Trình soạn thảo mã (JavaScript)

// Define a Geometry object.
var geometry = ee.Geometry({
  'type': 'Polygon',
  'coordinates':
    [[[-122.081, 37.417],
      [-122.086, 37.421],
      [-122.084, 37.418],
      [-122.089, 37.416]]]
});

// Define other inputs.
var inputGeom = ee.Geometry.Polygon(
        [[[-122.068, 37.418],
          [-122.068, 37.416],
          [-122.064, 37.416],
          [-122.064, 37.418]]]);

// Apply the closestPoints method to the Geometry objects.
var closestPoints = ee.Dictionary(geometry.closestPoints({'right': inputGeom, 'maxError': 1}));

// Print the result to the console.
print('geometry.closestPoints(...) =', closestPoints);

// There is also a one-sided API for convenience.
var closestPointOnInputGeom = geometry.closestPoint({'right': inputGeom, 'maxError': 1});
print('geometry.closestPoint(...) =', closestPointOnInputGeom);

// Display relevant geometries on the map.
Map.setCenter(-122.085, 37.422, 15);
Map.addLayer(geometry,
             {'color': 'black'},
             'Geometry [black]: geometry');
Map.addLayer(inputGeom,
             {'color': 'blue'},
             'Parameter [blue]: inputGeom');
Map.addLayer(closestPoints.getGeometry('left'),
             {'color': 'red'},
             'Result [red]: closestPointOnLeft');
Map.addLayer(closestPoints.getGeometry('right'),
             {'color': 'red'},
             'Result [red]: closestPointOnRight');