---
schema_version: "1"
id: 2846a9ce2252f3a47725f921e1909de0a10130ed118c7d6763c9a99ebd932343
title: 空間參數和運算子
collection: tableau
version: current
locale: zh-tw
portal_url: https://docs.salesforce.com/tableau/current/zh-tw/public/desktop/spatial_parameters.md
canonical_url: https://help.tableau.com/current/public/desktop/zh-tw/spatial_parameters.htm
source_site: help.tableau.com
content_type: documentation
content_hash: c50a5c88e62307a0e3ee0abf448dab8645fab73a5294b12a5ebd0fca246b32c6
description: Create spatial parameters and use spatial operators in calculations.
---
[跳至主要內容](#main-content)

# 空間參數和運算子

## 空間參數

可以建立空間參數以用於空間資料的計算。可以從資料來源載入空間參數，也可以使用眾所周知的文字 (WKT) 在 Tableau 中建立空間參數。空間參數可以是點、多邊形、多邊形、線或這些類型的相似集合。使用空間參數的方式與使用 Tableau 中的其他參數（例如參數控制項、參數動作和動態值）的方式相同。

從 Tableau 25.2 開始可以使用動態地圖視口參數將空間數據值參數設置為作為地圖視口的矩形。此功能讓您能夠建立更具互動性和回應性的地圖視覺效果。要瞭解詳細資料，請參閱[地圖視口參數。](https://help.tableau.com/current/pro/desktop/zh-tw/Map_Viewport_Parameters.htm)

**附註：**空間參數只能使用空間資料的欄位建立，例如緯度和經度座標。不能使用文字字串欄位來建立它們。例如，「國家/地區」欄位是一個已套用地理角色的文字字串，但它仍然是一個文字字串。

### 建立空間參數

要從「資料」窗格中建立參數：

1. 按一下右上角的下拉箭頭並選取「建立參數」。
    
    或者，可以右鍵按一下欄位，並選取建立參數。  
      
    ![用於建立參數的對話方塊。](/tableau/current/zh-tw/public/desktop/zh-tw/Img/parameter_create.png)
2. 在「建立參數」對話方塊中，為空間參數命名。
3. 開啟資料類型下拉式清單，然後選取「空間」。  
      
    ![對話方塊中的資料類型下拉式清單可建立醒目提示空間類型的參數。](/tableau/current/zh-tw/public/desktop/zh-tw/Img/spatialtype_parameter.png)
4. 在允許值下，選取「全部」或「清單」。  
    選取「清單」，以使用 WKT 或從欄位填入值。對於清單網域參數，我們建議您在命名參數時使用別名。例如，不要將空間參數命名為 POINT(-73.9856 40.7484079)，而是將其命名為「帝國大廈」。別名的使用僅適用於「清單」區域參數。
5. 開啟新增值來源旁邊的下拉式功能表並選取欄位。也可以直接在方格中輸入 WKT 值。
6. 選取「確定」。

空間參數顯示資料窗格底部的「參數」區段下。

### 視覺化空間參數

若要視覺化空間參數，請在計算中使用該參數。

1. 選取「分析」\>「建立計算欄位」。
2. 在開啟的計算編輯器中，為此計算欄位命名。
3. 在計算編輯器中，將參數拖曳到公式中。
4. 選取「確定」。

資料窗格中將新增新的計算欄位。它的資料類型圖示前面有一個 =，表示它是一個計算欄位。現在，可以透過拖曳到地圖圖層或按兩下欄位來視覺化參數。

可以使用參數控制項、參數動作或動態參數來變更參數值。

### 在視覺效果中顯示空間參數控制項

參數控制項是一個工作表卡，可修改參數值。它們與篩選器卡類似，因為它們包含修改檢視的控制項。

要顯示參數控制項，請在「資料」窗格中以右鍵按一下（在 Mac 上是 Control + 按一下）參數，然後選取「顯示參數」。  
  
![參數內容功能表，其中醒目提示「顯示參數」選項。](/tableau/current/zh-tw/public/desktop/zh-tw/Img/parameter_save.png)  

空間參數控制項可以透過多種不同的方式使用。作為輸入控制項，可以輸入 WKT 來設定參數值，也可以輸入參數的別名。也可以使用清單或下拉式控制項來檢視空間參數。

要瞭解有關參數及其使用方法的更多資訊，請參閱[建立參數](https://help.tableau.com/current/pro/desktop/zh-tw/parameters_create.htm)。

## 空間運算子

從 Tableau 版本 24.3 開始，可以在運算中使用空間運算子。

若要了解有關計算欄位以及如何使用它們的詳情，請參閱[在 Tableau 中建立簡單計算欄位](https://help.tableau.com/current/pro/desktop/zh-tw/calculations_calculatedfields_formulas.htm)。

### 使用空間運算子建立計算欄位

1. 在 Tableau 內的工作表中，選取分析\>建立計算欄位。
2. 在開啟的計算編輯器中，為此計算欄位命名。
3. 在計算編輯器中，在公式中使用空間運算子。
    
    例如：UNION(\[幾何\])
4. 選取「確定」。

新的計算欄位會新增至「資料」窗格，並在資料類型圖示前面顯示 ![等號和地球圖示資料表示空間計算欄位。](/tableau/current/zh-tw/public/desktop/zh-tw/Img/spatialcalculatedfieldlogo_28x15.png) 圖示，表示它是與空間運算子一起使用的計算欄位。

### Tableau 中可用的空間運算子

#### DIFFERENCE

<table class="TableStyle-Basic-Border" style="width: 100%;mc-table-style: url('Resources/TableStyles/Basic-Border-Light.css');" cellspacing="0"><colgroup><col style="width: 20%;" class="TableStyle-Basic-Border-Column-Column1"><col class="TableStyle-Basic-Border-Column-Column1"></colgroup><tbody><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">運算子</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1"><code>DIFFERENCE</code></td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">定義</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1">計算當第二個參數中的所有區域從重疊區域中的第一個參數中劃分出來時剩餘的區域部分。捨棄第二個參數中不重疊的區域。</td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyB-Column1-Body1">範例</td><td class="TableStyle-Basic-Border-BodyA-Column1-Body1"><p><img src="https://help.tableau.com/current/public/desktop/zh-tw/Img/spatialoperator_difference.png" alt="文氏圖表僅左側填充，中間未填充，旁邊的兩個地理區域僅顯示兩者之間的差異。"></p></td></tr></tbody></table>

#### INTERSECTION

<table class="TableStyle-Basic-Border" style="width: 100%;mc-table-style: url('Resources/TableStyles/Basic-Border-Light.css');" cellspacing="0"><colgroup><col style="width: 20%;" class="TableStyle-Basic-Border-Column-Column1"><col class="TableStyle-Basic-Border-Column-Column1"></colgroup><tbody><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">運算子</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1"><code>INTERSECTION</code></td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">定義</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1">計算並傳回第二個參數中與第一個參數中的區域重疊的區域部分。</td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyB-Column1-Body1">範例</td><td class="TableStyle-Basic-Border-BodyA-Column1-Body1"><p><img src="https://help.tableau.com/current/public/desktop/zh-tw/Img/spatialoperator_intersection.png" alt=""></p></td></tr></tbody></table>

#### SYMDIFFERENCE

<table class="TableStyle-Basic-Border" style="width: 100%;mc-table-style: url('Resources/TableStyles/Basic-Border-Light.css');" cellspacing="0"><colgroup><col style="width: 20%;" class="TableStyle-Basic-Border-Column-Column1"><col class="TableStyle-Basic-Border-Column-Column1"></colgroup><tbody><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">運算子</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1"><code>SYMDIFFERENCE</code></td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">定義</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1">計算第二個參數中與第一個參數中的區域重疊的區域的任何部分，並從兩者中捨棄。從兩個參數傳回區域的剩餘部分。</td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyB-Column1-Body1">範例</td><td class="TableStyle-Basic-Border-BodyA-Column1-Body1"><p><img src="https://help.tableau.com/current/public/desktop/zh-tw/Img/spatialoperator_symdifference.png" alt="文氏圖表，中間部分已丟棄，旁邊是兩組空間資料的地圖，重疊區域已丟棄。"></p></td></tr></tbody></table>

#### UNION

<table class="TableStyle-Basic-Border" style="width: 100%;mc-table-style: url('Resources/TableStyles/Basic-Border-Light.css');" cellspacing="0"><colgroup><col style="width: 20%;" class="TableStyle-Basic-Border-Column-Column1"><col class="TableStyle-Basic-Border-Column-Column1"></colgroup><tbody><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">運算子</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1"><code>UNION</code></td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyE-Column1-Body1">定義</td><td class="TableStyle-Basic-Border-BodyD-Column1-Body1"><p><strong>一元聯集（一個參數） </strong></p><p>語法：<code>Union (Spatial)</code></p><ul><li><p>點和線串：傳回原始輸入。</p></li><li><p>多邊形：計算空間聯集，將複多邊形中的所有不同多邊形融合為更大的多邊形，無論它們於何處重疊。傳回一個複多邊形（有時由一個多邊形組成）。</p></li></ul><p><strong>二元聯集（兩個參數） </strong></p><p>語法：<code>Union (Spatial, Spatial)
</code></p><ul><li><p>點和線串：合併兩個參數中每種類型的所有元素。</p></li><li><p>多邊形：執行空間聯集，將兩個參數中的所有多邊形融合為較大的多邊形，無論它們於何處重疊。傳回一個複多邊形（有時由一個多邊形組成）。</p></li></ul></td></tr><tr class="TableStyle-Basic-Border-Body-Body1"><td class="TableStyle-Basic-Border-BodyB-Column1-Body1">範例</td><td class="TableStyle-Basic-Border-BodyA-Column1-Body1"><p><img src="https://help.tableau.com/current/public/desktop/zh-tw/Img/spatialoperator_union.png" alt="在計算欄位中使用聯集空間運算子後，華盛頓州的地圖，其中所有城市都在華盛頓州外框旁邊，由自己的多邊形指示。"></p></td></tr></tbody></table>