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


Python ArcGIS merge_layers用法及代碼示例

本文簡要介紹 python 語言中 arcgis.geoanalytics.manage_data.merge_layers 的用法。

用法:

arcgis.geoanalytics.manage_data.merge_layers(input_layer, merge_layer, merge_attributes=None, output_name=None, gis=None, context=None, future=False)

返回:

FeatureLayer

merge_layers.png

merge_layers 任務組合兩個要素層以創建單個輸出層。該工具要求兩個圖層具有相同的幾何類型(表格、點、線或多邊形)。如果在一層上啟用了時間,則另一層也必須啟用時間並且具有相同的時間類型(即時或間隔)。結果將始終包含輸入層的所有字段。默認情況下,將包含合並層中的所有字段,或者您可以指定自定義合並規則來定義結果架構。例如:

  • I have three layers for England, Wales, and Scotland and I want a single layer of Great Britain. I can use Merge Layers to combine the areas and maintain all fields from each area.

  • I have two layers containing parcel information for contiguous townships. I want to join them together into a single layer, keeping only the fields that have the same name and type in the two layers.

注意:

僅在 ArcGIS Enterprise 10.7 及更高版本中可用。

Parameter

Description

input_layer

所需層。要與 merge_layer 參數合並的表、點、線或麵要素。 input_layer 中的所有字段都將包含在結果層中。請參閱特征輸入。

merge_layer

所需層。要與 input_layer 合並的點、線或麵要素。 merge_layer 必須包含與 input_layer 相同的幾何類型(表格、點、線或多邊形)和相同的時間類型(無、即時或間隔)。默認情況下,merge_layer 中的所有字段都將包含在結果層中,或者您可以定義 merge_attributes 來自定義結果架構。請參閱特征輸入。

merge_attributes

可選的字典列表。定義如何修改 merge_layer 中的字段。默認情況下,兩個輸入的所有字段都將包含在輸出層中。

如果一個字段存在於一個圖層中而另一圖層中不存在,則輸出圖層仍將包含該字段。輸出字段將包含沒有該字段的輸入要素的空值。例如,如果 input_layer 包含名為 TYPE 的字段,但 merge_layer 不包含 TYPE,則輸出將包含 TYPE,但對於從 merge_layer 複製的所有要素,其值為 null。

您可以使用對指定 merge_layer 字段進行操作的以下合並類型來控製如何將 merge_layer 中的字段寫入輸出層:

  • Remove - The field in the merge_layer will be removed from the output layer.

  • Rename - The field in the merge_layer will be renamed in the output layer. You cannot rename a field in the merge_layer to a field in the input_layer. If you want to make field names equivalent, use Match.

  • Match - A field in the merge_layer is made equivalent to a field in the input_layer specified by merge_layer. For example, the input_layer has a field named CODE and the merge_layer has a field named STATUS. You can match STATUS to CODE, and the output will contain the CODE field with values of the STATUS field used for features copied from the merge_layer. Type casting is supported (for example, double to integer, integer to string) except for string to numeric.

# Example:
>>> merge_attributes = [{"mergeLayerField": "Mean_Sales",
                         "mergeType": "Match",
                         "mergeValue": "Average_Sales"},
                        {"mergeLayerField": "Bonus",
                         "mergeType": "Remove",},
                        {"mergeLayerField": "Field4",
                         "mergeType": "Rename",
                         "mergeValue": "Errors"}]

output_name

可選字符串。該任務將創建結果的要素服務。您定義服務的名稱。

gis

可選 GIS ,將對其進行分析。

context

可選字典。 context 參數包含影響任務執行的其他設置。對於此任務,有五個設置:

  • extent - A bounding box that defines the analysis area. Only those features that intersect the bounding box will be analyzed.

  • processSR - The features will be projected into this coordinate system for analysis.

  • outSR - The features will be projected into this coordinate system after the analysis to be saved. The output spatial reference for the spatiotemporal big data store is always WGS84.

  • dataStore - Results will be saved to the specified data store. For ArcGIS Enterprise, the default is the spatiotemporal big data store.

  • defaultAggregationStyles - If set to True, results will have square, hexagon, and triangle aggregation styles enabled on results map services.

future

可選布爾值。如果 True ,則返回 GPJob 而不是結果。可以查詢 GPJob 的執行狀態。

默認值為 False

例子:

# Usage Example: To merge census blocks from two states into one output layer.

merge_result = merge_layers(input_layer=il_block,
                            merge_layer=wi_block,
                            merge_attributes=[{"mergeLayerField" : "State_Code", "mergeType" : "Match", "mergeValue" : "statecode"}],
                            output_name="IL_WI_Census_Blocks")

相關用法


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