FC = Feature Class
I have points and lines in two separate FCs representing regional projects (We can call them line_projects
and point_projects
). I need each project scored by how many polygons are intersected from the top Quartile of a selected demographic field. There are 5 of theses demographic fields needing to be analyzed. All demographic fields are in a single feature class called Census_Layer.
import arcpy
# Set workspace and feature class names
arcpy.env.workspace = r"C:\path\to\workspace.gdb"
point_projects = "point_projects"
line_projects = "line_projects"
census_layer = "Census_Layer"
# Set demographic fields to analyze and their quartile values
dem_fields = ["field1", "field2", "field3", "field4", "field5"]
quartile_values = [1234, 5678, 9101, 1121, 3141] # example quartile
values
# Loop through each demographic field
for i in range(len(dem_fields)):
dem_field = dem_fields[i]
quartile_value = quartile_values[i]
# Create where clause to select features with attribute value >=
quartile value
where_clause = "{} >=
{}".format(arcpy.AddFieldDelimiters(census_layer, dem_field),
quartile_value)
# Intersect point and line projects with selected demographic
features
intersect_output = "intersect_{}_{}".format(point_projects,
line_projects)
arcpy.analysis.Intersect([point_projects, line_projects,
census_layer], intersect_output, where_clause)
# Create dictionary to store project scores
project_scores = {}
# Loop through point and line projects and count intersecting
polygons
for proj_fc in [point_projects, line_projects]:
with arcpy.da.SearchCursor(proj_fc, ["OID@", "score_field"]) as
cursor:
for row in cursor:
proj_oid = row[0]
intersect_count = int(arcpy.management.GetCount("{}\\OID@
= {}".format(intersect_output, proj_oid))[0])
project_scores.setdefault(proj_oid,
[]).append(intersect_count)
# Update score fields for each project based on sum of intersection
counts
for proj_fc in [point_projects, line_projects]:
score_field = "score_field"
with arcpy.da.UpdateCursor(proj_fc, ["OID@", score_field]) as
cursor:
for row in cursor:
proj_oid = row[0]
if proj_oid in project_scores:
scores = project_scores[proj_oid]
final_score = sum(scores)
row[1] = final_score
cursor.updateRow(row)
Then I get this error:
ExecuteError Traceback (most recent call last)
In [14]:
Line 11: arcpy.analysis.Intersect(["point_projects", "line_projects", fc2], intersect_output, where_clause)
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\analysis.py, in Intersect:
Line 525: raise e
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\analysis.py, in Intersect:
Line 522: retval = convertArcObjectToPythonObject(gp.Intersect_analysis(*gp_fixargs((in_features, out_feature_class, join_attributes, cluster_tolerance, output_type), True)))
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py, in <lambda>:
Line 512: return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of NO_FID | ONLY_FID | ALL.
Failed to execute (Intersect).