当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。