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 to the Target Point Features when a point feature is completely within or contained by a polygon feature.

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

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

Syntax

JoinAttributesFromPolygon(target_features, in_features, fields)
ParameterExplanationData Type
target_features

The point features to be updated with attributes from the in_features.

Feature Layer
in_features

The input polygon features.

Feature Layer
fields
[fields,...]

The fields from the Input Polygon Features that will be appended to the Target Point Features.

Field

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:  Adding police precinct id and name to arrests, then printing 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

# Execute 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