當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript ArcGIS projection.project用法及代碼示例

基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/geometry/projection"], (projection) => { /* code goes here */ });

ESM: import * as projection from "@arcgis/core/geometry/projection";

對象: esri/geometry/projection

自從:用於 JavaScript 4.7 的 ArcGIS API

用法說明

projection.project函數(或屬性)的定義如下:

project (geometry, outSpatialReference, geographicTransformation) {Geometry|Geometry[]}


將幾何圖形或幾何圖形數組投影到指定的輸出空間參考。如果未明確提供但需要,則使用默認地理變換。使用 getTransformation() 方法找出給定輸入和輸出空間參考默認使用的變換。

請注意,您必須在嘗試投影幾何圖形之前加載此模塊。

已知限製

此方法使用第一個幾何圖形的空間參考作為輸入空間參考。因此,陣列中的所有幾何圖形必須具有相同的空間參考。

參數:

類型說明
geometry Geometry|Geometry[]

要投影的幾何圖形。

outSpatialReference SpatialReference autocast
來自 Object

將幾何坐標轉換到的空間參考。

geographicTransformation GeographicTransformation
可選的

用於變換幾何的地理變換。當默認變換不適合您的要求時,指定此參數以投影幾何。

返回:

類型 說明
Geometry | Geometry[] 如果將幾何數組用作輸入,則結果將是一個數組。如果將單個幾何用作輸入,它將是單個幾何。

例子:

// projects each polygon in the array
// project() will use the spatial reference of the first geometry in the array
// as an input spatial reference. It will use the default transformation
// if one is required when converting from input spatial reference
// to the output spatial reference
let outSpatialReference = new SpatialReference({
  wkid: 53008 //Sphere_Sinusoidal projection
});
polygonGraphics.forEach(function(graphic) {
  graphic.geometry = projection.project(graphic.geometry, outSpatialReference);
});
let outSpatialReference = {
  wkid: 54044
};
// projects an array of points
let projectedPoints = projection.project(wgsPoints, outSpatialReference);
projectedPoints.forEach(function(point) {
  console.log(point.x, point.y);
});

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 projection.project。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。