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


Python ArcGIS join_features用法及代碼示例


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

用法:

arcgis.geoanalytics.summarize_data.join_features(target_layer, join_layer, join_operation='JoinOneToOne', join_fields=None, summary_fields=None, spatial_relationship=None, spatial_near_distance=None, spatial_near_distance_unit=None, temporal_relationship=None, temporal_near_distance=None, temporal_near_distance_unit=None, attribute_relationship=None, join_condition=None, output_name=None, gis=None, context=None, future=False, keep_target=None)

join_features_geo.png

Using either feature layers or tabular data, you can join features and records based on specific relationships between the input layers or tables. Joins will be determined by spatial, temporal, and attribute relationships, and summary statistics can be optionally calculated.

For example

  • Given point locations of crime incidents with a time, join the crime data to itself specifying a spatial relationship of crimes within 1 kilometer of each other and that occurred within 1 hour of each other to determine if there are a sequence of crimes close to each other in space and time.

  • Given a table of ZIP Codes with demographic information and area features representing residential buildings, join the demographic information to the residences so each residence now has the information.

The join_features task works with two layers. join_features joins attributes from one feature to another based on spatial, temporal, and attribute relationships or some combination of the three. The tool determines all input features that meet the specified join conditions and joins the second input layer to the first. You can optionally join all features to the matching features or summarize the matching features.

join_features can be applied to points, lines, areas, and tables. A temporal join requires that your input data is time-enabled, and a spatial join requires that your data has a geometry.

請參閱Join Features 了解更多信息。

Parameter

Description

target_layer

必需的層。要連接的表、點、線或麵要素。請參閱特征輸入。

join_layer

必需的層。將連接到 target_layer 的點、線或麵要素。請參閱特征輸入。

join_operation

可選字符串。表示將應用的連接類型的字符串。

選擇清單:

  • JoinOneToOne - If multiple join features are found that have the same relationships with a single target feature, the attributes from the multiple join features will be aggregated using the specified summary statistics. For example, if a point target feature is found within two separate polygon join features, the attributes from the two polygons will be aggregated before being transferred to the output point feature class. If one polygon has an attribute value of 3 and the other has a value of 7, and a SummaryField of sum is selected, the aggregated value in the output feature class will be 10. There will always be a Count field calculated, with a value of 2, for the number of features specified. This is the default.

  • JoinOneToMany - If multiple join features are found that have the same relationship with a single target feature, the output feature class will contain multiple copies (records) of the target feature. For example, if a single point target feature is found within two separate polygon join features, the output feature class will contain two copies of the target feature: one record with the attributes of the first polygon, and another record with the attributes of the second polygon. There are no summary statistics calculated with this method.

默認值為 JoinOneToOne

join_fields

可選的字典列表。在完成分析之前要對 joinLayer 中的字段名稱進行修改的列表。任何被刪除的字段都不會計算統計信息。

用法:[{ "action" : "action", "field" : "fieldname1"}, { "action" : "action", "field" : "initial_fieldname", "to" : "new_fieldname"}]

  • action can be the following:

    • remove - Remove a field from analysis and output .

    • rename - Rename a field before running analysis.

summary_fields

可選的字典列表。您要計算的字段名稱和統計匯總類型的列表。請注意,始終返回計數。默認情況下,返回所有統計信息。

用法:[{"statisticType" : "<statistic type>", "onStatisticField" : "<field name>" }, ...]

  • onStatisticField is the name of the field in the target layer.

  • statisticType is one of the following:

    • for numeric fields:

      • Count - Totals the number of values of all the points in each polygon.

      • Sum - Adds the total value of all the points in each polygon.

      • Mean - Calculates the average of all the points in each polygon.

      • Min - Finds the smallest value of all the points in each polygon.

      • Max - Finds the largest value of all the points in each polygon.

      • Range - Finds the difference between the Min and Max values.

      • Stddev - Finds the standard deviation of all the points in each polygon.

      • Var - Finds the variance of all the points in each polygon.

    • for string fields:

      • Count - Totals the number of strings for all the points in each polygon.

      • Any - Returns a sample string of a point in each polygon.

spatial_relationship

可選字符串。定義用於空間連接要素的空間關係。

選擇清單:

  • Equals

  • Intersects

  • Contains

  • Within

  • Crosses

  • Touches

  • Overlaps

  • Near

  • NearGeodesic

spatial_near_distance(如果 spatial_relationship 接近或接近測地線則為必需)

可選浮點數。用於搜索距離的浮點值,以確定目標要素是否靠近連接要素。

注意:

僅當 NearNearGeodesic 是選定的 spatial_relationship 時才適用。您隻能輸入單個距離值。單位值由spatial_near_distance 參數提供。

spatial_near_distance_unit(如果 spatial_relationship 接近或接近測地線則為必需)

可選字符串。與 spatial_near_distance 中指定的距離值一起使用的線性單位。

選擇清單:

  • Feet

  • Yards

  • Miles

  • Meters

  • Kilometers

  • NauticalMiles

temporal_relationship

可選字符串。定義用於在時間上連接要素的時間關係。

選擇清單:

  • Equals

  • Intersects

  • During

  • Contains

  • Finishes

  • FinishedBy

  • Meets

  • MetBy

  • Overlaps

  • OverlappedBy

  • Starts

  • StartedBy

  • Near

temporal_near_distance(如果 temporal_relationship 為“Near”、“NearBefore”或“NearAfter”,則為必需)

可選整數。用於時間搜索距離的整數值,用於確定目標特征在時間上是否靠近連接特征。

注意:

僅當 NearNearBeforeNearAfter 是選定的 temporal_relationship 時才適用。您隻能輸入一個值。距離值。距離值的單位由temporal_near_distance_unit 參數提供。

temporal_near_distance_unit(如果 temporal_relationship 為“Near”、“NearBefore”或“NearAfter”,則為必需)

可選字符串。與 temporal_near_distance 中指定的距離值一起使用的時間單位。

選擇清單:

  • Years

  • Months

  • Weeks

  • Days

  • Hours

  • Minutes

  • Seconds

  • Milliseconds

attribute_relationship

可選的字典列表。用於連接相等屬性的目標字段、關係和連接字段。

用法:[{ "targetField" : "fieldname1", "joinField" : "fieldname2", "operator" : "operator" }]

join_condition

可選字符串。將條件應用於指定字段。隻有具有滿足這些條件的字段的要素才會被連接。例如,要僅對health_spending 大於收入的 20% 的那些特征應用連接到數據集,應用連接條件 target[‘health_spending’] > (join[‘income’] * .20) 使用來自第一個數據集 (target_layer) 的字段 health_spending 和來自第二個數據集 (join_layer) 的收入字段。

output_name

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

gis

可選 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.

future

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

默認值為 False

keep_target

可選布爾值。指定是在輸出要素類中保留所有目標要素(稱為左外連接),還是僅保留與連接要素具有指定關係的目標要素(內連接)。僅當 join_operation 參數為 JoinOneToOne` 時,此選項才可用。 False(內連接)是默認值。

注意:

此參數在 ArcGIS Enterprise 10.9 及更高版本中可用。

返回

輸出特征為 FeatureLayerCollection

# Usage Example: To find power outages in your state that may have been caused by a lightning strike.

output = join_features(target_layer=outages_layer,
                       join_layer=lightning,
                       join_operation="JoinOneToMany",
                       spatial_relationship="Near",
                       spatial_near_distance=20,
                       spatial_near_distance_unit="Miles",
                       temporal_relationship="NearAfter",
                       temporal_near_distance=30,
                       temporal_near_distance_unit="Minutes",
                       output_name="LightningOutages")

相關用法


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