Join Attributes From Polygon (Crime Analysis and Safety)

Summary

Joins attributes from input polygon features to input point features.

Usage

  • The tool transfers attributes from Input Polygon Features parameter value to the Target Point Features parameter value when a point feature is completely within or contained by a polygon feature.

  • By default, no attributes of the Input Polygon Features value are appended to attributes of the Target Point Features value. You can define which attributes will be added to the Target Point Features value by specifying them in the Join Fields parameter.

  • When a feature in the Target Point Features value is contained by multiple features in the Input Polygon Features value, the point will get the attribute from the polygon with the largest object ID value.

Parameters

LabelExplanationData Type
Target Point Features

The point features that will be updated with attributes from the Input Polygon Features parameter value.

The point features that will be updated with attributes from the in_features parameter value.

Feature Layer
Input Polygon Features

The input polygon features.

Feature Layer
Join Fields
(Optional)

The fields from the input polygon features that will be appended to the target point features.

Field
Overwrite matching fields in target point features
(Optional)

Specifies whether existing fields in the Target Point Features parameter value that have names that match fields in the Join Fields parameter value will be overwritten.

  • Checked—The matching fields will be overwritten.
  • Unchecked—The existing fields will not be overwritten, and new fields will be generated. This is the default.
Boolean

Derived Output

LabelExplanationData Type
Updated Point Features

The updated point features.

Feature Layer

arcpy.ca.JoinAttributesFromPolygon(target_features, in_features, {fields}, {overwrite_option})
NameExplanationData Type
target_features

The point features that will be updated with attributes from the in_features parameter value.

Feature Layer
in_features

The input polygon features.

Feature Layer
fields
[fields,...]
(Optional)

The fields from the input polygon features that will be appended to the target point features.

Field
overwrite_option
(Optional)

Specifies whether existing fields in the target_features parameter value that have names that match fields in the fields parameter value will be overwritten.

  • OVERWRITEThe matching fields will be overwritten.
  • NO_OVERWRITEThe existing fields will not be overwritten, and new fields will be generated. This is the default.
Boolean

Derived Output

NameExplanationData Type
out_features

The updated point features.

Feature Layer

Code sample

JoinAttributesFromPolygon example 1 (Python window)

The following Python window script demonstrates how to use the JoinAttributesFromPolygon function in immediate mode.

import arcpy
arcpy.env.workspace = r"C:\data\city_pd.gdb"
arcpy.ca.JoinAttributesFromPolygon("Arrests", "Precincts")
JoinAttributesFromPolygon example 2 (stand-alone script)

The following Python script demonstrates how to use the JoinAttributesFromPolygon function in a stand-alone script.

# Name: JoinAttributesFromPolygon.py
# Description:  Add police precinct ID and name to arrests, then print the number of arrests by precinct.

# import system modules 
import arcpy

# Set environment settings
arcpy.env.workspace = r"C:\data\city_pd.gdb"

# Set local variables
target_features = "Arrests"
in_features = "Precincts"
join_fields = ['districtid', 'name'] # Police Precinct ID and Name

# Run JoinAttributesFromPolygon
arcpy.ca.JoinAttributesFromPolygon(target_features, in_features, join_fields)

# Print count of arrest by precinct
count_dict = {}
with arcpy.da.SearchCursor(target_features, 'name') as cursor:
    for row in cursor:
        try:
            count_dict[row[0]] += 1
        except:
            count_dict[row[0]] = 1

for precinct, count in count_dict.items():
    print("Name: " + precinct + " Arrests: " + str(count))

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics