I'm new to Python so thanks for your patience.
I'm working with two feature classes: Buildings and Parcels. What I'm trying to achieve is as follow:
Any help would be greatly appreciated!
Did you look at
Spatial Join (Analysis)—ArcGIS Pro | Documentation
to get your started. It would enable you to sum the area of the buildings in the process.
The division can be done in a new field after the fact
Are you creating a script tool for this?
You could try something like this to get you started, though you need to make sure that the selected parcel parameter type in your script tool is set to a feature layer (so only the selected parcel is used):
selectedParcel = arcpy.GetParameter(0) # I assume this is for a script tool
buildingsFC = arcpy.GetParameterAsText(1) # path to buildings features
# Get the selected parcels area
parcelArea = arcpy.da.SearchCursor(selectedParcel, 'SHAPE@AREA').next()
# intersect to find buildings
selectedBuilding = arcpy.management.SelectLayerByLocation(buildingsFC, 'INTERSECT', selectedParcel, 'NEW_SELECTION')
# iterate over selected buildings and calculate math stuff
with arcpy.da.SearchCursor(selectedBuilding , 'SHAPE@AREA') as sCur:
for row in sCur:
print(f'area calc: {row[0]/ parcelArea}')
Thank you!