將幾何圖形視覺化
如要將幾何圖形顯示在地圖上,請將其加入地圖。例如:
程式碼編輯器 (JavaScript)
// Create a geodesic polygon. var polygon = ee.Geometry.Polygon([ [[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]] ]); // Create a planar polygon. var planarPolygon = ee.Geometry(polygon, null, false); // Display the polygons by adding them to the map. Map.centerObject(polygon); Map.addLayer(polygon, {color: 'FF0000'}, 'geodesic polygon'); Map.addLayer(planarPolygon, {color: '000000'}, 'planar polygon');
如要進一步瞭解如何進行視覺化,請參閱「地圖項目和 FeatureCollection 視覺化」。
幾何資訊和中繼資料
如要查看幾何圖形的相關資訊,請將其列印出來。如要透過程式輔助方式存取資訊,Earth Engine 提供多種方法。例如,如要取得先前建立的多邊形相關資訊,請使用:
程式碼編輯器 (JavaScript)
print('Polygon printout: ', polygon); // Print polygon area in square kilometers. print('Polygon area: ', polygon.area().divide(1000 * 1000)); // Print polygon perimeter length in kilometers. print('Polygon perimeter: ', polygon.perimeter().divide(1000)); // Print the geometry as a GeoJSON string. print('Polygon GeoJSON: ', polygon.toGeoJSONString()); // Print the GeoJSON 'type'. print('Geometry type: ', polygon.type()); // Print the coordinates as lists. print('Polygon coordinates: ', polygon.coordinates()); // Print whether the geometry is geodesic. print('Geodesic? ', polygon.geodesic());
請注意,除非指定投影,否則幾何圖形的周長 (或長度) 會以公尺為單位傳回,而面積會以平方公尺為單位傳回。根據預設,計算會在 WGS84 橢圓球體上執行,結果會以公尺或平方公尺計算。